Skip to content

Commit

Permalink
Extracting in IP address
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasberglund committed Nov 22, 2024
1 parent 19d443b commit b140ab8
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import androidx.constraintlayout.compose.ConstraintLayout
import androidx.constraintlayout.compose.Dimension
import net.mullvad.mullvadvpn.R
import net.mullvad.mullvadvpn.compose.screen.ConnectionDetails
import net.mullvad.mullvadvpn.compose.test.LOCATION_INFO_CONNECTION_IN_TEST_TAG
import net.mullvad.mullvadvpn.compose.test.LOCATION_INFO_CONNECTION_OUT_TEST_TAG
import net.mullvad.mullvadvpn.constant.SPACE_CHAR
import net.mullvad.mullvadvpn.lib.model.TransportProtocol
Expand Down Expand Up @@ -88,7 +89,7 @@ fun ConnectionDetails(
maxLines = 1,
overflow = TextOverflow.Ellipsis,
modifier =
Modifier.constrainAs(inAddr) {
Modifier.testTag(LOCATION_INFO_CONNECTION_IN_TEST_TAG).constrainAs(inAddr) {
start.linkTo(headerBarrier)
end.linkTo(parent.end)
top.linkTo(parent.top)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class AppInteractor(
}

fun extractInIpv4Address(): String {
device.findObjectWithTimeout(By.res("location_info_test_tag")).click()
device.findObjectWithTimeout(By.res("connect_card_header_test_tag")).click()
val inString =
device
.findObjectWithTimeout(
Expand All @@ -105,7 +105,7 @@ class AppInteractor(
)
.text

val extractedIpAddress = inString.split(" ")[1].split(":")[0]
val extractedIpAddress = inString.split(" ")[0].split(":")[0]
return extractedIpAddress
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package net.mullvad.mullvadvpn.test.e2e

import androidx.test.uiautomator.By
import androidx.test.uiautomator.Direction
import kotlin.time.Duration.Companion.milliseconds
import kotlinx.coroutines.delay
import kotlinx.coroutines.runBlocking
import net.mullvad.mullvadvpn.BuildConfig
import net.mullvad.mullvadvpn.compose.test.EXPAND_BUTTON_TEST_TAG
Expand Down Expand Up @@ -68,7 +70,7 @@ class ConnectionTest : EndToEndTest(BuildConfig.FLAVOR_infrastructure) {
device.findObjectWithTimeout(By.text(DEFAULT_RELAY)).click()
device.findObjectWithTimeout(By.text("OK")).click()
device.findObjectWithTimeout(By.text("CONNECTED"), VERY_LONG_TIMEOUT)
val relayIpAddress = app.extractOutIpv4Address()
val relayIpAddress = app.extractInIpv4Address()
device.findObjectWithTimeout(By.text("Disconnect")).click()

// Disable obfuscation
Expand All @@ -78,9 +80,8 @@ class ConnectionTest : EndToEndTest(BuildConfig.FLAVOR_infrastructure) {
device.findObjectWithTimeout(By.text("Local network sharing")).parent
val scrollView = device.findObjectWithTimeout(By.res(SETTINGS_SCROLL_VIEW_TEST_TAG))
scrollView.swipe(Direction.UP, 0.1f)
val wireGuardObfuscationOffCell = device.findObjectWithTimeout(By.res(
WIREGUARD_OBFUSCATION_OFF_CELL_TEST_TAG))
wireGuardObfuscationOffCell.click()
device.findObjectWithTimeout(By.res(
WIREGUARD_OBFUSCATION_OFF_CELL_TEST_TAG)).click()
device.pressBack()
device.pressBack()

Expand All @@ -91,8 +92,8 @@ class ConnectionTest : EndToEndTest(BuildConfig.FLAVOR_infrastructure) {

// Ensure it is not possible to connect to relay
device.findObjectWithTimeout(By.text("Connect")).click()
device.findObjectWithTimeout(By.text("OK")).click()
// TODO: assert failed connection attempt
delay(5000.milliseconds)
device.findObjectWithTimeout(By.text(("CONNECTING...")))
device.findObjectWithTimeout(By.text("Disconnect")).click()

// Enable UDP-over-TCP
Expand All @@ -108,6 +109,7 @@ class ConnectionTest : EndToEndTest(BuildConfig.FLAVOR_infrastructure) {
device.findObjectWithTimeout(By.text("Connect")).click()
device.findObjectWithTimeout(By.text("OK")).click()
device.findObjectWithTimeout(By.text("CONNECTED"), VERY_LONG_TIMEOUT)
device.findObjectWithTimeout(By.text("Disconnect")).click()
}

private fun clickLocationExpandButton(locationName: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class FirewallClient(private val httpClient: HttpClient = defaultHttpClient()) {

suspend fun createRule(rule: FirewallRule) {
Logger.v("Sending create rule request with body: ${Json.encodeToString(FirewallRule.serializer(), rule)}")
Logger.v("Requesting firewall API to block ${rule.protocols} traffic from ${rule.from} to ${rule.to}")
httpClient.post("rule") {
contentType(ContentType.Application.Json)
setBody(Json.encodeToString(FirewallRule.serializer(), rule))
Expand All @@ -61,7 +62,7 @@ class FirewallClient(private val httpClient: HttpClient = defaultHttpClient()) {
val src: String,
val dst: String,
val protocols: List<NetworkingProtocol>,
@EncodeDefault val label: String = FirewallClient.sessionIdentifierFromDeviceIdentifier()) {
@EncodeDefault val label: String = "urn:uuid:" + FirewallClient.sessionIdentifierFromDeviceIdentifier()) {
companion object {
fun blockUDPTrafficRule(to: String): FirewallRule {
val testDeviceIpAddress = Networking.getDeviceIpv4Address()
Expand All @@ -85,7 +86,7 @@ class FirewallClient(private val httpClient: HttpClient = defaultHttpClient()) {
Settings.Secure.ANDROID_ID
)

return "urn:uuid:" + UUID.nameUUIDFromBytes(deviceIdentifier.toByteArray()).toString()
return UUID.nameUUIDFromBytes(deviceIdentifier.toByteArray()).toString()
}
}
}
Expand Down

0 comments on commit b140ab8

Please sign in to comment.