diff options
author | cyberta <cyberta@riseup.net> | 2020-01-29 12:23:48 -0600 |
---|---|---|
committer | cyberta <cyberta@riseup.net> | 2020-01-29 12:23:48 -0600 |
commit | 7a42047640daef05f5771d8cb812a03ee14bbec6 (patch) | |
tree | c1976d6256e9ec9b19873d50bece585addaa4b53 /app/src | |
parent | 7fbea5459e59de1327f2c76a23f5940d67e4ae8d (diff) |
adapt tests
Diffstat (limited to 'app/src')
3 files changed, 20 insertions, 10 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/firewall/SetupTetheringTask.java b/app/src/main/java/se/leap/bitmaskclient/firewall/SetupTetheringTask.java index 93054099..8bb197b1 100644 --- a/app/src/main/java/se/leap/bitmaskclient/firewall/SetupTetheringTask.java +++ b/app/src/main/java/se/leap/bitmaskclient/firewall/SetupTetheringTask.java @@ -155,8 +155,8 @@ public class SetupTetheringTask extends AsyncTask<Void, Boolean, Boolean> { "ip route delete broadcast 255.255.255.255 dev " + state.wifiInterface +" scope link table 61", "ip route delete " + state.lastWifiAddress + " dev " + state.wifiInterface +" scope link table 61", "ip route delete default dev " + getTunName() + " scope link table 61", - "if [[ `ip rule show from " + state.wifiAddress+ " lookup 61` ]]; " + - "then ip rule del from " + state.wifiAddress + " lookup 61; " + + "if [[ `ip rule show from " + state.lastWifiAddress+ " lookup 61` ]]; " + + "then ip rule del from " + state.lastWifiAddress + " lookup 61; " + "fi", }; return runBlockingCmd(removeRules, log) == 0; diff --git a/app/src/main/java/se/leap/bitmaskclient/tethering/TetheringStateManager.java b/app/src/main/java/se/leap/bitmaskclient/tethering/TetheringStateManager.java index 58d67872..11e1a83d 100644 --- a/app/src/main/java/se/leap/bitmaskclient/tethering/TetheringStateManager.java +++ b/app/src/main/java/se/leap/bitmaskclient/tethering/TetheringStateManager.java @@ -18,6 +18,7 @@ package se.leap.bitmaskclient.tethering; import android.content.Context; import android.content.IntentFilter; +import android.support.annotation.VisibleForTesting; import android.util.Log; import java.net.Inet4Address; @@ -94,13 +95,13 @@ public class TetheringStateManager { if (interfaceAddress.split("\\.").length == 4) { String result = interfaceAddress.substring(0, interfaceAddress.lastIndexOf(".")); result = result + ".0/24"; - Log.d(TAG, "wifiAddressRange = " + result); return result; } return ""; } - private static String getWifiInterfaceAddress() { + @VisibleForTesting + static String getWifiInterfaceAddress() { NetworkInterface networkInterface = getWlanInterface(); if (networkInterface != null) { List<InterfaceAddress> ifaceAddresses = networkInterface.getInterfaceAddresses(); @@ -113,7 +114,7 @@ public class TetheringStateManager { return ""; } - public static String getWifiInterfaceName() { + private static String getWifiInterfaceName() { NetworkInterface networkInterface = getWlanInterface(); if (networkInterface != null) { return networkInterface.getName(); diff --git a/app/src/test/java/se/leap/bitmaskclient/tethering/TetheringStateManagerTest.java b/app/src/test/java/se/leap/bitmaskclient/tethering/TetheringStateManagerTest.java index 295714c3..85352c53 100644 --- a/app/src/test/java/se/leap/bitmaskclient/tethering/TetheringStateManagerTest.java +++ b/app/src/test/java/se/leap/bitmaskclient/tethering/TetheringStateManagerTest.java @@ -39,6 +39,7 @@ import java.util.Enumeration; import se.leap.bitmaskclient.utils.Cmd; import static junit.framework.TestCase.assertTrue; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; @@ -57,7 +58,7 @@ public class TetheringStateManagerTest { @Mock(answer = Answers.RETURNS_DEEP_STUBS) IntentFilter intentFilter; - TetheringObservable observable; + private TetheringObservable observable; @Before public void setup() throws Exception { @@ -233,7 +234,7 @@ public class TetheringStateManagerTest { when(mockWrapper.isWifiAPEnabled()).thenThrow(new NoSuchMethodException()); PowerMockito.whenNew(WifiManagerWrapper.class).withAnyArguments().thenReturn(mockWrapper); - TetheringObservable.setWifiTethering(true); + TetheringObservable.setWifiTethering(true, "192.168.43.0/24", "wlan0"); TetheringStateManager.getInstance().init(mockContext); TetheringStateManager manager = TetheringStateManager.getInstance(); assertTrue(observable.isWifiTetheringEnabled()); @@ -245,7 +246,7 @@ public class TetheringStateManagerTest { when(mockWrapper.isWifiAPEnabled()).thenThrow(new NoSuchMethodException()); PowerMockito.whenNew(WifiManagerWrapper.class).withAnyArguments().thenReturn(mockWrapper); - TetheringObservable.setWifiTethering(false); + TetheringObservable.setWifiTethering(false, "", ""); TetheringStateManager.getInstance().init(mockContext); TetheringStateManager manager = TetheringStateManager.getInstance(); assertFalse(observable.isWifiTetheringEnabled()); @@ -257,7 +258,7 @@ public class TetheringStateManagerTest { when(mockWrapper.isWifiAPEnabled()).thenReturn(true); PowerMockito.whenNew(WifiManagerWrapper.class).withAnyArguments().thenReturn(mockWrapper); - TetheringObservable.setWifiTethering(false); + TetheringObservable.setWifiTethering(false, "", ""); TetheringStateManager.getInstance().init(mockContext); TetheringStateManager manager = TetheringStateManager.getInstance(); assertTrue(observable.isWifiTetheringEnabled()); @@ -269,11 +270,19 @@ public class TetheringStateManagerTest { when(mockWrapper.isWifiAPEnabled()).thenReturn(false); PowerMockito.whenNew(WifiManagerWrapper.class).withAnyArguments().thenReturn(mockWrapper); - TetheringObservable.setWifiTethering(true); + TetheringObservable.setWifiTethering(true, "", ""); TetheringStateManager.getInstance().init(mockContext); TetheringStateManager manager = TetheringStateManager.getInstance(); assertFalse(observable.isWifiTetheringEnabled()); } + @Test + public void testGetWifiAddressRange() { + mockStatic(TetheringStateManager.class); + PowerMockito.when(TetheringStateManager.getWifiInterfaceAddress()).thenReturn("192.168.40.217/24"); + PowerMockito.when(TetheringStateManager.getInstance()).thenCallRealMethod(); + PowerMockito.when(TetheringStateManager.getWifiAddressRange()).thenCallRealMethod(); + assertEquals("192.168.40.0/24", TetheringStateManager.getWifiAddressRange()); + } }
\ No newline at end of file |