diff options
author | cyBerta <cyberta@riseup.net> | 2022-07-18 22:06:35 +0200 |
---|---|---|
committer | cyBerta <cyberta@riseup.net> | 2022-07-18 22:06:35 +0200 |
commit | 6ad47f6665312cfbc5c9b9e9bae1088d91b8dc99 (patch) | |
tree | 35cb991ee363dbf7e11d6f7a7669ab47fb8add0a /app/src/test/java/se | |
parent | 12797d89623adb34425cea6cb7de1057083d1cf7 (diff) |
adapt and add tests
Diffstat (limited to 'app/src/test/java/se')
-rw-r--r-- | app/src/test/java/se/leap/bitmaskclient/eip/VpnCertificateValidatorTest.java | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/app/src/test/java/se/leap/bitmaskclient/eip/VpnCertificateValidatorTest.java b/app/src/test/java/se/leap/bitmaskclient/eip/VpnCertificateValidatorTest.java index 32c0d0e4..1cb47f43 100644 --- a/app/src/test/java/se/leap/bitmaskclient/eip/VpnCertificateValidatorTest.java +++ b/app/src/test/java/se/leap/bitmaskclient/eip/VpnCertificateValidatorTest.java @@ -38,9 +38,9 @@ public class VpnCertificateValidatorTest { } @Test - public void test_isValid_lessThan15days_returnFalse() throws NoSuchAlgorithmException, CertificateEncodingException, IOException { + public void test_isValid_lessThan1day_returnFalse() throws NoSuchAlgorithmException, CertificateEncodingException, IOException { String cert = getInputAsString(getClass().getClassLoader().getResourceAsStream("riseup.net.pem")); - Calendar c = new Calendar.Builder().setDate(2024, 4, 14).setCalendarType("gregorian").build(); + Calendar c = new Calendar.Builder().setDate(2024, 3, 28).setCalendarType("gregorian").build(); mockConfigHelper("falseFingerPrint"); VpnCertificateValidator validator = new VpnCertificateValidator(cert); validator.setCalendarProvider(new TestCalendarProvider(c.getTimeInMillis())); @@ -50,7 +50,7 @@ public class VpnCertificateValidatorTest { @Test public void test_isValid_multipleCerts_failIfOneExpires() throws NoSuchAlgorithmException, CertificateEncodingException, IOException { String cert = getInputAsString(getClass().getClassLoader().getResourceAsStream("float.hexacab.org.pem")); - Calendar c = new Calendar.Builder().setDate(2024, 4, 14).setCalendarType("gregorian").build(); + Calendar c = new Calendar.Builder().setDate(2024, 3, 28).setCalendarType("gregorian").build(); mockConfigHelper("falseFingerPrint"); VpnCertificateValidator validator = new VpnCertificateValidator(cert); validator.setCalendarProvider(new TestCalendarProvider(c.getTimeInMillis())); @@ -60,10 +60,30 @@ public class VpnCertificateValidatorTest { @Test public void test_isValid_multipleCerts_allValid() throws NoSuchAlgorithmException, CertificateEncodingException, IOException { String cert = getInputAsString(getClass().getClassLoader().getResourceAsStream("float.hexacab.org.pem")); - Calendar c = new Calendar.Builder().setDate(2024, 4, 13).setCalendarType("gregorian").build(); + Calendar c = new Calendar.Builder().setDate(2024, 3, 27).setCalendarType("gregorian").build(); mockConfigHelper("falseFingerPrint"); VpnCertificateValidator validator = new VpnCertificateValidator(cert); validator.setCalendarProvider(new TestCalendarProvider(c.getTimeInMillis())); - assertFalse(validator.isValid()); + assertTrue(validator.isValid()); + } + + @Test + public void test_shouldBeUpdated_lessThan8days_returnTrue() throws NoSuchAlgorithmException, CertificateEncodingException, IOException { + String cert = getInputAsString(getClass().getClassLoader().getResourceAsStream("float.hexacab.org.pem")); + Calendar c = new Calendar.Builder().setDate(2024, 3, 21).setCalendarType("gregorian").build(); + mockConfigHelper("falseFingerPrint"); + VpnCertificateValidator validator = new VpnCertificateValidator(cert); + validator.setCalendarProvider(new TestCalendarProvider(c.getTimeInMillis())); + assertTrue(validator.shouldBeUpdated()); + } + + @Test + public void test_shouldBeUpdated_moreThan8days_returnFalse() throws NoSuchAlgorithmException, CertificateEncodingException, IOException { + String cert = getInputAsString(getClass().getClassLoader().getResourceAsStream("float.hexacab.org.pem")); + Calendar c = new Calendar.Builder().setDate(2024, 3, 20).setCalendarType("gregorian").build(); + mockConfigHelper("falseFingerPrint"); + VpnCertificateValidator validator = new VpnCertificateValidator(cert); + validator.setCalendarProvider(new TestCalendarProvider(c.getTimeInMillis())); + assertFalse(validator.shouldBeUpdated()); } }
\ No newline at end of file |