aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorckl <ckl@google.com>2023-09-26 14:12:06 -0700
committerCopybara-Service <copybara-worker@google.com>2023-09-26 14:12:45 -0700
commitc08128ba7bf6050bb9a19786dadf80448391257f (patch)
tree33dd60b49510c40b267d3cb91f6397029bf28593
parent7f80b0814581404f5423e391381301c541985626 (diff)
downloadwycheproof-c08128ba7bf6050bb9a19786dadf80448391257f.tar.gz
Add tests to verify provider registration utility functions.
For reference, here's the initial set of providers: ``` [SUN, SunRsaSign, SunEC, SunJSSE, SunJCE, SunJGSS, SunSASL, XMLDSig, SunPCSC, JdkLDAP, JdkSASL, SunPKCS11] ``` Versus the list after executing `installOnlyOpenJDKProviders()`: ``` [SUN, SunJCE, SunRsaSign, SunEC] ``` Note that the OpenJDK providers are initially present but in a different order, which is used convey provider preference. NOKEYCHECK=True PiperOrigin-RevId: 568645228
-rw-r--r--BUILD.bazel11
-rw-r--r--java/com/google/security/wycheproof/TestUtilTest.java54
2 files changed, 65 insertions, 0 deletions
diff --git a/BUILD.bazel b/BUILD.bazel
index 54addd2..dd5c889 100644
--- a/BUILD.bazel
+++ b/BUILD.bazel
@@ -20,6 +20,17 @@ java_library(
],
)
+java_test(
+ name = "TestUtilTest",
+ size = "small",
+ srcs = ["java/com/google/security/wycheproof/TestUtilTest.java"],
+ test_class = "com.google.security.wycheproof.TestUtilTest",
+ deps = [
+ ":utils",
+ "@junit",
+ ],
+)
+
common_deps = [
":utils",
"@com_google_code_gson_gson",
diff --git a/java/com/google/security/wycheproof/TestUtilTest.java b/java/com/google/security/wycheproof/TestUtilTest.java
new file mode 100644
index 0000000..a920de8
--- /dev/null
+++ b/java/com/google/security/wycheproof/TestUtilTest.java
@@ -0,0 +1,54 @@
+/**
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * <p>http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * <p>Unless required by applicable law or agreed to in writing, software distributed under the
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied. See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.google.security.wycheproof;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.security.Provider;
+import java.security.Security;
+import java.util.ArrayList;
+import java.util.List;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+/** Tests the test utilities. */
+@RunWith(JUnit4.class)
+public final class TestUtilTest {
+
+ private static List<String> getProviders() {
+ List<String> providerNames = new ArrayList<>();
+ for (Provider p : Security.getProviders()) {
+ providerNames.add(p.getName());
+ }
+ return providerNames;
+ }
+
+ @Test
+ public void removeAllProviders_succeeds() throws Exception {
+ TestUtil.removeAllProviders();
+
+ assertTrue("List of providers is not empty", getProviders().isEmpty());
+ }
+
+ @Test
+ public void installOnlyOpenJDKProviders_correctOrder() throws Exception {
+ TestUtil.installOnlyOpenJDKProviders();
+
+ String[] expectedProviders = {"SUN", "SunJCE", "SunRsaSign", "SunEC"};
+ assertArrayEquals(
+ "Expected providers not present and/or not in order",
+ getProviders().toArray(),
+ expectedProviders);
+ }
+}