summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDavid Göransson <david.goransson@mullvad.net>2024-09-17 15:28:58 +0200
committerDavid Göransson <david.goransson@mullvad.net>2024-09-18 14:35:22 +0200
commitc06026cae12be2757376883dfbf879528e545b4f (patch)
treeb533d83806ec42fcbe242e693032d4db62e45d4a
parent567e64f458781112eae97f860e8e2796e78507a3 (diff)
downloadmullvadvpn-c06026cae12be2757376883dfbf879528e545b4f.tar.xz
mullvadvpn-c06026cae12be2757376883dfbf879528e545b4f.zip
Fix tests
-rw-r--r--android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/ConnectScreenTest.kt172
-rw-r--r--android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/ConnectViewModelTest.kt16
-rw-r--r--android/test/common/src/main/kotlin/net/mullvad/mullvadvpn/test/common/interactor/AppInteractor.kt11
-rw-r--r--android/test/e2e/src/main/kotlin/net/mullvad/mullvadvpn/test/e2e/ConnectionTest.kt10
4 files changed, 52 insertions, 157 deletions
diff --git a/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/ConnectScreenTest.kt b/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/ConnectScreenTest.kt
index c9cd30e439..1ae19c534a 100644
--- a/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/ConnectScreenTest.kt
+++ b/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/ConnectScreenTest.kt
@@ -14,10 +14,9 @@ import net.mullvad.mullvadvpn.compose.setContentWithTheme
import net.mullvad.mullvadvpn.compose.state.ConnectUiState
import net.mullvad.mullvadvpn.compose.test.CIRCULAR_PROGRESS_INDICATOR
import net.mullvad.mullvadvpn.compose.test.CONNECT_BUTTON_TEST_TAG
-import net.mullvad.mullvadvpn.compose.test.LOCATION_INFO_TEST_TAG
+import net.mullvad.mullvadvpn.compose.test.CONNECT_CARD_HEADER_TEST_TAG
import net.mullvad.mullvadvpn.compose.test.NOTIFICATION_BANNER_ACTION
import net.mullvad.mullvadvpn.compose.test.RECONNECT_BUTTON_TEST_TAG
-import net.mullvad.mullvadvpn.compose.test.SCROLLABLE_COLUMN_TEST_TAG
import net.mullvad.mullvadvpn.compose.test.SELECT_LOCATION_BUTTON_TEST_TAG
import net.mullvad.mullvadvpn.compose.test.TOP_BAR_ACCOUNT_BUTTON
import net.mullvad.mullvadvpn.lib.model.ActionAfterDisconnect
@@ -59,9 +58,8 @@ class ConnectScreenTest {
setContentWithTheme { ConnectScreen(state = ConnectUiState.INITIAL) }
// Assert
- onNodeWithTag(SCROLLABLE_COLUMN_TEST_TAG).assertExists()
- onNodeWithText("UNSECURED CONNECTION").assertExists()
- onNodeWithText("Secure my connection").assertExists()
+ onNodeWithText("DISCONNECTED").assertExists()
+ onNodeWithText("Connect").assertExists()
}
}
@@ -76,8 +74,6 @@ class ConnectScreenTest {
location = null,
selectedRelayItemTitle = null,
tunnelState = TunnelState.Connecting(null, null, emptyList()),
- inAddress = null,
- outAddress = "",
showLocation = false,
deviceName = "",
daysLeftUntilExpiry = null,
@@ -89,45 +85,7 @@ class ConnectScreenTest {
// Assert
onNodeWithTag(CIRCULAR_PROGRESS_INDICATOR).assertExists()
- onNodeWithText("CREATING SECURE CONNECTION").assertExists()
- onNodeWithText("Switch location").assertExists()
- onNodeWithText("Cancel").assertExists()
- onNodeWithText("BLOCKING INTERNET").assertExists()
- }
- }
-
- @Test
- fun testConnectingStateQuantumSecured() {
- composeExtension.use {
- // Arrange
- val mockTunnelEndpoint: TunnelEndpoint = mockk(relaxed = true)
- every { mockTunnelEndpoint.quantumResistant } returns true
- setContentWithTheme {
- ConnectScreen(
- state =
- ConnectUiState(
- location = null,
- selectedRelayItemTitle = null,
- tunnelState =
- TunnelState.Connecting(
- endpoint = mockTunnelEndpoint,
- null,
- emptyList(),
- ),
- inAddress = null,
- outAddress = "",
- showLocation = false,
- deviceName = "",
- daysLeftUntilExpiry = null,
- inAppNotification = InAppNotification.TunnelStateBlocked,
- isPlayBuild = false,
- )
- )
- }
-
- // Assert
- onNodeWithTag(CIRCULAR_PROGRESS_INDICATOR).assertExists()
- onNodeWithText("CREATING QUANTUM SECURE CONNECTION").assertExists()
+ onNodeWithText("CONNECTING...").assertExists()
onNodeWithText("Switch location").assertExists()
onNodeWithText("Cancel").assertExists()
onNodeWithText("BLOCKING INTERNET").assertExists()
@@ -147,40 +105,6 @@ class ConnectScreenTest {
selectedRelayItemTitle = null,
tunnelState =
TunnelState.Connected(mockTunnelEndpoint, null, emptyList()),
- inAddress = null,
- outAddress = "",
- showLocation = false,
- deviceName = "",
- daysLeftUntilExpiry = null,
- inAppNotification = null,
- isPlayBuild = false,
- )
- )
- }
-
- // Assert
- onNodeWithText("SECURE CONNECTION").assertExists()
- onNodeWithText("Switch location").assertExists()
- onNodeWithText("Disconnect").assertExists()
- }
- }
-
- @Test
- fun testConnectedStateQuantumSecured() {
- composeExtension.use {
- // Arrange
- val mockTunnelEndpoint: TunnelEndpoint = mockk(relaxed = true)
- every { mockTunnelEndpoint.quantumResistant } returns true
- setContentWithTheme {
- ConnectScreen(
- state =
- ConnectUiState(
- location = null,
- selectedRelayItemTitle = null,
- tunnelState =
- TunnelState.Connected(mockTunnelEndpoint, null, emptyList()),
- inAddress = null,
- outAddress = "",
showLocation = false,
deviceName = "",
daysLeftUntilExpiry = null,
@@ -191,7 +115,7 @@ class ConnectScreenTest {
}
// Assert
- onNodeWithText("QUANTUM SECURE CONNECTION").assertExists()
+ onNodeWithText("CONNECTED").assertExists()
onNodeWithText("Switch location").assertExists()
onNodeWithText("Disconnect").assertExists()
}
@@ -209,8 +133,6 @@ class ConnectScreenTest {
location = null,
selectedRelayItemTitle = mockLocationName,
tunnelState = TunnelState.Disconnecting(ActionAfterDisconnect.Nothing),
- inAddress = null,
- outAddress = "",
showLocation = true,
deviceName = "",
daysLeftUntilExpiry = null,
@@ -221,7 +143,7 @@ class ConnectScreenTest {
}
// Assert
- onNodeWithText("UNSECURED CONNECTION").assertExists()
+ onNodeWithText("DISCONNECTED").assertExists()
onNodeWithText(mockLocationName).assertExists()
onNodeWithText("Disconnect").assertExists()
}
@@ -239,8 +161,6 @@ class ConnectScreenTest {
location = null,
selectedRelayItemTitle = mockLocationName,
tunnelState = TunnelState.Disconnected(),
- inAddress = null,
- outAddress = "",
showLocation = true,
deviceName = "",
daysLeftUntilExpiry = null,
@@ -251,9 +171,9 @@ class ConnectScreenTest {
}
// Assert
- onNodeWithText("UNSECURED CONNECTION").assertExists()
+ onNodeWithText("DISCONNECTED").assertExists()
onNodeWithText(mockLocationName).assertExists()
- onNodeWithText("Secure my connection").assertExists()
+ onNodeWithText("Connect").assertExists()
}
}
@@ -272,8 +192,6 @@ class ConnectScreenTest {
TunnelState.Error(
ErrorState(ErrorStateCause.StartTunnelError, true)
),
- inAddress = null,
- outAddress = "",
showLocation = true,
deviceName = "",
daysLeftUntilExpiry = null,
@@ -309,8 +227,6 @@ class ConnectScreenTest {
TunnelState.Error(
ErrorState(ErrorStateCause.StartTunnelError, false)
),
- inAddress = null,
- outAddress = "",
showLocation = true,
deviceName = "",
daysLeftUntilExpiry = null,
@@ -344,8 +260,6 @@ class ConnectScreenTest {
selectedRelayItemTitle = null,
tunnelState =
TunnelState.Disconnecting(ActionAfterDisconnect.Reconnect),
- inAddress = null,
- outAddress = "",
showLocation = false,
deviceName = "",
daysLeftUntilExpiry = null,
@@ -357,7 +271,7 @@ class ConnectScreenTest {
// Assert
onNodeWithTag(CIRCULAR_PROGRESS_INDICATOR).assertExists()
- onNodeWithText("CREATING SECURE CONNECTION").assertExists()
+ onNodeWithText("CONNECTING...").assertExists()
onNodeWithText("Switch location").assertExists()
onNodeWithText("Disconnect").assertExists()
onNodeWithText("BLOCKING INTERNET").assertExists()
@@ -376,8 +290,6 @@ class ConnectScreenTest {
location = null,
selectedRelayItemTitle = mockLocationName,
tunnelState = TunnelState.Disconnecting(ActionAfterDisconnect.Block),
- inAddress = null,
- outAddress = "",
showLocation = true,
deviceName = "",
daysLeftUntilExpiry = null,
@@ -388,7 +300,7 @@ class ConnectScreenTest {
}
// Assert
- onNodeWithText("SECURE CONNECTION").assertExists()
+ onNodeWithText("CONNECTED").assertExists()
onNodeWithText(mockLocationName).assertExists()
onNodeWithText("Disconnect").assertExists()
onNodeWithText("BLOCKING INTERNET").assertExists()
@@ -408,8 +320,6 @@ class ConnectScreenTest {
location = null,
selectedRelayItemTitle = mockLocationName,
tunnelState = TunnelState.Disconnected(),
- inAddress = null,
- outAddress = "",
showLocation = false,
deviceName = "",
daysLeftUntilExpiry = null,
@@ -442,8 +352,6 @@ class ConnectScreenTest {
selectedRelayItemTitle = null,
tunnelState =
TunnelState.Connected(mockTunnelEndpoint, null, emptyList()),
- inAddress = null,
- outAddress = "",
showLocation = false,
deviceName = "",
daysLeftUntilExpiry = null,
@@ -476,8 +384,6 @@ class ConnectScreenTest {
selectedRelayItemTitle = null,
tunnelState =
TunnelState.Connected(mockTunnelEndpoint, null, emptyList()),
- inAddress = null,
- outAddress = "",
showLocation = false,
deviceName = "",
daysLeftUntilExpiry = null,
@@ -508,8 +414,6 @@ class ConnectScreenTest {
location = null,
selectedRelayItemTitle = null,
tunnelState = TunnelState.Disconnected(),
- inAddress = null,
- outAddress = "",
showLocation = false,
deviceName = "",
daysLeftUntilExpiry = null,
@@ -540,8 +444,6 @@ class ConnectScreenTest {
location = null,
selectedRelayItemTitle = null,
tunnelState = TunnelState.Connecting(null, null, emptyList()),
- inAddress = null,
- outAddress = "",
showLocation = false,
deviceName = "",
daysLeftUntilExpiry = null,
@@ -561,18 +463,31 @@ class ConnectScreenTest {
}
@Test
- fun showLocationInfo() {
+ fun showConnectionDetails() {
composeExtension.use {
// Arrange
val mockLocation: GeoIpLocation = mockk(relaxed = true)
val mockTunnelEndpoint: TunnelEndpoint = mockk(relaxed = true)
val mockHostName = "Host-Name"
- val mockPort = 99
- val mockHost = "Host"
- val mockProtocol = TransportProtocol.Udp
- val mockInAddress = Triple(mockHost, mockPort, mockProtocol)
- val mockOutAddress = "HostAddressV4 / HostAddressV4"
+ val inHost = "Host"
+ val inPort = 99
+ val inProtocol = TransportProtocol.Udp
every { mockLocation.hostname } returns mockHostName
+
+ // In
+ every { mockTunnelEndpoint.obfuscation } returns null
+ every { mockTunnelEndpoint.endpoint.address.address.hostAddress } returns inHost
+ every { mockTunnelEndpoint.endpoint.address.port } returns inPort
+ every { mockTunnelEndpoint.endpoint.protocol } returns inProtocol
+
+ // Out Ipv4
+ val outIpv4 = "ipv4address"
+ every { mockLocation.ipv4?.hostAddress } returns outIpv4
+
+ // Out Ipv6
+ val outIpv6 = "ipv6address"
+ every { mockLocation.ipv6?.hostAddress } returns outIpv6
+
setContentWithTheme {
ConnectScreen(
state =
@@ -580,9 +495,11 @@ class ConnectScreenTest {
location = mockLocation,
selectedRelayItemTitle = null,
tunnelState =
- TunnelState.Connected(mockTunnelEndpoint, null, emptyList()),
- inAddress = mockInAddress,
- outAddress = mockOutAddress,
+ TunnelState.Connected(
+ mockTunnelEndpoint,
+ mockLocation,
+ emptyList(),
+ ),
showLocation = false,
deviceName = "",
daysLeftUntilExpiry = null,
@@ -593,13 +510,18 @@ class ConnectScreenTest {
}
// Act
- onNodeWithTag(LOCATION_INFO_TEST_TAG).performClick()
+ onNodeWithTag(CONNECT_CARD_HEADER_TEST_TAG).performClick()
// Assert
onNodeWithText(mockHostName).assertExists()
- onNodeWithText("WireGuard").assertExists()
- onNodeWithText("In $mockHost:$mockPort UDP").assertExists()
- onNodeWithText("Out $mockOutAddress").assertExists()
+ onNodeWithText("In").assertExists()
+ onNodeWithText("$inHost:$inPort UDP").assertExists()
+
+ onNodeWithText("Out Ipv4").assertExists()
+ onNodeWithText(outIpv4).assertExists()
+
+ onNodeWithText("Out Ipv6").assertExists()
+ onNodeWithText(outIpv6).assertExists()
}
}
@@ -615,8 +537,6 @@ class ConnectScreenTest {
location = null,
selectedRelayItemTitle = null,
tunnelState = TunnelState.Connecting(null, null, emptyList()),
- inAddress = null,
- outAddress = "",
showLocation = false,
deviceName = "",
daysLeftUntilExpiry = null,
@@ -647,8 +567,6 @@ class ConnectScreenTest {
location = null,
selectedRelayItemTitle = null,
tunnelState = TunnelState.Connecting(null, null, emptyList()),
- inAddress = null,
- outAddress = "",
showLocation = false,
deviceName = "",
daysLeftUntilExpiry = null,
@@ -678,8 +596,6 @@ class ConnectScreenTest {
location = null,
selectedRelayItemTitle = null,
tunnelState = TunnelState.Connecting(null, null, emptyList()),
- inAddress = null,
- outAddress = "",
showLocation = false,
deviceName = "",
daysLeftUntilExpiry = null,
@@ -711,8 +627,6 @@ class ConnectScreenTest {
location = null,
selectedRelayItemTitle = null,
tunnelState = TunnelState.Connecting(null, null, emptyList()),
- inAddress = null,
- outAddress = "",
showLocation = false,
deviceName = "",
daysLeftUntilExpiry = null,
diff --git a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/ConnectViewModelTest.kt b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/ConnectViewModelTest.kt
index 79f97ff466..267813d62a 100644
--- a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/ConnectViewModelTest.kt
+++ b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/ConnectViewModelTest.kt
@@ -9,7 +9,6 @@ import io.mockk.coVerify
import io.mockk.every
import io.mockk.just
import io.mockk.mockk
-import io.mockk.mockkStatic
import io.mockk.unmockkAll
import kotlin.test.assertEquals
import kotlin.test.assertIs
@@ -41,8 +40,6 @@ import net.mullvad.mullvadvpn.usecase.LastKnownLocationUseCase
import net.mullvad.mullvadvpn.usecase.OutOfTimeUseCase
import net.mullvad.mullvadvpn.usecase.PaymentUseCase
import net.mullvad.mullvadvpn.usecase.SelectedLocationTitleUseCase
-import net.mullvad.mullvadvpn.util.toInAddress
-import net.mullvad.mullvadvpn.util.toOutAddress
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
@@ -95,9 +92,6 @@ class ConnectViewModelTest {
@BeforeEach
fun setup() {
- mockkStatic(TUNNEL_ENDPOINT_EXTENSIONS)
- mockkStatic(GEO_IP_LOCATIONS_EXTENSIONS)
-
every { mockServiceConnectionManager.connectionState } returns serviceConnectionState
every { mockAccountRepository.accountData } returns accountExpiryState
@@ -164,8 +158,7 @@ class ConnectViewModelTest {
val tunnelEndpoint: TunnelEndpoint = mockk()
val location: GeoIpLocation = mockk()
val tunnelStateTestItem = TunnelState.Connected(tunnelEndpoint, location, emptyList())
- every { tunnelEndpoint.toInAddress() } returns mockk(relaxed = true)
- every { location.toOutAddress() } returns "1.1.1.1"
+ every { location.ipv4?.hostAddress } returns "1.1.1.1"
every { location.hostname } returns "hostname"
// Act, Assert
@@ -330,11 +323,4 @@ class ConnectViewModelTest {
// Assert
assertIs<ConnectViewModel.UiSideEffect.OutOfTime>(deferred.await())
}
-
- companion object {
- private const val TUNNEL_ENDPOINT_EXTENSIONS =
- "net.mullvad.mullvadvpn.util.TunnelEndpointExtensionsKt"
- private const val GEO_IP_LOCATIONS_EXTENSIONS =
- "net.mullvad.mullvadvpn.util.GeoIpLocationExtensionsKt"
- }
}
diff --git a/android/test/common/src/main/kotlin/net/mullvad/mullvadvpn/test/common/interactor/AppInteractor.kt b/android/test/common/src/main/kotlin/net/mullvad/mullvadvpn/test/common/interactor/AppInteractor.kt
index 340dad5ea0..1434de600e 100644
--- a/android/test/common/src/main/kotlin/net/mullvad/mullvadvpn/test/common/interactor/AppInteractor.kt
+++ b/android/test/common/src/main/kotlin/net/mullvad/mullvadvpn/test/common/interactor/AppInteractor.kt
@@ -71,7 +71,7 @@ class AppInteractor(
}
fun ensureLoggedIn() {
- device.findObjectWithTimeout(By.text("UNSECURED CONNECTION"), VERY_LONG_TIMEOUT)
+ device.findObjectWithTimeout(By.text("DISCONNECTED"), VERY_LONG_TIMEOUT)
}
fun ensureOutOfTime() {
@@ -82,8 +82,8 @@ class AppInteractor(
device.findObjectWithTimeout(By.text("Account"))
}
- fun extractIpAddress(): String {
- device.findObjectWithTimeout(By.res("location_info_test_tag")).click()
+ fun extractOutIpv4Address(): String {
+ device.findObjectWithTimeout(By.res("connect_card_header_test_tag")).click()
return device
.findObjectWithTimeout(
// Text exist and contains IP address
@@ -91,7 +91,6 @@ class AppInteractor(
VERY_LONG_TIMEOUT,
)
.text
- .extractIpAddress()
}
fun clickSettingsCog() {
@@ -118,8 +117,4 @@ class AppInteractor(
device.findObjectWithTimeout(By.desc("Remove")).click()
clickActionButtonByText("Yes, log out device")
}
-
- private fun String.extractIpAddress(): String {
- return split(" ")[1].split(" ")[0]
- }
}
diff --git a/android/test/e2e/src/main/kotlin/net/mullvad/mullvadvpn/test/e2e/ConnectionTest.kt b/android/test/e2e/src/main/kotlin/net/mullvad/mullvadvpn/test/e2e/ConnectionTest.kt
index 8f262f94e9..7b98c2f8f3 100644
--- a/android/test/e2e/src/main/kotlin/net/mullvad/mullvadvpn/test/e2e/ConnectionTest.kt
+++ b/android/test/e2e/src/main/kotlin/net/mullvad/mullvadvpn/test/e2e/ConnectionTest.kt
@@ -26,11 +26,11 @@ class ConnectionTest : EndToEndTest(BuildConfig.FLAVOR_infrastructure) {
app.launchAndEnsureLoggedIn(accountTestRule.validAccountNumber)
// When
- device.findObjectWithTimeout(By.text("Secure my connection")).click()
+ device.findObjectWithTimeout(By.text("Connect")).click()
device.findObjectWithTimeout(By.text("OK")).click()
// Then
- device.findObjectWithTimeout(By.text("SECURE CONNECTION"), VERY_LONG_TIMEOUT)
+ device.findObjectWithTimeout(By.text("CONNECTED"), VERY_LONG_TIMEOUT)
}
@Test
@@ -39,10 +39,10 @@ class ConnectionTest : EndToEndTest(BuildConfig.FLAVOR_infrastructure) {
app.launchAndEnsureLoggedIn(accountTestRule.validAccountNumber)
// When
- device.findObjectWithTimeout(By.text("Secure my connection")).click()
+ device.findObjectWithTimeout(By.text("Connect")).click()
device.findObjectWithTimeout(By.text("OK")).click()
- device.findObjectWithTimeout(By.text("SECURE CONNECTION"), VERY_LONG_TIMEOUT)
- val expected = ConnCheckState(true, app.extractIpAddress())
+ device.findObjectWithTimeout(By.text("CONNECTED"), VERY_LONG_TIMEOUT)
+ val expected = ConnCheckState(true, app.extractOutIpv4Address())
// Then
val result = SimpleMullvadHttpClient(targetContext).runConnectionCheck()