diff options
author | cyBerta <cyberta@riseup.net> | 2025-02-27 22:43:44 +0100 |
---|---|---|
committer | cyberta <cyberta@riseup.net> | 2025-02-28 10:49:48 +0000 |
commit | c352890f3567e0c5502c59c797cff18a45e8bf69 (patch) | |
tree | 87248a089202ff28b04d63d42864e3a87eaeb431 /app/src/test/java/se/leap | |
parent | 968f27e03b59a9bd750a109446f49ff25fa199e1 (diff) |
update tests, add quic parsing tests and include fixes for updated hopping model classes
Diffstat (limited to 'app/src/test/java/se/leap')
5 files changed, 64 insertions, 13 deletions
diff --git a/app/src/test/java/se/leap/bitmaskclient/base/models/GatewayJsonTest.java b/app/src/test/java/se/leap/bitmaskclient/base/models/GatewayJsonTest.java index 801f98ad..1e07b293 100644 --- a/app/src/test/java/se/leap/bitmaskclient/base/models/GatewayJsonTest.java +++ b/app/src/test/java/se/leap/bitmaskclient/base/models/GatewayJsonTest.java @@ -12,7 +12,7 @@ public class GatewayJsonTest { @Test public void testToString() { - String gatewayJSON = "{\"location\":\"Unknown Location\",\"ip_address\":\"1.2.3.4\",\"host\":\"pinned.obfuscation.proxy\",\"capabilities\":{\"adblock\":false,\"filter_dns\":false,\"limited\":false,\"transport\":[{\"type\":\"obfs4\",\"protocols\":[\"tcp\"],\"ports\":[\"1194\"],\"options\":{\"cert\":\"xxxxxxx\",\"iatMode\":\"0\",\"experimental\":false,\"portSeed\":0,\"portCount\":0}}],\"user_ips\":false}}"; + String gatewayJSON = "{\"location\":\"Unknown Location\",\"ip_address\":\"1.2.3.4\",\"host\":\"pinned.obfuscation.proxy\",\"capabilities\":{\"adblock\":false,\"filter_dns\":false,\"limited\":false,\"transport\":[{\"type\":\"obfs4\",\"protocols\":[\"tcp\"],\"ports\":[\"1194\"],\"options\":{\"cert\":\"xxxxxxx\",\"iatMode\":\"0\",\"experimental\":false,\"portSeed\":0,\"portCount\":0,\"minHopPort\":0,\"maxHopPort\":0,\"minHopSeconds\":0,\"hopJitter\":0}}],\"user_ips\":false}}"; Connection.TransportType transportType = OBFS4; Transport[] transports = new Transport[]{ diff --git a/app/src/test/java/se/leap/bitmaskclient/base/models/ProviderTest.java b/app/src/test/java/se/leap/bitmaskclient/base/models/ProviderTest.java index dc35ecb9..fc2e6d03 100644 --- a/app/src/test/java/se/leap/bitmaskclient/base/models/ProviderTest.java +++ b/app/src/test/java/se/leap/bitmaskclient/base/models/ProviderTest.java @@ -125,6 +125,20 @@ public class ProviderTest { } @Test + public void testIsExperimentalPluggableTransportsSupported_Obfs4Quic_returnsTrue() throws Exception { + Provider p1 = TestSetupHelper.getProvider( + "https://pt.demo.bitmask.net", + null, + null, + null, + null, + null, + "multiple_pts_per_host_eip-service.json", + null); + assertTrue(p1.supportsExperimentalPluggableTransports()); + } + + @Test public void testSupportsPluggableTransports_Obfs4Kcp_obsvpn_returnsTrue() throws Exception { BuildConfigHelper helper = MockHelper.mockBuildConfigHelper(true); @@ -140,4 +154,20 @@ public class ProviderTest { assertTrue(p1.supportsPluggableTransports()); } + @Test + public void testSupportsPluggableTransports_Obfs4Quic_obsvpn_returnsTrue() throws Exception { + BuildConfigHelper helper = MockHelper.mockBuildConfigHelper(true); + + Provider p1 = TestSetupHelper.getProvider( + "https://pt.demo.bitmask.net", + null, + null, + null, + null, + null, + "ptdemo_only_experimental_transports_gateways.json", + null); + assertTrue(p1.supportsPluggableTransports()); + } + } diff --git a/app/src/test/java/se/leap/bitmaskclient/eip/GatewayTest.java b/app/src/test/java/se/leap/bitmaskclient/eip/GatewayTest.java index 88e58cd8..fc062079 100644 --- a/app/src/test/java/se/leap/bitmaskclient/eip/GatewayTest.java +++ b/app/src/test/java/se/leap/bitmaskclient/eip/GatewayTest.java @@ -1,11 +1,12 @@ package se.leap.bitmaskclient.eip; -import static org.junit.Assert.*; - +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; import static se.leap.bitmaskclient.base.models.Constants.GATEWAYS; -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.models.Provider.CA_CERT; import static se.leap.bitmaskclient.testutils.TestSetupHelper.getProvider; import android.content.Context; @@ -33,11 +34,8 @@ import de.blinkt.openvpn.core.ConfigParser; import de.blinkt.openvpn.core.connection.Connection; import de.blinkt.openvpn.core.connection.Obfs4Connection; import se.leap.bitmaskclient.base.models.Provider; -import se.leap.bitmaskclient.base.models.ProviderObservable; import se.leap.bitmaskclient.base.utils.PreferenceHelper; -import se.leap.bitmaskclient.base.utils.TimezoneHelper; import se.leap.bitmaskclient.testutils.MockSharedPreferences; -import se.leap.bitmaskclient.testutils.TestSetupHelper; @RunWith(RobolectricTestRunner.class) @Config(sdk = {Build.VERSION_CODES.P}) @@ -129,6 +127,7 @@ public class GatewayTest { assertTrue(gateway.supportsTransport(Connection.TransportType.OBFS4, null)); assertTrue(gateway.supportsTransport(Connection.TransportType.OBFS4, new HashSet<>(Arrays.asList("kcp")))); assertTrue(gateway.supportsTransport(Connection.TransportType.OBFS4, new HashSet<>(Arrays.asList("tcp")))); + assertTrue(gateway.supportsTransport(Connection.TransportType.OBFS4, new HashSet<>(Arrays.asList("quic")))); assertFalse(gateway.supportsTransport(Connection.TransportType.OBFS4, new HashSet<>(Arrays.asList("invalid")))); } diff --git a/app/src/test/java/se/leap/bitmaskclient/eip/VpnConfigGeneratorTest.java b/app/src/test/java/se/leap/bitmaskclient/eip/VpnConfigGeneratorTest.java index 327e2085..fa5d888b 100644 --- a/app/src/test/java/se/leap/bitmaskclient/eip/VpnConfigGeneratorTest.java +++ b/app/src/test/java/se/leap/bitmaskclient/eip/VpnConfigGeneratorTest.java @@ -1653,7 +1653,7 @@ public class VpnConfigGeneratorTest { configuration.obfuscationProxyPort = "443"; configuration.obfuscationProxyIP = "5.6.7.8"; configuration.obfuscationProxyCert = "asdfasdf"; - configuration.obfuscationProxyKCP = true; + configuration.obfuscationProxyTransportProtocol = "kcp"; configuration.remoteGatewayIP = "1.2.3.4"; configuration.transports = createTransportsFrom(gateway, 3); vpnConfigGenerator = new VpnConfigGenerator(generalConfig, secrets, configuration); @@ -1671,7 +1671,7 @@ public class VpnConfigGeneratorTest { VpnConfigGenerator.Configuration configuration = new VpnConfigGenerator.Configuration(); configuration.apiVersion = 3; configuration.useObfuscationPinning = true; - configuration.obfuscationProxyKCP = false; + configuration.obfuscationProxyTransportProtocol = "tcp"; configuration.obfuscationProxyPort = "443"; configuration.obfuscationProxyIP = "5.6.7.8"; configuration.obfuscationProxyCert = "asdfasdf"; @@ -1692,7 +1692,7 @@ public class VpnConfigGeneratorTest { VpnConfigGenerator.Configuration configuration = new VpnConfigGenerator.Configuration(); configuration.apiVersion = 3; configuration.useObfuscationPinning = true; - configuration.obfuscationProxyKCP = true; + configuration.obfuscationProxyTransportProtocol = "kcp"; configuration.obfuscationProxyPort = "443"; configuration.obfuscationProxyIP = "5.6.7.8"; configuration.obfuscationProxyCert = "asdfasdf"; @@ -1706,6 +1706,28 @@ public class VpnConfigGeneratorTest { assertTrue("bridge is pinned one", getVpnProfile(vpnProfiles, OBFS4).getTransportType() == OBFS4 && getVpnProfile(vpnProfiles, OBFS4).mGatewayIp.equals("1.2.3.4")); assertTrue("bridge is running KCP", ((Obfs4Connection) getVpnProfile(vpnProfiles, OBFS4).mConnections[0]).getObfs4Options().transport.getProtocols()[0].equals("kcp")); } + + @Test + public void testGenerateVpnProfile_ObfuscationPinningEnabled_quic_obfs4QuicProfile () throws Exception { + gateway = new JSONObject(TestSetupHelper.getInputAsString(getClass().getClassLoader().getResourceAsStream("ptdemo_kcp_gateways.json"))).getJSONArray("gateways").getJSONObject(0); + generalConfig = new JSONObject(TestSetupHelper.getInputAsString(getClass().getClassLoader().getResourceAsStream("ptdemo_kcp_gateways.json"))).getJSONObject(OPENVPN_CONFIGURATION); + VpnConfigGenerator.Configuration configuration = new VpnConfigGenerator.Configuration(); + configuration.apiVersion = 3; + configuration.useObfuscationPinning = true; + configuration.obfuscationProxyTransportProtocol = "quic"; + configuration.obfuscationProxyPort = "443"; + configuration.obfuscationProxyIP = "5.6.7.8"; + configuration.obfuscationProxyCert = "asdfasdf"; + configuration.remoteGatewayIP = "1.2.3.4"; + configuration.transports = createTransportsFrom(gateway, 3); + + vpnConfigGenerator = new VpnConfigGenerator(generalConfig, secrets, configuration); + Vector<VpnProfile> vpnProfiles = vpnConfigGenerator.generateVpnProfiles(); + assertFalse("has openvpn profile", containsKey(vpnProfiles, OPENVPN)); + assertTrue("has no obfs4 profile", containsKey(vpnProfiles, OBFS4)); + assertTrue("bridge is pinned one", getVpnProfile(vpnProfiles, OBFS4).getTransportType() == OBFS4 && getVpnProfile(vpnProfiles, OBFS4).mGatewayIp.equals("1.2.3.4")); + assertTrue("bridge is running QUIC", ((Obfs4Connection) getVpnProfile(vpnProfiles, OBFS4).mConnections[0]).getObfs4Options().transport.getProtocols()[0].equals("quic")); + } @Test public void testGenerateVpnProfile_obfs4hop_tcp () throws Exception { gateway = new JSONObject(TestSetupHelper.getInputAsString(getClass().getClassLoader().getResourceAsStream("ptdemo_obfs4hop_tcp_gateways.json"))).getJSONArray("gateways").getJSONObject(2); 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 c89d08cb..cb226033 100644 --- a/app/src/test/java/se/leap/bitmaskclient/testutils/MockHelper.java +++ b/app/src/test/java/se/leap/bitmaskclient/testutils/MockHelper.java @@ -203,8 +203,8 @@ public class MockHelper { } @Override - public boolean useKcp() { - return false; + public String obfsvpnTransportProtocol() { + return "tcp"; } @Override |