Skip to content

Commit

Permalink
Merge branch 'implement-wireguard-over-shadowsocks-droid-1276'
Browse files Browse the repository at this point in the history
  • Loading branch information
Rawa committed Sep 17, 2024
2 parents 196061b + 25857ce commit 9bd9d08
Show file tree
Hide file tree
Showing 66 changed files with 1,304 additions and 395 deletions.
1 change: 1 addition & 0 deletions android/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Line wrap the file at 100 chars. Th
## [Unreleased]
### Added
- Add support for predictive back.
- Add WireGuard over Shadowsocks.

### Changed
- Update colors in the app to be more in line with material design.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ private val DUMMY_RELAY_COUNTRY_2 =
)

private val DUMMY_WIREGUARD_PORT_RANGES = ArrayList<PortRange>()
private val DUMMY_WIREGUARD_ENDPOINT_DATA = WireguardEndpointData(DUMMY_WIREGUARD_PORT_RANGES)
private val DUMMY_SHADOWSOCKS_PORT_RANGES = emptyList<PortRange>()
private val DUMMY_WIREGUARD_ENDPOINT_DATA =
WireguardEndpointData(DUMMY_WIREGUARD_PORT_RANGES, DUMMY_SHADOWSOCKS_PORT_RANGES)

val DUMMY_RELAY_COUNTRIES = listOf(DUMMY_RELAY_COUNTRY_1, DUMMY_RELAY_COUNTRY_2)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import net.mullvad.mullvadvpn.compose.setContentWithTheme
import net.mullvad.mullvadvpn.compose.test.CUSTOM_PORT_DIALOG_INPUT_TEST_TAG
import net.mullvad.mullvadvpn.lib.model.PortRange
import net.mullvad.mullvadvpn.onNodeWithTagAndText
import net.mullvad.mullvadvpn.viewmodel.WireguardCustomPortDialogUiState
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.RegisterExtension
Expand All @@ -40,6 +39,7 @@ class CustomPortDialogTest {
@SuppressLint("ComposableNaming")
@Composable
private fun testWireguardCustomPortDialog(
title: String = "",
portInput: String = "",
isValidInput: Boolean = false,
showResetToDefault: Boolean = false,
Expand All @@ -49,16 +49,12 @@ class CustomPortDialogTest {
onResetPort: () -> Unit = {},
onDismiss: () -> Unit = {},
) {
val state =
WireguardCustomPortDialogUiState(
portInput = portInput,
isValidInput = isValidInput,
allowedPortRanges = allowedPortRanges,
showResetToDefault = showResetToDefault,
)

WireguardCustomPortDialog(
state,
CustomPortDialog(
title = title,
portInput = portInput,
isValidInput = isValidInput,
showResetToDefault = showResetToDefault,
allowedPortRanges = allowedPortRanges,
onInputChanged = onInputChanged,
onSavePort = onSavePort,
onDismiss = onDismiss,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package net.mullvad.mullvadvpn.compose.screen

import androidx.compose.ui.test.ExperimentalTestApi
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import io.mockk.mockk
import io.mockk.verify
import net.mullvad.mullvadvpn.compose.createEdgeToEdgeComposeExtension
import net.mullvad.mullvadvpn.compose.setContentWithTheme
import net.mullvad.mullvadvpn.compose.state.ShadowsocksSettingsState
import net.mullvad.mullvadvpn.compose.test.SHADOWSOCKS_CUSTOM_PORT_TEXT_TEST_TAG
import net.mullvad.mullvadvpn.lib.model.Constraint
import net.mullvad.mullvadvpn.lib.model.Port
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.RegisterExtension

@OptIn(ExperimentalTestApi::class)
class ShadowsocksSettingsScreenTest {
@JvmField @RegisterExtension val composeExtension = createEdgeToEdgeComposeExtension()

@Test
fun testShowShadowsocksCustomPort() =
composeExtension.use {
// Arrange
setContentWithTheme {
ShadowsocksSettingsScreen(state = ShadowsocksSettingsState(customPort = Port(4000)))
}

// Assert
onNodeWithText("4000").assertExists()
}

@Test
fun testSelectShadowsocksCustomPort() =
composeExtension.use {
// Arrange
val onObfuscationPortSelected: (Constraint<Port>) -> Unit = mockk(relaxed = true)
setContentWithTheme {
ShadowsocksSettingsScreen(
state =
ShadowsocksSettingsState(
port = Constraint.Only(Port(4000)),
customPort = Port(4000),
),
onObfuscationPortSelected = onObfuscationPortSelected,
)
}

// Act
onNodeWithTag(testTag = SHADOWSOCKS_CUSTOM_PORT_TEXT_TEST_TAG).performClick()

// Assert
verify { onObfuscationPortSelected.invoke(Constraint.Only(Port(4000))) }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package net.mullvad.mullvadvpn.compose.screen

import androidx.compose.ui.test.ExperimentalTestApi
import androidx.compose.ui.test.performClick
import io.mockk.coVerify
import io.mockk.mockk
import net.mullvad.mullvadvpn.compose.createEdgeToEdgeComposeExtension
import net.mullvad.mullvadvpn.compose.setContentWithTheme
import net.mullvad.mullvadvpn.compose.state.Udp2TcpSettingsState
import net.mullvad.mullvadvpn.compose.test.UDP_OVER_TCP_PORT_ITEM_X_TEST_TAG
import net.mullvad.mullvadvpn.lib.model.Constraint
import net.mullvad.mullvadvpn.lib.model.Port
import net.mullvad.mullvadvpn.onNodeWithTagAndText
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.RegisterExtension

@OptIn(ExperimentalTestApi::class)
class Udp2TcpSettingsScreenTest {
@JvmField @RegisterExtension val composeExtension = createEdgeToEdgeComposeExtension()

@Test
fun testSelectTcpOverUdpPortOption() =
composeExtension.use {
// Arrange
val onObfuscationPortSelected: (Constraint<Port>) -> Unit = mockk(relaxed = true)
setContentWithTheme {
Udp2TcpSettingsScreen(
state = Udp2TcpSettingsState(port = Constraint.Any),
onObfuscationPortSelected = onObfuscationPortSelected,
)
}

// Act
onNodeWithTagAndText(
testTag = String.format(UDP_OVER_TCP_PORT_ITEM_X_TEST_TAG, 5001),
text = "5001",
)
.assertExists()
.performClick()

// Assert
coVerify(exactly = 1) { onObfuscationPortSelected.invoke(Constraint.Only(Port(5001))) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import androidx.compose.ui.test.performScrollToNode
import io.mockk.MockKAnnotations
import io.mockk.coVerify
import io.mockk.mockk
import io.mockk.verify
import net.mullvad.mullvadvpn.compose.createEdgeToEdgeComposeExtension
Expand All @@ -18,17 +17,15 @@ import net.mullvad.mullvadvpn.compose.test.LAZY_LIST_LAST_ITEM_TEST_TAG
import net.mullvad.mullvadvpn.compose.test.LAZY_LIST_QUANTUM_ITEM_OFF_TEST_TAG
import net.mullvad.mullvadvpn.compose.test.LAZY_LIST_QUANTUM_ITEM_ON_TEST_TAG
import net.mullvad.mullvadvpn.compose.test.LAZY_LIST_TEST_TAG
import net.mullvad.mullvadvpn.compose.test.LAZY_LIST_UDP_OVER_TCP_PORT_ITEM_X_TEST_TAG
import net.mullvad.mullvadvpn.compose.test.LAZY_LIST_UDP_OVER_TCP_PORT_TEST_TAG
import net.mullvad.mullvadvpn.compose.test.LAZY_LIST_WIREGUARD_CUSTOM_PORT_NUMBER_TEST_TAG
import net.mullvad.mullvadvpn.compose.test.LAZY_LIST_WIREGUARD_CUSTOM_PORT_TEXT_TEST_TAG
import net.mullvad.mullvadvpn.compose.test.LAZY_LIST_WIREGUARD_OBFUSCATION_TITLE_TEST_TAG
import net.mullvad.mullvadvpn.compose.test.LAZY_LIST_WIREGUARD_PORT_ITEM_X_TEST_TAG
import net.mullvad.mullvadvpn.lib.model.Constraint
import net.mullvad.mullvadvpn.lib.model.Mtu
import net.mullvad.mullvadvpn.lib.model.Port
import net.mullvad.mullvadvpn.lib.model.PortRange
import net.mullvad.mullvadvpn.lib.model.QuantumResistantState
import net.mullvad.mullvadvpn.lib.model.SelectedObfuscation
import net.mullvad.mullvadvpn.onNodeWithTagAndText
import net.mullvad.mullvadvpn.viewmodel.CustomDnsItem
import org.junit.jupiter.api.BeforeEach
Expand Down Expand Up @@ -206,74 +203,6 @@ class VpnSettingsScreenTest {
onNodeWithContentDescription(LOCAL_DNS_SERVER_WARNING).assertExists()
}

@Test
fun testSelectTcpOverUdpPortOption() =
composeExtension.use {
// Arrange
val onObfuscationPortSelected: (Constraint<Port>) -> Unit = mockk(relaxed = true)
setContentWithTheme {
VpnSettingsScreen(
state =
VpnSettingsUiState.createDefault(
selectedObfuscation = SelectedObfuscation.Udp2Tcp,
selectedObfuscationPort = Constraint.Only(Port(5001)),
),
onObfuscationPortSelected = onObfuscationPortSelected,
)
}

// Act
onNodeWithTag(LAZY_LIST_TEST_TAG)
.performScrollToNode(hasTestTag(LAZY_LIST_UDP_OVER_TCP_PORT_TEST_TAG))
onNodeWithText("UDP-over-TCP port").performClick()
onNodeWithTag(LAZY_LIST_TEST_TAG)
.performScrollToNode(
hasTestTag(String.format(LAZY_LIST_UDP_OVER_TCP_PORT_ITEM_X_TEST_TAG, 5001))
)

// Assert
onNodeWithTagAndText(
testTag = String.format(LAZY_LIST_UDP_OVER_TCP_PORT_ITEM_X_TEST_TAG, 5001),
text = "5001",
)
.assertExists()
.performClick()

coVerify(exactly = 1) { onObfuscationPortSelected.invoke(Constraint.Only(Port(5001))) }
}

@Test
fun testAttemptSelectTcpOverUdpPortOption() =
composeExtension.use {
// Arrange
val onObfuscationPortSelected: (Constraint<Port>) -> Unit = mockk(relaxed = true)
setContentWithTheme {
VpnSettingsScreen(
state =
VpnSettingsUiState.createDefault(
selectedObfuscation = SelectedObfuscation.Off
),
onObfuscationPortSelected = onObfuscationPortSelected,
)
}

// Act
onNodeWithTag(LAZY_LIST_TEST_TAG)
.performScrollToNode(hasTestTag(LAZY_LIST_UDP_OVER_TCP_PORT_TEST_TAG))
onNodeWithText("UDP-over-TCP port").performClick()
onNodeWithTag(LAZY_LIST_TEST_TAG)
.performScrollToNode(
hasTestTag(String.format(LAZY_LIST_UDP_OVER_TCP_PORT_ITEM_X_TEST_TAG, 5001))
)

// Assert
onNodeWithTag(String.format(LAZY_LIST_UDP_OVER_TCP_PORT_ITEM_X_TEST_TAG, 5001))
.assertExists()
.performClick()

verify(exactly = 0) { onObfuscationPortSelected.invoke(any()) }
}

@Test
fun testShowSelectedTunnelQuantumOption() =
composeExtension.use {
Expand Down Expand Up @@ -386,10 +315,7 @@ class VpnSettingsScreenTest {
// Arrange
setContentWithTheme {
VpnSettingsScreen(
state =
VpnSettingsUiState.createDefault(
customWireguardPort = Constraint.Only(Port(4000))
)
state = VpnSettingsUiState.createDefault(customWireguardPort = Port(4000))
)
}

Expand All @@ -411,7 +337,7 @@ class VpnSettingsScreenTest {
state =
VpnSettingsUiState.createDefault(
selectedWireguardPort = Constraint.Only(Port(4000)),
customWireguardPort = Constraint.Only(Port(4000)),
customWireguardPort = Port(4000),
),
onWireguardPortSelected = onWireguardPortSelected,
)
Expand Down Expand Up @@ -483,9 +409,8 @@ class VpnSettingsScreenTest {
}

// Act

onNodeWithTag(LAZY_LIST_TEST_TAG)
.performScrollToNode(hasTestTag(LAZY_LIST_UDP_OVER_TCP_PORT_TEST_TAG))
.performScrollToNode(hasTestTag(LAZY_LIST_WIREGUARD_OBFUSCATION_TITLE_TEST_TAG))
onNodeWithText("WireGuard obfuscation").performClick()

// Assert
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ fun InformationComposeCell(
background: Color = MaterialTheme.colorScheme.primary,
onCellClicked: () -> Unit = {},
onInfoClicked: (() -> Unit)? = null,
testTag: String = "",
) {
val titleModifier = Modifier.alpha(if (isEnabled) AlphaVisible else AlphaInactive)
val bodyViewModifier = Modifier
Expand All @@ -60,6 +61,7 @@ fun InformationComposeCell(
InformationComposeCellBody(modifier = bodyViewModifier, onInfoClicked = onInfoClicked)
},
onCellClicked = onCellClicked,
testTag = testTag,
)
}

Expand Down
Loading

0 comments on commit 9bd9d08

Please sign in to comment.