summaryrefslogtreecommitdiff
path: root/app/src/androidTest
diff options
context:
space:
mode:
authorcyBerta <cyberta@riseup.net>2017-09-14 17:30:47 +0200
committercyBerta <cyberta@riseup.net>2017-09-14 17:30:47 +0200
commit7cbf75518603ba4f5bc47cc5bf5cbd9fac289a41 (patch)
tree47518d23bd609acfae793d1691896b79e9368945 /app/src/androidTest
parenta5fe0aa9ae57c688d3a8373a1a7bae0b91efd9d7 (diff)
refactor failing certification validation test
Diffstat (limited to 'app/src/androidTest')
-rw-r--r--app/src/androidTest/java/se/leap/bitmaskclient/test/TestCalendarProvider.java26
-rw-r--r--app/src/androidTest/java/se/leap/bitmaskclient/test/TestVpnCertificateValidator.java44
2 files changed, 64 insertions, 6 deletions
diff --git a/app/src/androidTest/java/se/leap/bitmaskclient/test/TestCalendarProvider.java b/app/src/androidTest/java/se/leap/bitmaskclient/test/TestCalendarProvider.java
new file mode 100644
index 00000000..82ea8b59
--- /dev/null
+++ b/app/src/androidTest/java/se/leap/bitmaskclient/test/TestCalendarProvider.java
@@ -0,0 +1,26 @@
+package se.leap.bitmaskclient.test;
+
+import java.util.Calendar;
+
+import se.leap.bitmaskclient.eip.CalendarProviderInterface;
+
+/**
+ * Created by cyberta on 13.09.17.
+ */
+
+class TestCalendarProvider implements CalendarProviderInterface {
+
+ private long currentTimeInMillis = 0;
+
+ public TestCalendarProvider(long currentTimeInMillis) {
+ this.currentTimeInMillis = currentTimeInMillis;
+ }
+
+ @Override
+ public Calendar getCalendar() {
+ Calendar calendar = Calendar.getInstance();
+ calendar.setTimeInMillis(currentTimeInMillis);
+ return calendar;
+ }
+
+}
diff --git a/app/src/androidTest/java/se/leap/bitmaskclient/test/TestVpnCertificateValidator.java b/app/src/androidTest/java/se/leap/bitmaskclient/test/TestVpnCertificateValidator.java
index 672607be..2704bcad 100644
--- a/app/src/androidTest/java/se/leap/bitmaskclient/test/TestVpnCertificateValidator.java
+++ b/app/src/androidTest/java/se/leap/bitmaskclient/test/TestVpnCertificateValidator.java
@@ -30,10 +30,11 @@ import se.leap.bitmaskclient.eip.*;
/**
* @author parmegv
+ * //FIXME: The class VpnCertificateValidator should be tested with unit tests!
*/
-public class testVpnCertificateValidator extends InstrumentationTestCase {
+public class TestVpnCertificateValidator extends InstrumentationTestCase {
- String certificate_valid_from_jan2015_to_nov2022 = "";
+ String certificate_valid_from_nov2012_to_nov2022 = "";
Context context;
FromAssets assets;
@@ -43,16 +44,47 @@ public class testVpnCertificateValidator extends InstrumentationTestCase {
context = getInstrumentation().getContext();
assets = new FromAssets(context);
JSONObject secrets = new JSONObject(assets.toString(TestConstants.SECRETS_FILE));
- certificate_valid_from_jan2015_to_nov2022 = secrets.getString(Provider.CA_CERT);
+ certificate_valid_from_nov2012_to_nov2022 = secrets.getString(Provider.CA_CERT);
super.setUp();
}
+
+ //TODO: This test proves that the validation method is weird. Valid dates range between Nov. 2oo6 and Nov. 2017 instead of Nov. 2012 and Nov.2022
public void testIsValid() {
- VpnCertificateValidator validator = new VpnCertificateValidator(certificate_valid_from_jan2015_to_nov2022);
- setTime(2015, 1, 6);
+ VpnCertificateValidator validator = new VpnCertificateValidator(certificate_valid_from_nov2012_to_nov2022);
+ Calendar calendar = Calendar.getInstance();
+
+ calendar.set(Calendar.YEAR, 2006);
+ calendar.set(Calendar.MONTH, Calendar.NOVEMBER);
+ calendar.set(Calendar.DAY_OF_MONTH, 6); calendar.set(Calendar.YEAR, 2006);
+ validator.setCalendarProvider(new TestCalendarProvider(calendar.getTimeInMillis()));
+ assertFalse(validator.isValid());
+
+ calendar.set(Calendar.YEAR, 2010);
+ calendar.set(Calendar.MONTH, Calendar.NOVEMBER);
+ calendar.set(Calendar.DAY_OF_MONTH, 6);
+ validator.setCalendarProvider(new TestCalendarProvider(calendar.getTimeInMillis()));
+ assertTrue(validator.isValid());
+
+ calendar.set(Calendar.YEAR, 2011);
+ calendar.set(Calendar.MONTH, Calendar.NOVEMBER);
+ calendar.set(Calendar.DAY_OF_MONTH, 6);
+ validator.setCalendarProvider(new TestCalendarProvider(calendar.getTimeInMillis()));
assertTrue(validator.isValid());
- setTime(2020, 1, 6);
+
+ calendar.set(Calendar.YEAR, 2017);
+ calendar.set(Calendar.MONTH, Calendar.NOVEMBER);
+ calendar.set(Calendar.DAY_OF_MONTH, 5);
+ validator.setCalendarProvider(new TestCalendarProvider(calendar.getTimeInMillis()));
+ assertTrue(validator.isValid());
+
+ calendar.set(Calendar.YEAR, 2017);
+ calendar.set(Calendar.MONTH, Calendar.NOVEMBER);
+ calendar.set(Calendar.DAY_OF_MONTH, 6);
+ validator.setCalendarProvider(new TestCalendarProvider(calendar.getTimeInMillis()));
assertFalse(validator.isValid());
+
+
}
private void setTime(int year, int month, int day) {