Move testInvalidKeyMaterial from StreamingAeadFactoryTest to StreamingAeadIntegrationTest.
PiperOrigin-RevId: 461689475
Change-Id: I7475f01c4a06d4b14242b054b6b1cec54f5af73e
diff --git a/src/test/java/com/google/crypto/tink/streamingaead/BUILD.bazel b/src/test/java/com/google/crypto/tink/streamingaead/BUILD.bazel
index b24cb17..01c20b0 100644
--- a/src/test/java/com/google/crypto/tink/streamingaead/BUILD.bazel
+++ b/src/test/java/com/google/crypto/tink/streamingaead/BUILD.bazel
@@ -8,6 +8,7 @@
"//proto:tink_java_proto",
"//src/main/java/com/google/crypto/tink:registry_cluster",
"//src/main/java/com/google/crypto/tink:streaming_aead",
+ "//src/main/java/com/google/crypto/tink/daead:deterministic_aead_config",
"//src/main/java/com/google/crypto/tink/streamingaead:streaming_aead_config",
"//src/main/java/com/google/crypto/tink/subtle:random",
"//src/main/java/com/google/crypto/tink/testing:streaming_test_util",
@@ -53,7 +54,6 @@
"//proto:tink_java_proto",
"//src/main/java/com/google/crypto/tink:registry_cluster",
"//src/main/java/com/google/crypto/tink:streaming_aead",
- "//src/main/java/com/google/crypto/tink/daead:deterministic_aead_config",
"//src/main/java/com/google/crypto/tink/streamingaead:streaming_aead_config",
"//src/main/java/com/google/crypto/tink/streamingaead:streaming_aead_factory",
"//src/main/java/com/google/crypto/tink/subtle:random",
diff --git a/src/test/java/com/google/crypto/tink/streamingaead/StreamingAeadFactoryTest.java b/src/test/java/com/google/crypto/tink/streamingaead/StreamingAeadFactoryTest.java
index 3ef32f3..c3c6400 100644
--- a/src/test/java/com/google/crypto/tink/streamingaead/StreamingAeadFactoryTest.java
+++ b/src/test/java/com/google/crypto/tink/streamingaead/StreamingAeadFactoryTest.java
@@ -21,7 +21,6 @@
import com.google.crypto.tink.KeysetHandle;
import com.google.crypto.tink.StreamingAead;
-import com.google.crypto.tink.daead.DeterministicAeadConfig;
import com.google.crypto.tink.proto.KeyStatusType;
import com.google.crypto.tink.proto.Keyset.Key;
import com.google.crypto.tink.proto.OutputPrefixType;
@@ -29,7 +28,6 @@
import com.google.crypto.tink.testing.StreamingTestUtil;
import com.google.crypto.tink.testing.TestUtil;
import java.io.IOException;
-import java.security.GeneralSecurityException;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -44,7 +42,6 @@
@BeforeClass
public static void setUp() throws Exception {
StreamingAeadConfig.register();
- DeterministicAeadConfig.register(); // need this for testInvalidKeyMaterial.
}
@Test
@@ -142,31 +139,4 @@
() -> StreamingTestUtil.testEncryptionAndDecryption(anotherAead, primaryAead));
assertExceptionContains(expected2, "No matching key");
}
-
- @Test
- public void testInvalidKeyMaterial() throws Exception {
- Key valid =
- TestUtil.createKey(
- TestUtil.createAesGcmHkdfStreamingKeyData(
- Random.randBytes(KDF_KEY_SIZE), AES_KEY_SIZE, 128),
- 42,
- KeyStatusType.ENABLED,
- OutputPrefixType.RAW);
- Key invalid =
- TestUtil.createKey(
- TestUtil.createAesSivKeyData(64), 43, KeyStatusType.ENABLED, OutputPrefixType.TINK);
-
- KeysetHandle keysetHandle = TestUtil.createKeysetHandle(TestUtil.createKeyset(valid, invalid));
- GeneralSecurityException e =
- assertThrows(
- GeneralSecurityException.class, () -> StreamingAeadFactory.getPrimitive(keysetHandle));
- assertExceptionContains(e, "com.google.crypto.tink.StreamingAead not supported");
-
- // invalid as the primary key.
- KeysetHandle keysetHandle2 = TestUtil.createKeysetHandle(TestUtil.createKeyset(invalid, valid));
- GeneralSecurityException e2 =
- assertThrows(
- GeneralSecurityException.class, () -> StreamingAeadFactory.getPrimitive(keysetHandle2));
- assertExceptionContains(e2, "com.google.crypto.tink.StreamingAead not supported");
- }
}
diff --git a/src/test/java/com/google/crypto/tink/streamingaead/StreamingAeadIntegrationTest.java b/src/test/java/com/google/crypto/tink/streamingaead/StreamingAeadIntegrationTest.java
index 58888e0..5d4039d 100644
--- a/src/test/java/com/google/crypto/tink/streamingaead/StreamingAeadIntegrationTest.java
+++ b/src/test/java/com/google/crypto/tink/streamingaead/StreamingAeadIntegrationTest.java
@@ -21,6 +21,7 @@
import com.google.crypto.tink.KeysetHandle;
import com.google.crypto.tink.StreamingAead;
+import com.google.crypto.tink.daead.DeterministicAeadConfig;
import com.google.crypto.tink.proto.KeyStatusType;
import com.google.crypto.tink.proto.Keyset.Key;
import com.google.crypto.tink.proto.OutputPrefixType;
@@ -28,6 +29,7 @@
import com.google.crypto.tink.testing.StreamingTestUtil;
import com.google.crypto.tink.testing.TestUtil;
import java.io.IOException;
+import java.security.GeneralSecurityException;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -42,6 +44,7 @@
@BeforeClass
public static void setUp() throws Exception {
StreamingAeadConfig.register();
+ DeterministicAeadConfig.register(); // need this for testInvalidKeyMaterial.
}
@Test
@@ -142,4 +145,31 @@
() -> StreamingTestUtil.testEncryptionAndDecryption(anotherAead, primaryAead));
assertExceptionContains(expected2, "No matching key");
}
+
+ @Test
+ public void testInvalidKeyMaterial() throws Exception {
+ Key valid =
+ TestUtil.createKey(
+ TestUtil.createAesGcmHkdfStreamingKeyData(
+ Random.randBytes(KDF_KEY_SIZE), AES_KEY_SIZE, 128),
+ 42,
+ KeyStatusType.ENABLED,
+ OutputPrefixType.RAW);
+ Key invalid =
+ TestUtil.createKey(
+ TestUtil.createAesSivKeyData(64), 43, KeyStatusType.ENABLED, OutputPrefixType.TINK);
+
+ KeysetHandle keysetHandle = TestUtil.createKeysetHandle(TestUtil.createKeyset(valid, invalid));
+ GeneralSecurityException e =
+ assertThrows(
+ GeneralSecurityException.class, () -> keysetHandle.getPrimitive(StreamingAead.class));
+ assertExceptionContains(e, "com.google.crypto.tink.StreamingAead not supported");
+
+ // invalid as the primary key.
+ KeysetHandle keysetHandle2 = TestUtil.createKeysetHandle(TestUtil.createKeyset(invalid, valid));
+ GeneralSecurityException e2 =
+ assertThrows(
+ GeneralSecurityException.class, () -> keysetHandle2.getPrimitive(StreamingAead.class));
+ assertExceptionContains(e2, "com.google.crypto.tink.StreamingAead not supported");
+ }
}