From 2aad9b6ae61337ef94b05adc377a9ad2cbaa8eb8 Mon Sep 17 00:00:00 2001 From: StevenWdV Date: Wed, 9 Feb 2022 00:40:38 +0100 Subject: Add Android wrapper, remove plain Java Maven wrapper. Fix some overrides in Makefiles. --- .../test/java/org/eduvpn/common/VerifyTests.java | 77 ++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 wrappers/java-android/lib/src/test/java/org/eduvpn/common/VerifyTests.java (limited to 'wrappers/java-android/lib/src/test/java/org/eduvpn') diff --git a/wrappers/java-android/lib/src/test/java/org/eduvpn/common/VerifyTests.java b/wrappers/java-android/lib/src/test/java/org/eduvpn/common/VerifyTests.java new file mode 100644 index 0000000..a73ac75 --- /dev/null +++ b/wrappers/java-android/lib/src/test/java/org/eduvpn/common/VerifyTests.java @@ -0,0 +1,77 @@ +package org.eduvpn.common; + +import org.apache.commons.io.IOUtils; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; + +public class VerifyTests { + private static byte[] readAll(String resource) throws IOException { + try (InputStream stream = VerifyTests.class.getResourceAsStream(resource)) { + return IOUtils.toByteArray(stream); + } + } + + @SuppressWarnings("OptionalGetWithoutIsPresent") + @BeforeClass + public static void oneTimeSetup() throws IOException { + try (BufferedReader reader = new BufferedReader(new InputStreamReader( + VerifyTests.class.getResourceAsStream("public.key")))) { + Discovery.insecureTestingSetExtraKey(reader.lines().reduce((a, b) -> b).get()); + } + } + + @Test + public void testValid() throws IOException, VerifyException { + Discovery.verify( + readAll("server_list.json.minisig"), + readAll("server_list.json"), + "server_list.json", + 0 + ); + } + + @Test(expected = InvalidSignatureException.class) + public void testInvalidSignature() throws IOException, VerifyException { + Discovery.verify( + readAll("random.txt"), + readAll("server_list.json"), + "server_list.json", + 0 + ); + } + + @Test(expected = InvalidSignatureUnknownKeyException.class) + public void testWrongKey() throws IOException, VerifyException { + Discovery.verify( + readAll("server_list.json.wrong_key.minisig"), + readAll("server_list.json"), + "server_list.json", + 0 + ); + } + + @Test(expected = SignatureTooOldException.class) + public void testOldSignature() throws IOException, VerifyException { + Discovery.verify( + readAll("server_list.json.minisig"), + readAll("server_list.json"), + "server_list.json", + Long.MAX_VALUE + ); + } + + @Test(expected = IllegalArgumentException.class) + public void testUnknownExpectedFile() throws IOException, VerifyException { + Discovery.verify( + readAll("other_list.json.minisig"), + readAll("other_list.json"), + "other_list.json", + 0 + ); + } +} -- cgit v1.2.3