diff options
author | Narayan Kamath <narayan@google.com> | 2015-07-08 15:46:22 +0100 |
---|---|---|
committer | Narayan Kamath <narayan@google.com> | 2015-07-10 09:34:02 +0100 |
commit | ca3db2c813a5066650fef0ccf3c5e25d5dace289 (patch) | |
tree | 4ddb892a1b33171a1e2ad2206a700c0db561bfaa /luni | |
parent | be80d8833a8058eba9e510a29b84dfac711cf5db (diff) | |
download | libcore-ca3db2c813a5066650fef0ccf3c5e25d5dace289.zip libcore-ca3db2c813a5066650fef0ccf3c5e25d5dace289.tar.gz libcore-ca3db2c813a5066650fef0ccf3c5e25d5dace289.tar.bz2 |
Fix KeyPairGeneratorTest.
Properly exclude AndroidKeyStore from testing given that it's tested
elsewhere. Also use the same set of providers to test (generated at
setup) for all tests.
bug: 21211314
(cherry picked from commit a02da73e5741c02408fa82c189d6b0921d399b20)
Change-Id: Idcddfd223033314be1788b21caf3cf89767bccf4
Diffstat (limited to 'luni')
-rw-r--r-- | luni/src/test/java/libcore/java/security/KeyPairGeneratorTest.java | 42 |
1 files changed, 25 insertions, 17 deletions
diff --git a/luni/src/test/java/libcore/java/security/KeyPairGeneratorTest.java b/luni/src/test/java/libcore/java/security/KeyPairGeneratorTest.java index 1320a8a..10bb621 100644 --- a/luni/src/test/java/libcore/java/security/KeyPairGeneratorTest.java +++ b/luni/src/test/java/libcore/java/security/KeyPairGeneratorTest.java @@ -56,13 +56,32 @@ import junit.framework.TestCase; public class KeyPairGeneratorTest extends TestCase { - public void test_providerCount() { + private List<Provider> providers = new ArrayList<Provider>(); + + @Override + public void setUp() { Provider[] providers = Security.getProviders(); + for (Provider p : providers) { + // Do not test AndroidKeyStore Provider. It does not accept vanilla public keys for + // signature verification. It's OKish not to test here because it's tested by + // cts/tests/tests/keystore. + if (!p.getName().startsWith("AndroidKeyStore")) { + this.providers.add(p); + } + } + } + + @Override + public void tearDown() { + providers.clear(); + } + + public void test_providerCount() { // We expect there to be at least one provider. - assertTrue(providers.length > 0); + assertTrue(providers.size() > 0); // If this fails remember to add _provider methods below. This test is sharded because it // takes a long time to execute. - assertTrue(providers.length < 10); + assertTrue(providers.size() < 10); } public void test_getInstance_provider0() throws Exception { @@ -106,14 +125,14 @@ public class KeyPairGeneratorTest extends TestCase { } private void test_getInstance(int providerIndex) throws Exception { - Provider[] providers = Security.getProviders(); - if (providerIndex >= providers.length) { + if (providerIndex >= providers.size()) { // Providers can be added by vendors and other tests. We do not // specify a fixed number and silenty pass if the provider at the // specified index does not exist. return; } - Provider provider = providers[providerIndex]; + + Provider provider = providers.get(providerIndex); Set<Provider.Service> services = provider.getServices(); for (Provider.Service service : services) { String type = service.getType(); @@ -121,15 +140,6 @@ public class KeyPairGeneratorTest extends TestCase { continue; } String algorithm = service.getAlgorithm(); - - // Do not test AndroidKeyStore's KeyPairGenerator. It cannot be initialized without - // providing AndroidKeyStore-specific algorithm parameters. - // It's OKish not to test AndroidKeyStore's KeyPairGenerator here because it's tested - // by cts/tests/test/keystore. - if ("AndroidKeyStore".equals(provider.getName())) { - continue; - } - AlgorithmParameterSpec params = null; if ("DH".equals(algorithm)) { @@ -306,8 +316,6 @@ public class KeyPairGeneratorTest extends TestCase { byte[] encoded = k.getEncoded(); String keyAlgo = k.getAlgorithm(); - - Provider[] providers = Security.getProviders(); for (Provider p : providers) { Set<Provider.Service> services = p.getServices(); for (Provider.Service service : services) { |