1
1
package net.mullvad.mullvadvpn.test.e2e
2
2
3
- import androidx.test.uiautomator.By
4
3
import kotlin.time.Duration.Companion.milliseconds
5
4
import kotlinx.coroutines.delay
6
5
import kotlinx.coroutines.runBlocking
7
- import net.mullvad.mullvadvpn.compose.test.EXPAND_BUTTON_TEST_TAG
8
- import net.mullvad.mullvadvpn.compose.test.SELECT_LOCATION_BUTTON_TEST_TAG
9
- import net.mullvad.mullvadvpn.compose.test.SWITCH_TEST_TAG
10
- import net.mullvad.mullvadvpn.compose.test.TOP_BAR_SETTINGS_BUTTON
11
- import net.mullvad.mullvadvpn.test.common.constant.VERY_LONG_TIMEOUT
12
- import net.mullvad.mullvadvpn.test.common.extension.findObjectWithTimeout
13
6
import net.mullvad.mullvadvpn.test.common.misc.Attachment
7
+ import net.mullvad.mullvadvpn.test.common.page.ConnectPage
8
+ import net.mullvad.mullvadvpn.test.common.page.SelectLocationPage
9
+ import net.mullvad.mullvadvpn.test.common.page.SettingsPage
10
+ import net.mullvad.mullvadvpn.test.common.page.SystemVpnConfigurationAlert
11
+ import net.mullvad.mullvadvpn.test.common.page.TopBar
12
+ import net.mullvad.mullvadvpn.test.common.page.VpnSettingsPage
13
+ import net.mullvad.mullvadvpn.test.common.page.WireGuardCustomPortDialog
14
+ import net.mullvad.mullvadvpn.test.common.page.on
14
15
import net.mullvad.mullvadvpn.test.common.rule.ForgetAllVpnAppsInSettingsTestRule
15
16
import net.mullvad.mullvadvpn.test.e2e.annotations.HasDependencyOnLocalAPI
16
17
import net.mullvad.mullvadvpn.test.e2e.misc.AccountTestRule
@@ -34,18 +35,22 @@ class LeakTest : EndToEndTest(BuildConfig.FLAVOR_infrastructure) {
34
35
@BeforeEach
35
36
fun setupVPNSettings () {
36
37
app.launchAndEnsureLoggedIn(accountTestRule.validAccountNumber)
37
- device.findObjectWithTimeout(By .res(TOP_BAR_SETTINGS_BUTTON )).click()
38
- device.findObjectWithTimeout(By .text(" VPN settings" )).click()
39
38
40
- val localNetworkSharingCell =
41
- device.findObjectWithTimeout(By .text(" Local network sharing" )).parent
42
- val localNetworkSharingSwitch =
43
- localNetworkSharingCell.findObjectWithTimeout(By .res(SWITCH_TEST_TAG ))
39
+ on<TopBar > { clickSettings() }
44
40
45
- localNetworkSharingSwitch.click()
41
+ on< SettingsPage > { clickVpnSettings() }
46
42
47
- // Only use port 51820 to make packet capture more deterministic
48
- device.findObjectWithTimeout(By .text(" 51820" )).click()
43
+ on<VpnSettingsPage > {
44
+ clickLocalNetworkSharingSwitch()
45
+ clickWireguardCustomPort()
46
+ }
47
+
48
+ on<WireGuardCustomPortDialog > {
49
+ enterCustomPort(" 51820" )
50
+ clickSetPort()
51
+ }
52
+
53
+ on<VpnSettingsPage > {}
49
54
50
55
device.pressBack()
51
56
device.pressBack()
@@ -56,18 +61,26 @@ class LeakTest : EndToEndTest(BuildConfig.FLAVOR_infrastructure) {
56
61
fun testNegativeLeak () =
57
62
runBlocking<Unit > {
58
63
app.launch()
59
- device.findObjectWithTimeout(By .text(" DISCONNECTED" ))
60
64
61
- val targetIpAddress = BuildConfig .TRAFFIC_GENERATION_IP_ADDRESS
62
- val targetPort = 80
65
+ on<ConnectPage > {
66
+ waitForDisconnectedLabel()
67
+
68
+ clickSelectLocation()
69
+ }
63
70
64
- device.findObjectWithTimeout(By .res(SELECT_LOCATION_BUTTON_TEST_TAG )).click()
65
- clickLocationExpandButton(DEFAULT_COUNTRY )
66
- clickLocationExpandButton(DEFAULT_CITY )
67
- device.findObjectWithTimeout(By .text(DEFAULT_RELAY )).click()
68
- device.findObjectWithTimeout(By .text(" OK" )).click()
69
- device.findObjectWithTimeout(By .text(" CONNECTED" ), VERY_LONG_TIMEOUT )
71
+ on<SelectLocationPage > {
72
+ clickLocationExpandButton(DEFAULT_COUNTRY )
73
+ clickLocationExpandButton(DEFAULT_CITY )
74
+ clickLocationCell(DEFAULT_RELAY )
75
+ }
70
76
77
+ on<SystemVpnConfigurationAlert > { clickOk() }
78
+
79
+ on<ConnectPage > { waitForConnectedLabel() }
80
+
81
+ // Capture generated traffic to a specific host
82
+ val targetIpAddress = BuildConfig .TRAFFIC_GENERATION_IP_ADDRESS
83
+ val targetPort = 80
71
84
val captureResult =
72
85
PacketCapture ().capturePackets {
73
86
TrafficGenerator (targetIpAddress, targetPort).generateTraffic(10 .milliseconds) {
@@ -76,11 +89,10 @@ class LeakTest : EndToEndTest(BuildConfig.FLAVOR_infrastructure) {
76
89
}
77
90
}
78
91
79
- device.findObjectWithTimeout( By .text( " Disconnect " )).click()
92
+ on< ConnectPage > { clickDisconnect() }
80
93
81
94
val capturedStreams = captureResult.streams
82
95
val capturedPcap = captureResult.pcap
83
-
84
96
val timestamp = System .currentTimeMillis()
85
97
Attachment .saveAttachment(" capture-testNegativeLeak-$timestamp .pcap" , capturedPcap)
86
98
@@ -93,37 +105,51 @@ class LeakTest : EndToEndTest(BuildConfig.FLAVOR_infrastructure) {
93
105
fun testShouldHaveNegativeLeak () =
94
106
runBlocking<Unit > {
95
107
app.launch()
96
- device.findObjectWithTimeout(By .text(" DISCONNECTED" ))
97
108
98
- val targetIpAddress = BuildConfig .TRAFFIC_GENERATION_IP_ADDRESS
99
- val targetPort = 80
109
+ on<ConnectPage > {
110
+ waitForDisconnectedLabel()
111
+
112
+ clickSelectLocation()
113
+ }
114
+
115
+ on<SelectLocationPage > {
116
+ clickLocationExpandButton(DEFAULT_COUNTRY )
117
+ clickLocationExpandButton(DEFAULT_CITY )
118
+ clickLocationCell(DEFAULT_RELAY )
119
+ }
100
120
101
- device.findObjectWithTimeout(By .res(SELECT_LOCATION_BUTTON_TEST_TAG )).click()
102
- delay(1000 .milliseconds)
103
- clickLocationExpandButton(DEFAULT_COUNTRY )
104
- clickLocationExpandButton(DEFAULT_CITY )
105
- device.findObjectWithTimeout(By .text(DEFAULT_RELAY )).click()
106
- device.findObjectWithTimeout(By .text(" OK" )).click()
107
- device.findObjectWithTimeout(By .text(" CONNECTED" ), VERY_LONG_TIMEOUT )
121
+ on<SystemVpnConfigurationAlert > { clickOk() }
108
122
123
+ on<ConnectPage > { waitForConnectedLabel() }
124
+
125
+ // Capture generated traffic to a specific host
126
+ val targetIpAddress = BuildConfig .TRAFFIC_GENERATION_IP_ADDRESS
127
+ val targetPort = 80
109
128
val captureResult: PacketCaptureResult =
110
129
PacketCapture ().capturePackets {
111
130
TrafficGenerator (targetIpAddress, targetPort).generateTraffic(10 .milliseconds) {
112
131
delay(
113
132
3000 .milliseconds
114
133
) // Give it some time for generating traffic in tunnel
115
- device.findObjectWithTimeout(By .text(" Disconnect" )).click()
134
+
135
+ on<ConnectPage > { clickDisconnect() }
136
+
116
137
delay(
117
138
2000 .milliseconds
118
139
) // Give it some time to leak traffic outside of tunnel
119
- device.findObjectWithTimeout(By .text(" Connect" )).click()
140
+
141
+ on<ConnectPage > {
142
+ clickConnect()
143
+ waitForConnectedLabel()
144
+ }
145
+
120
146
delay(
121
147
3000 .milliseconds
122
148
) // Give it some time for generating traffic in tunnel
123
149
}
124
150
}
125
151
126
- device.findObjectWithTimeout( By .text( " Disconnect " )).click()
152
+ on< ConnectPage > { clickDisconnect() }
127
153
128
154
val capturedStreams = captureResult.streams
129
155
val capturedPcap = captureResult.pcap
@@ -133,10 +159,4 @@ class LeakTest : EndToEndTest(BuildConfig.FLAVOR_infrastructure) {
133
159
val leakRules = listOf (NoTrafficToHostRule (targetIpAddress))
134
160
LeakCheck .assertLeaks(capturedStreams, leakRules)
135
161
}
136
-
137
- private fun clickLocationExpandButton (locationName : String ) {
138
- val locationCell = device.findObjectWithTimeout(By .text(locationName)).parent.parent
139
- val expandButton = locationCell.findObjectWithTimeout(By .res(EXPAND_BUTTON_TEST_TAG ))
140
- expandButton.click()
141
- }
142
162
}
0 commit comments