diff options
Diffstat (limited to 'app/src/test')
4 files changed, 104 insertions, 49 deletions
diff --git a/app/src/test/java/se/leap/bitmaskclient/base/utils/DateHelperTest.java b/app/src/test/java/se/leap/bitmaskclient/base/utils/DateHelperTest.java new file mode 100644 index 00000000..2651a64d --- /dev/null +++ b/app/src/test/java/se/leap/bitmaskclient/base/utils/DateHelperTest.java @@ -0,0 +1,20 @@ +package se.leap.bitmaskclient.base.utils; + +import static org.junit.Assert.*; + +import org.junit.Test; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class DateHelperTest { + + @Test + public void getFormattedDateWithTimezone() { + Pattern datePattern = Pattern.compile("^10 Nov 22 [1]?[0-9]:26 [+-][0-9]{4}$"); + String formattedDate = DateHelper.getFormattedDateWithTimezone(1668075969744L); + Matcher matcher = datePattern.matcher(formattedDate); + System.out.println(formattedDate); + assertTrue("date should be formatted similar to 10 Nov 22 11:26 +0100", matcher.find()); + } +}
\ No newline at end of file diff --git a/app/src/test/java/se/leap/bitmaskclient/testutils/MockHelper.java b/app/src/test/java/se/leap/bitmaskclient/testutils/MockHelper.java index c6ba1e6f..e14fa4c3 100644 --- a/app/src/test/java/se/leap/bitmaskclient/testutils/MockHelper.java +++ b/app/src/test/java/se/leap/bitmaskclient/testutils/MockHelper.java @@ -12,11 +12,17 @@ import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import static org.powermock.api.mockito.PowerMockito.mockStatic; +import static se.leap.bitmaskclient.base.models.Constants.PROVIDER_MOTD; +import static se.leap.bitmaskclient.base.models.Constants.PROVIDER_MOTD_HASHES; +import static se.leap.bitmaskclient.base.models.Constants.PROVIDER_MOTD_LAST_SEEN; +import static se.leap.bitmaskclient.base.models.Constants.PROVIDER_MOTD_LAST_UPDATED; import static se.leap.bitmaskclient.base.models.Constants.PROVIDER_PRIVATE_KEY; import static se.leap.bitmaskclient.base.models.Constants.PROVIDER_VPN_CERTIFICATE; import static se.leap.bitmaskclient.base.utils.FileHelper.createFile; import static se.leap.bitmaskclient.base.utils.PreferenceHelper.getEipDefinitionFromPreferences; import static se.leap.bitmaskclient.base.utils.PreferenceHelper.getFromPersistedProvider; +import static se.leap.bitmaskclient.base.utils.PreferenceHelper.getLongFromPersistedProvider; +import static se.leap.bitmaskclient.base.utils.PreferenceHelper.getStringSetFromPersistedProvider; import android.content.Context; import android.content.Intent; @@ -474,11 +480,39 @@ public class MockHelper { return providerFromPrefs.getCaCert(); case Provider.GEOIP_URL: return providerFromPrefs.getGeoipUrl().toString(); + case Provider.MOTD_URL: + return providerFromPrefs.getMotdUrl().toString(); + case PROVIDER_MOTD: + return providerFromPrefs.getMotdJsonString(); } return null; } }); + when(getLongFromPersistedProvider(anyString(), anyString(), any(SharedPreferences.class))).thenAnswer(new Answer<Long>() { + @Override + public Long answer(InvocationOnMock invocation) throws Throwable { + String key = (String) invocation.getArguments()[0]; + switch (key) { + case PROVIDER_MOTD_LAST_SEEN: + return providerFromPrefs.getLastMotdSeen(); + case PROVIDER_MOTD_LAST_UPDATED: + return providerFromPrefs.getLastMotdUpdate(); + } + return 0L; + } + }); + when(getStringSetFromPersistedProvider(anyString(), anyString(), any(SharedPreferences.class))).thenAnswer(new Answer<Set<String>>() { + @Override + public Set<String> answer(InvocationOnMock invocation) throws Throwable { + String key = (String) invocation.getArguments()[0]; + switch (key) { + case PROVIDER_MOTD_HASHES: + return providerFromPrefs.getMotdLastSeenHashes(); + } + return null; + } + }); } public static void mockPreferenceHelper(MockSharedPreferences preferences) { diff --git a/app/src/test/java/se/leap/bitmaskclient/testutils/MockSharedPreferences.java b/app/src/test/java/se/leap/bitmaskclient/testutils/MockSharedPreferences.java index be0cf41f..4fabc2c0 100644 --- a/app/src/test/java/se/leap/bitmaskclient/testutils/MockSharedPreferences.java +++ b/app/src/test/java/se/leap/bitmaskclient/testutils/MockSharedPreferences.java @@ -21,6 +21,7 @@ import android.content.SharedPreferences; import androidx.annotation.Nullable; import java.util.HashMap; +import java.util.HashSet; import java.util.Map; import java.util.Set; @@ -48,7 +49,7 @@ public class MockSharedPreferences implements SharedPreferences { @Nullable @Override public Set<String> getStringSet(String key, @Nullable Set<String> defValues) { - return null; + return new HashSet<>(); } @Override diff --git a/app/src/test/resources/v4/riseup.net.cert b/app/src/test/resources/v4/riseup.net.cert index 86bc0b55..1beff4bd 100644 --- a/app/src/test/resources/v4/riseup.net.cert +++ b/app/src/test/resources/v4/riseup.net.cert @@ -1,54 +1,54 @@ -----BEGIN RSA PRIVATE KEY----- -MIIEpAIBAAKCAQEAwtqqSbTsB/JchPr41KdSyTWfG+qBxRfbqYw5hx8VxzuVNPn4 -nEmKm4KbtEhZLT3Kk0yJa+9X3UBVkeTrI6IZQmsK1s1lq9YTcwjsryza//xtw6gM -7Wd8X8FaMnaYPBBRpaWWi//RsrLmztm0kSU1pJbgSL1VJsngGImWPcnAPvhPS4IG -6XD/4DLyog7Hyg0yuZyBf6DzvQUMFh/B9Sm+ogY8nG+vEaoN/RaKn25M+uC6NC2v -X+9wcqLyQeh0JsIA23foyyWlA2sW2+ad4VWfI3DpXwYCnCuJZlD3JZoLP8OoQacl -PsBIll+n6KeVcE7H7af2CkNinFa+0CgMYtvpgQIDAQABAoIBAQC5ufkkRinQLUfY -jOuOrmovVUfyMOU+es4qXnka/RsiCv3eQAGi3koajjRhc7BkeghTvFkkIz9pqX+m -jz89eK2A7Eypj5/AWU2ykSgglK2t3+qz2sNvqfsXvlF91iKm5ZsdO6cyjEVRgkqT -kVkWHBR0bEcdrjGyxisu2D33aQ0wNo1ENoJYJEe+F+fcm3IhVsSCMWEoYeX+RXXq -scwGgwNSn3V4fEqQA7Hs77ri+gjbuIf6KZ3DPcQTpJ4ST6UcJkyXowLLYFmPgVJt -XOqJ5sjDUNLgX2F6LJj8r0C2V0UmRoed/ZONmB2AVr/e/BmGB4zLVOFv4NLK52CP -m3B4SrPNAoGBAPEJcfFPAOAHIW51xz2l61W4d4rqvu54IuHYMGWRJjtNx/zqIxwE -I4hTHz9jz++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zLhcC9dLLXC4ef +zH25zfe7vkt58UcuG+YCsaIR8Hy3I/yDQWVkbNawEYUboEHHRd8pQmUIkHLaYibt +eq1SXtuulUUDIkyfRATiA/GkPVPPnJImL8XK12WFPQ== +-----END CERTIFICATE----- |