summaryrefslogtreecommitdiff
path: root/app/src/test/java/se
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/test/java/se')
-rw-r--r--app/src/test/java/se/leap/bitmaskclient/eip/ProviderApiManagerTest.java47
-rw-r--r--app/src/test/java/se/leap/bitmaskclient/eip/VpnCertificateValidatorTest.java30
2 files changed, 52 insertions, 25 deletions
diff --git a/app/src/test/java/se/leap/bitmaskclient/eip/ProviderApiManagerTest.java b/app/src/test/java/se/leap/bitmaskclient/eip/ProviderApiManagerTest.java
index cb1e1f73..2b1615da 100644
--- a/app/src/test/java/se/leap/bitmaskclient/eip/ProviderApiManagerTest.java
+++ b/app/src/test/java/se/leap/bitmaskclient/eip/ProviderApiManagerTest.java
@@ -186,6 +186,7 @@ public class ProviderApiManagerTest {
providerApiCommand.setAction(ProviderAPI.SET_UP_PROVIDER);
providerApiCommand.putExtra(ProviderAPI.RECEIVER_KEY, mockResultReceiver(PROVIDER_NOK, expectedResult));
providerApiCommand.putExtra(PROVIDER_KEY, provider);
+ providerApiCommand.putExtra(PARAMETERS, mockBundle());
providerApiManager.handleIntent(providerApiCommand);
}
@@ -207,6 +208,7 @@ public class ProviderApiManagerTest {
providerApiCommand.putExtra(PROVIDER_KEY, provider);
providerApiCommand.setAction(ProviderAPI.SET_UP_PROVIDER);
providerApiCommand.putExtra(ProviderAPI.RECEIVER_KEY, mockResultReceiver(PROVIDER_OK, expectedResult));
+ providerApiCommand.putExtra(PARAMETERS, mockBundle());
providerApiManager.handleIntent(providerApiCommand);
}
@@ -228,6 +230,7 @@ public class ProviderApiManagerTest {
providerApiCommand.setAction(ProviderAPI.SET_UP_PROVIDER);
providerApiCommand.putExtra(ProviderAPI.RECEIVER_KEY, mockResultReceiver(PROVIDER_OK, expectedResult));
providerApiCommand.putExtra(PROVIDER_KEY, provider);
+ providerApiCommand.putExtra(PARAMETERS, mockBundle());
providerApiManager.handleIntent(providerApiCommand);
}
@@ -249,7 +252,7 @@ public class ProviderApiManagerTest {
Intent providerApiCommand = mockIntent();
providerApiCommand.setAction(ProviderAPI.SET_UP_PROVIDER);
providerApiCommand.putExtra(ProviderAPI.RECEIVER_KEY, mockResultReceiver(PROVIDER_OK, expectedResult));
-
+ providerApiCommand.putExtra(PARAMETERS, mockBundle());
providerApiCommand.putExtra(PROVIDER_KEY, provider);
providerApiManager.handleIntent(providerApiCommand);
@@ -270,6 +273,7 @@ public class ProviderApiManagerTest {
providerApiCommand.setAction(ProviderAPI.SET_UP_PROVIDER);
providerApiCommand.putExtra(ProviderAPI.RECEIVER_KEY, mockResultReceiver(PROVIDER_NOK, expectedResult));
+ providerApiCommand.putExtra(PARAMETERS, mockBundle());
providerApiCommand.putExtra(PROVIDER_KEY, provider);
@@ -292,6 +296,7 @@ public class ProviderApiManagerTest {
providerApiCommand.setAction(ProviderAPI.SET_UP_PROVIDER);
providerApiCommand.putExtra(ProviderAPI.RECEIVER_KEY, mockResultReceiver(PROVIDER_NOK, expectedResult));
+ providerApiCommand.putExtra(PARAMETERS, mockBundle());
providerApiCommand.putExtra(PROVIDER_KEY, provider);
@@ -318,7 +323,7 @@ public class ProviderApiManagerTest {
providerApiCommand.setAction(ProviderAPI.SET_UP_PROVIDER);
providerApiCommand.putExtra(ProviderAPI.RECEIVER_KEY, mockResultReceiver(PROVIDER_NOK, expectedResult));
-
+ providerApiCommand.putExtra(PARAMETERS, mockBundle());
providerApiCommand.putExtra(PROVIDER_KEY, provider);
providerApiManager.handleIntent(providerApiCommand);
@@ -341,7 +346,7 @@ public class ProviderApiManagerTest {
providerApiCommand.setAction(ProviderAPI.SET_UP_PROVIDER);
providerApiCommand.putExtra(ProviderAPI.RECEIVER_KEY, mockResultReceiver(PROVIDER_NOK, expectedResult));
-
+ providerApiCommand.putExtra(PARAMETERS, mockBundle());
providerApiCommand.putExtra(PROVIDER_KEY, provider);
providerApiManager.handleIntent(providerApiCommand);
@@ -365,7 +370,7 @@ public class ProviderApiManagerTest {
providerApiCommand.setAction(ProviderAPI.SET_UP_PROVIDER);
providerApiCommand.putExtra(ProviderAPI.RECEIVER_KEY, mockResultReceiver(PROVIDER_NOK, expectedResult));
-
+ providerApiCommand.putExtra(PARAMETERS, mockBundle());
providerApiCommand.putExtra(PROVIDER_KEY, provider);
providerApiManager.handleIntent(providerApiCommand);
@@ -388,6 +393,7 @@ public class ProviderApiManagerTest {
providerApiCommand.setAction(ProviderAPI.SET_UP_PROVIDER);
providerApiCommand.putExtra(ProviderAPI.RECEIVER_KEY, mockResultReceiver(PROVIDER_NOK, expectedResult));
+ providerApiCommand.putExtra(PARAMETERS, mockBundle());
providerApiCommand.putExtra(PROVIDER_KEY, provider);
@@ -413,6 +419,7 @@ public class ProviderApiManagerTest {
providerApiCommand.setAction(ProviderAPI.SET_UP_PROVIDER);
providerApiCommand.putExtra(ProviderAPI.RECEIVER_KEY, mockResultReceiver(PROVIDER_NOK, expectedResult));
+ providerApiCommand.putExtra(PARAMETERS, mockBundle());
providerApiCommand.putExtra(PROVIDER_KEY, provider);
@@ -433,12 +440,12 @@ public class ProviderApiManagerTest {
expectedResult.putString(ERRORS, "{\"errors\":\"There was an error configuring Bitmask with your chosen provider.\"}");
expectedResult.putParcelable(PROVIDER_KEY, provider);
-
Intent providerApiCommand = mockIntent();
providerApiCommand.putExtra(PROVIDER_KEY, provider);
providerApiCommand.setAction(ProviderAPI.SET_UP_PROVIDER);
providerApiCommand.putExtra(ProviderAPI.RECEIVER_KEY, mockResultReceiver(PROVIDER_NOK, expectedResult));
+ providerApiCommand.putExtra(PARAMETERS, mockBundle());
providerApiManager.handleIntent(providerApiCommand);
}
@@ -461,12 +468,12 @@ public class ProviderApiManagerTest {
expectedResult.putString(ERRORS, "{\"errors\":\"There was an error configuring RiseupVPN.\"}");
expectedResult.putParcelable(PROVIDER_KEY, provider);
-
Intent providerApiCommand = mockIntent();
providerApiCommand.putExtra(PROVIDER_KEY, provider);
providerApiCommand.setAction(ProviderAPI.SET_UP_PROVIDER);
providerApiCommand.putExtra(ProviderAPI.RECEIVER_KEY, mockResultReceiver(PROVIDER_NOK, expectedResult));
+ providerApiCommand.putExtra(PARAMETERS, mockBundle());
providerApiManager.handleIntent(providerApiCommand);
}
@@ -484,12 +491,12 @@ public class ProviderApiManagerTest {
expectedResult.putBoolean(BROADCAST_RESULT_KEY, true);
expectedResult.putParcelable(PROVIDER_KEY, provider);
-
Intent providerApiCommand = mockIntent();
providerApiCommand.putExtra(PROVIDER_KEY, provider);
providerApiCommand.setAction(ProviderAPI.SET_UP_PROVIDER);
providerApiCommand.putExtra(ProviderAPI.RECEIVER_KEY, mockResultReceiver(PROVIDER_OK, expectedResult));
+ providerApiCommand.putExtra(PARAMETERS, mockBundle());
providerApiManager.handleIntent(providerApiCommand);
}
@@ -510,12 +517,12 @@ public class ProviderApiManagerTest {
expectedResult.putBoolean(BROADCAST_RESULT_KEY, false);
expectedResult.putParcelable(PROVIDER_KEY, provider);
expectedResult.putString(ERRORS, "This is not a trusted Bitmask provider.");
-
Intent providerApiCommand = mockIntent();
providerApiCommand.setAction(ProviderAPI.SET_UP_PROVIDER);
providerApiCommand.putExtra(ProviderAPI.RECEIVER_KEY, mockResultReceiver(PROVIDER_NOK, expectedResult));
providerApiCommand.putExtra(PROVIDER_KEY, provider);
+ providerApiCommand.putExtra(PARAMETERS, mockBundle());
providerApiManager.handleIntent(providerApiCommand);
}
@@ -685,12 +692,12 @@ public class ProviderApiManagerTest {
expectedResult.putBoolean(BROADCAST_RESULT_KEY, true);
expectedResult.putParcelable(PROVIDER_KEY, provider);
-
Intent providerApiCommand = mockIntent();
providerApiCommand.putExtra(PROVIDER_KEY, provider);
providerApiCommand.setAction(ProviderAPI.SET_UP_PROVIDER);
providerApiCommand.putExtra(ProviderAPI.RECEIVER_KEY, mockResultReceiver(PROVIDER_OK, expectedResult));
+ providerApiCommand.putExtra(PARAMETERS, mockBundle());
providerApiManager.handleIntent(providerApiCommand);
}
@@ -707,7 +714,7 @@ public class ProviderApiManagerTest {
providerApiCommand.putExtra(PROVIDER_KEY, provider);
providerApiCommand.setAction(ProviderAPI.SET_UP_PROVIDER);
providerApiCommand.putExtra(ProviderAPI.RECEIVER_KEY, mockResultReceiver(PROVIDER_OK));
-
+ providerApiCommand.putExtra(PARAMETERS, mockBundle());
mockTorStatusObservable(null);
providerApiManager.handleIntent(providerApiCommand);
@@ -727,7 +734,7 @@ public class ProviderApiManagerTest {
providerApiCommand.putExtra(PROVIDER_KEY, provider);
providerApiCommand.setAction(ProviderAPI.SET_UP_PROVIDER);
providerApiCommand.putExtra(ProviderAPI.RECEIVER_KEY, mockResultReceiver(PROVIDER_NOK));
-
+ providerApiCommand.putExtra(PARAMETERS, mockBundle());
mockTorStatusObservable(null);
providerApiManager.handleIntent(providerApiCommand);
@@ -746,7 +753,7 @@ public class ProviderApiManagerTest {
providerApiCommand.putExtra(PROVIDER_KEY, provider);
providerApiCommand.setAction(ProviderAPI.SET_UP_PROVIDER);
providerApiCommand.putExtra(ProviderAPI.RECEIVER_KEY, mockResultReceiver(PROVIDER_NOK));
-
+ providerApiCommand.putExtra(PARAMETERS, mockBundle());
mockTorStatusObservable(new TimeoutException("Tor took too long to start."));
providerApiManager.handleIntent(providerApiCommand);
@@ -767,7 +774,7 @@ public class ProviderApiManagerTest {
providerApiCommand.putExtra(PROVIDER_KEY, provider);
providerApiCommand.setAction(ProviderAPI.SET_UP_PROVIDER);
providerApiCommand.putExtra(ProviderAPI.RECEIVER_KEY, mockResultReceiver(PROVIDER_OK));
-
+ providerApiCommand.putExtra(PARAMETERS, mockBundle());
mockTorStatusObservable(null);
providerApiManager.handleIntent(providerApiCommand);
@@ -788,7 +795,7 @@ public class ProviderApiManagerTest {
providerApiCommand.putExtra(PROVIDER_KEY, provider);
providerApiCommand.setAction(ProviderAPI.SET_UP_PROVIDER);
providerApiCommand.putExtra(ProviderAPI.RECEIVER_KEY, mockResultReceiver(PROVIDER_OK));
-
+ providerApiCommand.putExtra(PARAMETERS, mockBundle());
mockTorStatusObservable(new TimeoutException("This timeout exception is never thrown"));
providerApiManager.handleIntent(providerApiCommand);
@@ -809,7 +816,7 @@ public class ProviderApiManagerTest {
providerApiCommand.putExtra(PROVIDER_KEY, provider);
providerApiCommand.setAction(ProviderAPI.UPDATE_INVALID_VPN_CERTIFICATE);
providerApiCommand.putExtra(ProviderAPI.RECEIVER_KEY, mockResultReceiver(CORRECTLY_UPDATED_INVALID_VPN_CERTIFICATE));
-
+ providerApiCommand.putExtra(PARAMETERS, mockBundle());
mockTorStatusObservable(null);
providerApiManager.handleIntent(providerApiCommand);
@@ -831,7 +838,7 @@ public class ProviderApiManagerTest {
providerApiCommand.putExtra(PROVIDER_KEY, provider);
providerApiCommand.setAction(ProviderAPI.UPDATE_INVALID_VPN_CERTIFICATE);
providerApiCommand.putExtra(ProviderAPI.RECEIVER_KEY, mockResultReceiver(INCORRECTLY_UPDATED_INVALID_VPN_CERTIFICATE));
-
+ providerApiCommand.putExtra(PARAMETERS, mockBundle());
mockTorStatusObservable(new TimeoutException("This timeout exception is never thrown"));
providerApiManager.handleIntent(providerApiCommand);
@@ -853,7 +860,7 @@ public class ProviderApiManagerTest {
providerApiCommand.putExtra(PROVIDER_KEY, provider);
providerApiCommand.setAction(ProviderAPI.UPDATE_INVALID_VPN_CERTIFICATE);
providerApiCommand.putExtra(ProviderAPI.RECEIVER_KEY, mockResultReceiver(CORRECTLY_UPDATED_INVALID_VPN_CERTIFICATE));
-
+ providerApiCommand.putExtra(PARAMETERS, mockBundle());
mockTorStatusObservable(null);
providerApiManager.handleIntent(providerApiCommand);
@@ -880,7 +887,7 @@ public class ProviderApiManagerTest {
providerApiCommand.putExtra(PROVIDER_KEY, provider);
providerApiCommand.setAction(ProviderAPI.UPDATE_INVALID_VPN_CERTIFICATE);
providerApiCommand.putExtra(ProviderAPI.RECEIVER_KEY, mockResultReceiver(TOR_EXCEPTION, expectedResult));
-
+ providerApiCommand.putExtra(PARAMETERS, mockBundle());
mockTorStatusObservable(new InterruptedException("Tor thread was interrupted."));
providerApiManager.handleIntent(providerApiCommand);
@@ -903,7 +910,7 @@ public class ProviderApiManagerTest {
providerApiCommand.putExtra(PROVIDER_KEY, provider);
providerApiCommand.setAction(ProviderAPI.SET_UP_PROVIDER);
providerApiCommand.putExtra(ProviderAPI.RECEIVER_KEY, mockResultReceiver(TOR_TIMEOUT, expectedResult));
-
+ providerApiCommand.putExtra(PARAMETERS, mockBundle());
mockTorStatusObservable(new TimeoutException("Tor took too long to start."));
providerApiManager.handleIntent(providerApiCommand);
@@ -928,7 +935,7 @@ public class ProviderApiManagerTest {
providerApiCommand.setAction(ProviderAPI.SET_UP_PROVIDER);
providerApiCommand.putExtra(ProviderAPI.RECEIVER_KEY, mockResultReceiver(MISSING_NETWORK_CONNECTION, expectedResult));
providerApiCommand.putExtra(PROVIDER_KEY, provider);
-
+ providerApiCommand.putExtra(PARAMETERS, mockBundle());
providerApiManager.handleIntent(providerApiCommand);
}
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