FileDocCategorySizeDatePackage
CertBlacklisterTest.javaAPI DocAndroid 5.1 API6990Thu Mar 12 22:22:42 GMT 2015com.android.server

CertBlacklisterTest

public class CertBlacklisterTest extends android.test.AndroidTestCase
Tests for {@link com.android.server.CertBlacklister}

Fields Summary
private static final String
BLACKLIST_ROOT
public static final String
PUBKEY_PATH
public static final String
SERIAL_PATH
public static final String
PUBKEY_KEY
public static final String
SERIAL_KEY
Constructors Summary
Methods Summary
private voidoverrideSettings(java.lang.String key, java.lang.String value)


            
        Settings.Secure.putString(mContext.getContentResolver(), key, value);
        Thread.sleep(1000);
    
public voidtestChangeBlacklistPubkey()

        String badPubkey = "6ccabd7db47e94a5759901b6a7dfd45d1c091ccc";
        overrideSettings(PUBKEY_KEY, badPubkey);
        badPubkey = "6ccabd7db47e94a5759901b6a7dfd45d1c091cce";
        overrideSettings(PUBKEY_KEY, badPubkey);
        String blacklist = IoUtils.readFileAsString(PUBKEY_PATH);
        assertEquals(badPubkey, blacklist);
    
public voidtestChangeBlacklistSerial()

        String badSerial = "22e514121e61c643b1e9b06bd4b9f7d0";
        overrideSettings(SERIAL_KEY, badSerial);
        badSerial = "22e514121e61c643b1e9b06bd4b9f7d1";
        overrideSettings(SERIAL_KEY, badSerial);
        String blacklist = IoUtils.readFileAsString(SERIAL_PATH);
        assertEquals(badSerial, blacklist);
    
public voidtestClearBlacklistPubkey()

        // clear the gservices setting for a clean slate
        overrideSettings(PUBKEY_KEY, "");
        // read the contents of the pubkey blacklist
        String blacklist = IoUtils.readFileAsString(PUBKEY_PATH);
        // Verify that it's empty
        assertEquals("", blacklist);
    
public voidtestClearBlacklistSerial()

        // clear the gservices setting for a clean slate
        overrideSettings(SERIAL_KEY, "");
        // read the contents of the pubkey blacklist
        String blacklist = IoUtils.readFileAsString(SERIAL_PATH);
        // Verify that it's empty
        assertEquals("", blacklist);
    
public voidtestInvalidCharsBlacklistPubkey()

        String badPubkey = "\n6ccabd7db47e94a5759901b6a7dfd45d1c091ccc,-ZZZZZ,+6ccabd7db47e94a5759901b6a7dfd45d1c091ccd";
        overrideSettings(PUBKEY_KEY, badPubkey);
        String blacklist = IoUtils.readFileAsString(PUBKEY_PATH);
        assertEquals(badPubkey, blacklist);
    
public voidtestInvalidCharsBlacklistSerial()

        String badSerial = "\n22e514121e61c643b1e9b06bd4b9f7d0,-ZZZZ,+22e514121e61c643b1e9b06bd4b9f7d1";
        overrideSettings(SERIAL_KEY, badSerial);
        String blacklist = IoUtils.readFileAsString(SERIAL_PATH);
        assertEquals(badSerial, blacklist);
    
public voidtestInvalidMultiBlacklistPubkey()

        String badPubkey = "6ccabd7db47e94a5759901b6a7dfd45d1c091ccc,ZZZZZ,6ccabd7db47e94a5759901b6a7dfd45d1c091ccd";
        overrideSettings(PUBKEY_KEY, badPubkey);
        String blacklist = IoUtils.readFileAsString(PUBKEY_PATH);
        assertEquals(badPubkey, blacklist);
    
public voidtestInvalidMultiBlacklistSerial()

        String badSerial = "22e514121e61c643b1e9b06bd4b9f7d0,ZZZZ,22e514121e61c643b1e9b06bd4b9f7d1";
        overrideSettings(SERIAL_KEY, badSerial);
        String blacklist = IoUtils.readFileAsString(SERIAL_PATH);
        assertEquals(badSerial, blacklist);
    
public voidtestLotsOfBlacklistedPubkeys()

        StringBuilder bl = new StringBuilder();
        for (int i=0; i < 1000; i++) {
            bl.append("6ccabd7db47e94a5759901b6a7dfd45d1c091ccc,");
        }
        overrideSettings(PUBKEY_KEY, bl.toString());
        String blacklist = IoUtils.readFileAsString(PUBKEY_PATH);
        assertEquals(bl.toString(), blacklist);
    
public voidtestLotsOfBlacklistedSerials()

        StringBuilder bl = new StringBuilder();
        for (int i=0; i < 1000; i++) {
            bl.append("22e514121e61c643b1e9b06bd4b9f7d0,");
        }
        overrideSettings(SERIAL_KEY, bl.toString());
        String blacklist = IoUtils.readFileAsString(SERIAL_PATH);
        assertEquals(bl.toString(), blacklist);
    
public voidtestMultiBlacklistPubkey()

        String badPubkey = "6ccabd7db47e94a5759901b6a7dfd45d1c091ccc,6ccabd7db47e94a5759901b6a7dfd45d1c091ccd";
        overrideSettings(PUBKEY_KEY, badPubkey);
        String blacklist = IoUtils.readFileAsString(PUBKEY_PATH);
        assertEquals(badPubkey, blacklist);
    
public voidtestMultiBlacklistSerial()

        String badSerial = "22e514121e61c643b1e9b06bd4b9f7d0,22e514121e61c643b1e9b06bd4b9f7d1";
        overrideSettings(SERIAL_KEY, badSerial);
        String blacklist = IoUtils.readFileAsString(SERIAL_PATH);
        assertEquals(badSerial, blacklist);
    
public voidtestSetBlacklistPubkey()

        // build a new thing to blacklist
        String badPubkey = "7ccabd7db47e94a5759901b6a7dfd45d1c091ccc";
        // add the gservices override
        overrideSettings(PUBKEY_KEY, badPubkey);
        // check the contents again
        String blacklist = IoUtils.readFileAsString(PUBKEY_PATH);
        // make sure that we're equal to the string we sent out
        assertEquals(badPubkey, blacklist);
    
public voidtestSetBlacklistSerial()

        // build a new thing to blacklist
        String badSerial = "22e514121e61c643b1e9b06bd4b9f7d0";
        // add the gservices override
        overrideSettings(SERIAL_KEY, badSerial);
        // check the contents again
        String blacklist = IoUtils.readFileAsString(SERIAL_PATH);
        // make sure that we're equal to the string we sent out
        assertEquals(badSerial, blacklist);