From e1f028e6a27f209ed1f1773c234faf85085d87ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Parm=C3=A9nides=20GV?= Date: Wed, 7 Jan 2015 16:44:11 +0100 Subject: Tests for valid certificate. --- .../test/testVpnCertificateValidator.java | 77 ++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 app/src/androidTest/java/se/leap/bitmaskclient/test/testVpnCertificateValidator.java (limited to 'app/src/androidTest/java/se/leap/bitmaskclient/test/testVpnCertificateValidator.java') diff --git a/app/src/androidTest/java/se/leap/bitmaskclient/test/testVpnCertificateValidator.java b/app/src/androidTest/java/se/leap/bitmaskclient/test/testVpnCertificateValidator.java new file mode 100644 index 00000000..87154956 --- /dev/null +++ b/app/src/androidTest/java/se/leap/bitmaskclient/test/testVpnCertificateValidator.java @@ -0,0 +1,77 @@ +/** + * Copyright (c) 2013, 2014, 2015 LEAP Encryption Access Project and contributers + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package se.leap.bitmaskclient.test; + +import android.content.Context; +import android.os.SystemClock; +import android.test.InstrumentationTestCase; + +import org.json.JSONObject; + +import java.io.IOException; +import java.util.Calendar; + +import se.leap.bitmaskclient.Provider; +import se.leap.bitmaskclient.eip.VpnCertificateValidator; + +/** + * @author parmegv + */ +public class testVpnCertificateValidator extends InstrumentationTestCase { + + String certificate_valid_from_jan2015_to_nov2022 = ""; + + Context context; + FromAssets assets; + + @Override + protected void setUp() throws Exception { + 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); + super.setUp(); + } + + public void testIsValid() { + VpnCertificateValidator validator = new VpnCertificateValidator(certificate_valid_from_jan2015_to_nov2022); + setTime(2015, 1, 6); + assertTrue(validator.isValid()); + setTime(2020, 1, 6); + assertFalse(validator.isValid()); + } + + private void setTime(int year, int month, int day) { + shellCommand("adb shell chmod 666 /dev/alarm"); + Calendar c = Calendar.getInstance(); + c.set(year, month, day, 12, 00, 00); + SystemClock.setCurrentTimeMillis(c.getTimeInMillis()); + shellCommand("adb shell chmod 664 /dev/alarm"); + } + + private int shellCommand(String command) { + int result = -1; + try { + result = Runtime.getRuntime().exec(command).waitFor(); + } catch (InterruptedException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + return result; + } +} -- cgit v1.2.3 From 250b56762857f2e52626236d3716459786ce126d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Parm=C3=A9nides=20GV?= Date: Thu, 15 Jan 2015 15:24:52 +0100 Subject: More tests, sometimes they don't pass sometimes do testIsValid depends on the speed of Runtime's exec: sometimes it's quick and passes (because it changes the date correctly) and sometimes is not. A waitFor doesn't fix the issue, it waits forever. --- .../test/testVpnCertificateValidator.java | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) (limited to 'app/src/androidTest/java/se/leap/bitmaskclient/test/testVpnCertificateValidator.java') 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 87154956..cd1d6c3b 100644 --- a/app/src/androidTest/java/se/leap/bitmaskclient/test/testVpnCertificateValidator.java +++ b/app/src/androidTest/java/se/leap/bitmaskclient/test/testVpnCertificateValidator.java @@ -16,17 +16,17 @@ */ package se.leap.bitmaskclient.test; -import android.content.Context; -import android.os.SystemClock; -import android.test.InstrumentationTestCase; +import android.content.*; +import android.os.*; +import android.test.*; -import org.json.JSONObject; +import org.json.*; -import java.io.IOException; -import java.util.Calendar; +import java.io.*; +import java.util.*; -import se.leap.bitmaskclient.Provider; -import se.leap.bitmaskclient.eip.VpnCertificateValidator; +import se.leap.bitmaskclient.*; +import se.leap.bitmaskclient.eip.*; /** * @author parmegv @@ -64,11 +64,9 @@ public class testVpnCertificateValidator extends InstrumentationTestCase { } private int shellCommand(String command) { - int result = -1; + int result = 0; try { - result = Runtime.getRuntime().exec(command).waitFor(); - } catch (InterruptedException e) { - e.printStackTrace(); + Runtime.getRuntime().exec(command); } catch (IOException e) { e.printStackTrace(); } -- cgit v1.2.3