KeyStore3Testpublic class KeyStore3Test extends TestCase
Fields Summary |
---|
private KeyStore | mockKeyStore | private KeyPair | keyPair | private Certificate | certificate |
Constructors Summary |
---|
public KeyStore3Test()
KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("DSA");
keyPair = keyPairGenerator.generateKeyPair();
String certificateData = "-----BEGIN CERTIFICATE-----\n"
+ "MIICZTCCAdICBQL3AAC2MA0GCSqGSIb3DQEBAgUAMF8xCzAJBgNVBAYTAlVTMSAw\n"
+ "HgYDVQQKExdSU0EgRGF0YSBTZWN1cml0eSwgSW5jLjEuMCwGA1UECxMlU2VjdXJl\n"
+ "IFNlcnZlciBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTAeFw05NzAyMjAwMDAwMDBa\n"
+ "Fw05ODAyMjAyMzU5NTlaMIGWMQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZv\n"
+ "cm5pYTESMBAGA1UEBxMJUGFsbyBBbHRvMR8wHQYDVQQKExZTdW4gTWljcm9zeXN0\n"
+ "ZW1zLCBJbmMuMSEwHwYDVQQLExhUZXN0IGFuZCBFdmFsdWF0aW9uIE9ubHkxGjAY\n"
+ "BgNVBAMTEWFyZ29uLmVuZy5zdW4uY29tMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCB\n"
+ "iQKBgQCofmdY+PiUWN01FOzEewf+GaG+lFf132UpzATmYJkA4AEA/juW7jSi+LJk\n"
+ "wJKi5GO4RyZoyimAL/5yIWDV6l1KlvxyKslr0REhMBaD/3Z3EsLTTEf5gVrQS6sT\n"
+ "WMoSZAyzB39kFfsB6oUXNtV8+UKKxSxKbxvhQn267PeCz5VX2QIDAQABMA0GCSqG\n"
+ "SIb3DQEBAgUAA34AXl3at6luiV/7I9MN5CXYoPJYI8Bcdc1hBagJvTMcmlqL2uOZ\n"
+ "H9T5hNMEL9Tk6aI7yZPXcw/xI2K6pOR/FrMp0UwJmdxX7ljV6ZtUZf7pY492UqwC\n"
+ "1777XQ9UEZyrKJvF5ntleeO0ayBqLGVKCWzWZX9YsXCpv47FNLZbupE=\n"
+ "-----END CERTIFICATE-----\n";
ByteArrayInputStream certArray = new ByteArrayInputStream(
certificateData.getBytes());
CertificateFactory cf = CertificateFactory.getInstance("X.509");
certificate = cf.generateCertificate(certArray);
|
Methods Summary |
---|
protected void | setUp()
super.setUp();
mockKeyStore = new MyKeyStore(new MyKeyStoreSpi(), null, "MyKeyStore");
| public void | test_KeyStore()
Provider p = new MyProvider();
try {
MyKeyStore ks = new MyKeyStore(new MyKeyStoreSpi(), p, "MyKeyStore");
assertNotNull(ks);
assertTrue(ks instanceof KeyStore);
} catch (Exception e) {
fail("Exception should be not thrown");
}
try {
MyKeyStore ks = new MyKeyStore(null, null, null);
assertNotNull(ks);
assertTrue(ks instanceof KeyStore);
} catch (Exception e) {
fail("Exception should be not thrown");
}
| public void | test_load()
// No exception should be thrown out.
mockKeyStore.load(null);
| public void | test_setCertificateEntry_null()
mockKeyStore.load(null, null);
mockKeyStore.setCertificateEntry(null, null);
mockKeyStore.setCertificateEntry(null, certificate);
mockKeyStore.setCertificateEntry("Alias", null);
| public void | test_setKeyEntry_key_is_null()
mockKeyStore.load(null, null);
// No exception should be thrown out.
mockKeyStore.setKeyEntry("Alias", null, null, new Certificate[]{certificate});
| public void | test_setKeyEntry_key_is_private()
mockKeyStore.load(null, null);
Key key = keyPair.getPrivate();
try {
mockKeyStore.setKeyEntry("Alias", key, null, null);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// expected
}
try {
mockKeyStore.setKeyEntry("Alias", key, null,
new Certificate[0]);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// expected
}
mockKeyStore.setKeyEntry("Alias", key, null, new Certificate[]{certificate});
| public void | test_setKeyEntry_key_is_public()
mockKeyStore.load(null, null);
Key key = keyPair.getPublic();
mockKeyStore.setKeyEntry("Alias1", key, null, null);
mockKeyStore.setKeyEntry("Alias2", key, null,
new Certificate[0]);
mockKeyStore.setKeyEntry("Alias3", key, null, new Certificate[]{certificate});
| public void | test_setKeyEntry_null()
mockKeyStore.load(null, null);
// No exception should be thrown out.
mockKeyStore.setKeyEntry(null, null, null, null);
| public void | test_store()
try {
mockKeyStore.store(null);
fail("should throw KeyStoreException: not initialized");
} catch (KeyStoreException e) {
// expected
}
// No exception should be thrown out.
mockKeyStore.load(null, null);
mockKeyStore.store(null);
|
|