summaryrefslogtreecommitdiff
path: root/wrappers/java-android/lib/src
diff options
context:
space:
mode:
Diffstat (limited to 'wrappers/java-android/lib/src')
-rw-r--r--wrappers/java-android/lib/src/main/AndroidManifest.xml4
-rw-r--r--wrappers/java-android/lib/src/test/java/org/eduvpn/common/VerifyTests.java77
2 files changed, 81 insertions, 0 deletions
diff --git a/wrappers/java-android/lib/src/main/AndroidManifest.xml b/wrappers/java-android/lib/src/main/AndroidManifest.xml
new file mode 100644
index 0000000..5a49838
--- /dev/null
+++ b/wrappers/java-android/lib/src/main/AndroidManifest.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest package="org.eduvpn.common">
+
+</manifest>
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
+ );
+ }
+}