summaryrefslogtreecommitdiffstats
path: root/luni
diff options
context:
space:
mode:
authorKenny Root <kroot@google.com>2015-07-22 11:22:16 -0700
committerKenny Root <kroot@google.com>2015-07-23 09:13:35 -0700
commit45a9e938ee58e79b00ae37233678ef9ab54e0392 (patch)
tree6dcd2931fffe7dd0a3c3ec13b8ef6c7327652c49 /luni
parent5423595a40397888d426112b1c6fe7b4fcf24e7a (diff)
downloadlibcore-45a9e938ee58e79b00ae37233678ef9ab54e0392.zip
libcore-45a9e938ee58e79b00ae37233678ef9ab54e0392.tar.gz
libcore-45a9e938ee58e79b00ae37233678ef9ab54e0392.tar.bz2
Late binding: add more Cipher tests
Any provider throwing an unchecked exception should not prevent the next possibly working provider from having a chance. (cherry picked from commit f7cae3971c030257c62ebc20e9e5dfd6d734b34c) Bug: 22573249 Change-Id: If3f508ed3e87de58b39ab380fb298a92fb1b593b
Diffstat (limited to 'luni')
-rw-r--r--luni/src/test/java/libcore/javax/crypto/CipherTest.java27
-rw-r--r--luni/src/test/java/libcore/javax/crypto/MockCipherSpi.java21
2 files changed, 48 insertions, 0 deletions
diff --git a/luni/src/test/java/libcore/javax/crypto/CipherTest.java b/luni/src/test/java/libcore/javax/crypto/CipherTest.java
index 3e81926..73c5f7d 100644
--- a/luni/src/test/java/libcore/javax/crypto/CipherTest.java
+++ b/luni/src/test/java/libcore/javax/crypto/CipherTest.java
@@ -1050,6 +1050,33 @@ public final class CipherTest extends TestCase {
}
}
+ public void testCipher_init_CallsInitIgnoresRuntimeException() throws Exception {
+ Provider mockProviderRejects = new MockProvider("MockProviderRejects") {
+ public void setup() {
+ put("Cipher.FOO",
+ MockCipherSpi.MustInitWithAlgorithmParameters_ThrowsNull.class.getName());
+ put("Cipher.FOO SupportedKeyClasses", MockKey.class.getName());
+ }
+ };
+ Provider mockProviderAccepts = new MockProvider("MockProviderAccepts") {
+ public void setup() {
+ put("Cipher.FOO", MockCipherSpi.AllKeyTypes.class.getName());
+ put("Cipher.FOO SupportedKeyClasses", MockKey.class.getName());
+ }
+ };
+
+ Security.addProvider(mockProviderRejects);
+ Security.addProvider(mockProviderAccepts);
+ try {
+ Cipher c = Cipher.getInstance("FOO");
+ c.init(Cipher.ENCRYPT_MODE, new MockKey(), AlgorithmParameters.getInstance("AES"));
+ assertEquals(mockProviderAccepts, c.getProvider());
+ } finally {
+ Security.removeProvider(mockProviderRejects.getName());
+ Security.removeProvider(mockProviderAccepts.getName());
+ }
+ }
+
public void testCipher_init_CallsInitWithMode() throws Exception {
Provider mockProviderOnlyEncrypt = new MockProvider("MockProviderOnlyEncrypt") {
public void setup() {
diff --git a/luni/src/test/java/libcore/javax/crypto/MockCipherSpi.java b/luni/src/test/java/libcore/javax/crypto/MockCipherSpi.java
index e398b33..c1b1bd2 100644
--- a/luni/src/test/java/libcore/javax/crypto/MockCipherSpi.java
+++ b/luni/src/test/java/libcore/javax/crypto/MockCipherSpi.java
@@ -81,6 +81,7 @@ public class MockCipherSpi extends CipherSpi {
@Override
protected void engineInit(int opmode, Key key, SecureRandom random)
throws InvalidKeyException {
+ throw new AssertionError("Must have AlgorithmParameterSpec");
}
@Override
@@ -96,6 +97,26 @@ public class MockCipherSpi extends CipherSpi {
}
}
+ public static class MustInitWithAlgorithmParameters_ThrowsNull extends MockCipherSpi {
+ @Override
+ protected void engineInit(int opmode, Key key, SecureRandom random)
+ throws InvalidKeyException {
+ throw new NullPointerException("expected rejection");
+ }
+
+ @Override
+ protected void engineInit(int opmode, Key key, AlgorithmParameterSpec params,
+ SecureRandom random) throws InvalidKeyException, InvalidAlgorithmParameterException {
+ throw new NullPointerException("expected rejection");
+ }
+
+ @Override
+ protected void engineInit(int opmode, Key key, AlgorithmParameters params,
+ SecureRandom random) throws InvalidKeyException, InvalidAlgorithmParameterException {
+ throw new NullPointerException("expected rejection");
+ }
+ }
+
public static class MustInitForEncryptModeOrRejects extends MockCipherSpi {
@Override
protected void engineInit(int opmode, Key key, SecureRandom random)