Skip to content

Commit

Permalink
Merge branch 'implement-firewall-api-client-droid-1552'
Browse files Browse the repository at this point in the history
  • Loading branch information
Rawa committed Dec 3, 2024
2 parents 7b0f970 + a83948c commit a0312ca
Show file tree
Hide file tree
Showing 26 changed files with 352 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import net.mullvad.mullvadvpn.compose.state.VpnSettingsUiState
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_VPN_SETTINGS_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
Expand Down Expand Up @@ -47,7 +47,7 @@ class VpnSettingsScreenTest {
// Arrange
setContentWithTheme { VpnSettingsScreen(state = VpnSettingsUiState.createDefault()) }

onNodeWithTag(LAZY_LIST_TEST_TAG)
onNodeWithTag(LAZY_LIST_VPN_SETTINGS_TEST_TAG)
.performScrollToNode(hasTestTag(LAZY_LIST_LAST_ITEM_TEST_TAG))

// Assert
Expand All @@ -70,7 +70,7 @@ class VpnSettingsScreenTest {
)
}

onNodeWithTag(LAZY_LIST_TEST_TAG)
onNodeWithTag(LAZY_LIST_VPN_SETTINGS_TEST_TAG)
.performScrollToNode(hasTestTag(LAZY_LIST_LAST_ITEM_TEST_TAG))

// Assert
Expand Down Expand Up @@ -117,7 +117,7 @@ class VpnSettingsScreenTest {
)
)
}
onNodeWithTag(LAZY_LIST_TEST_TAG)
onNodeWithTag(LAZY_LIST_VPN_SETTINGS_TEST_TAG)
.performScrollToNode(hasTestTag(LAZY_LIST_LAST_ITEM_TEST_TAG))
// Assert
onNodeWithText(DUMMY_DNS_ADDRESS).assertDoesNotExist()
Expand Down Expand Up @@ -213,7 +213,7 @@ class VpnSettingsScreenTest {
)
)
}
onNodeWithTag(LAZY_LIST_TEST_TAG)
onNodeWithTag(LAZY_LIST_VPN_SETTINGS_TEST_TAG)
.performScrollToNode(hasTestTag(LAZY_LIST_QUANTUM_ITEM_OFF_TEST_TAG))

// Assert
Expand All @@ -236,7 +236,7 @@ class VpnSettingsScreenTest {
onSelectQuantumResistanceSetting = mockSelectQuantumResistantSettingListener,
)
}
onNodeWithTag(LAZY_LIST_TEST_TAG)
onNodeWithTag(LAZY_LIST_VPN_SETTINGS_TEST_TAG)
.performScrollToNode(hasTestTag(LAZY_LIST_QUANTUM_ITEM_OFF_TEST_TAG))

// Assert
Expand All @@ -261,7 +261,7 @@ class VpnSettingsScreenTest {
}

// Act
onNodeWithTag(LAZY_LIST_TEST_TAG)
onNodeWithTag(LAZY_LIST_VPN_SETTINGS_TEST_TAG)
.performScrollToNode(
hasTestTag(String.format(LAZY_LIST_WIREGUARD_PORT_ITEM_X_TEST_TAG, 53))
)
Expand Down Expand Up @@ -291,7 +291,7 @@ class VpnSettingsScreenTest {
}

// Act
onNodeWithTag(LAZY_LIST_TEST_TAG)
onNodeWithTag(LAZY_LIST_VPN_SETTINGS_TEST_TAG)
.performScrollToNode(
hasTestTag(String.format(LAZY_LIST_WIREGUARD_PORT_ITEM_X_TEST_TAG, 53))
)
Expand All @@ -318,7 +318,7 @@ class VpnSettingsScreenTest {
}

// Act
onNodeWithTag(LAZY_LIST_TEST_TAG)
onNodeWithTag(LAZY_LIST_VPN_SETTINGS_TEST_TAG)
.performScrollToNode(hasTestTag(LAZY_LIST_WIREGUARD_CUSTOM_PORT_TEXT_TEST_TAG))

// Assert
Expand All @@ -342,7 +342,7 @@ class VpnSettingsScreenTest {
}

// Act
onNodeWithTag(LAZY_LIST_TEST_TAG)
onNodeWithTag(LAZY_LIST_VPN_SETTINGS_TEST_TAG)
.performScrollToNode(hasTestTag(LAZY_LIST_WIREGUARD_CUSTOM_PORT_TEXT_TEST_TAG))
onNodeWithTag(testTag = LAZY_LIST_WIREGUARD_CUSTOM_PORT_TEXT_TEST_TAG).performClick()

Expand All @@ -364,7 +364,7 @@ class VpnSettingsScreenTest {
)
}

onNodeWithTag(LAZY_LIST_TEST_TAG)
onNodeWithTag(LAZY_LIST_VPN_SETTINGS_TEST_TAG)
.performScrollToNode(hasTestTag(LAZY_LIST_LAST_ITEM_TEST_TAG))

// Act
Expand Down Expand Up @@ -407,7 +407,7 @@ class VpnSettingsScreenTest {
}

// Act
onNodeWithTag(LAZY_LIST_TEST_TAG)
onNodeWithTag(LAZY_LIST_VPN_SETTINGS_TEST_TAG)
.performScrollToNode(hasTestTag(LAZY_LIST_WIREGUARD_OBFUSCATION_TITLE_TEST_TAG))
onNodeWithText("WireGuard obfuscation").performClick()

Expand All @@ -430,7 +430,7 @@ class VpnSettingsScreenTest {

// Act

onNodeWithTag(LAZY_LIST_TEST_TAG)
onNodeWithTag(LAZY_LIST_VPN_SETTINGS_TEST_TAG)
.performScrollToNode(hasTestTag(LAZY_LIST_QUANTUM_ITEM_ON_TEST_TAG))
onNodeWithText("Quantum-resistant tunnel").performClick()

Expand Down Expand Up @@ -469,7 +469,7 @@ class VpnSettingsScreenTest {
)
}

onNodeWithTag(LAZY_LIST_TEST_TAG)
onNodeWithTag(LAZY_LIST_VPN_SETTINGS_TEST_TAG)
.performScrollToNode(hasTestTag(LAZY_LIST_WIREGUARD_CUSTOM_PORT_NUMBER_TEST_TAG))
onNodeWithText("Custom").performClick()

Expand All @@ -490,7 +490,7 @@ class VpnSettingsScreenTest {
}

// Act
onNodeWithTag(LAZY_LIST_TEST_TAG)
onNodeWithTag(LAZY_LIST_VPN_SETTINGS_TEST_TAG)
.performScrollToNode(hasTestTag(LAZY_LIST_WIREGUARD_CUSTOM_PORT_TEXT_TEST_TAG))
onNodeWithTag(LAZY_LIST_WIREGUARD_CUSTOM_PORT_TEXT_TEST_TAG).performClick()

Expand All @@ -514,7 +514,7 @@ class VpnSettingsScreenTest {
}

// Act
onNodeWithTag(LAZY_LIST_TEST_TAG)
onNodeWithTag(LAZY_LIST_VPN_SETTINGS_TEST_TAG)
.performScrollToNode(hasTestTag(LAZY_LIST_WIREGUARD_CUSTOM_PORT_TEXT_TEST_TAG))
onNodeWithTag(testTag = LAZY_LIST_WIREGUARD_CUSTOM_PORT_NUMBER_TEST_TAG).performClick()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.tooling.preview.PreviewParameter
Expand Down Expand Up @@ -57,12 +58,14 @@ fun ObfuscationModeCell(
isSelected: Boolean,
onSelected: (ObfuscationMode) -> Unit,
onNavigate: () -> Unit = {},
testTag: String? = null,
) {
Row(
modifier =
Modifier.height(IntrinsicSize.Min)
.fillMaxWidth()
.background(MaterialTheme.colorScheme.surfaceContainerLow)
.let { if (testTag != null) it.testTag(testTag) else it }
) {
TwoRowCell(
modifier = Modifier.weight(1f),
Expand Down
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 @@ -82,11 +82,13 @@ import net.mullvad.mullvadvpn.compose.state.VpnSettingsUiState
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_VPN_SETTINGS_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.compose.test.WIREGUARD_OBFUSCATION_OFF_CELL
import net.mullvad.mullvadvpn.compose.test.WIREGUARD_OBFUSCATION_UDP_OVER_TCP_CELL
import net.mullvad.mullvadvpn.compose.transitions.SlideInFromRightTransition
import net.mullvad.mullvadvpn.compose.util.CollectSideEffectWithLifecycle
import net.mullvad.mullvadvpn.compose.util.OnNavResultValue
Expand Down Expand Up @@ -297,7 +299,7 @@ fun VpnSettingsScreen(
snackbarHostState = snackbarHostState,
) { modifier, lazyListState ->
LazyColumn(
modifier = modifier.testTag(LAZY_LIST_TEST_TAG).animateContentSize(),
modifier = modifier.testTag(LAZY_LIST_VPN_SETTINGS_TEST_TAG).animateContentSize(),
state = lazyListState,
) {
if (state.systemVpnSettingsAvailable) {
Expand Down Expand Up @@ -568,13 +570,15 @@ fun VpnSettingsScreen(
port = state.selectedUdp2TcpObfuscationPort,
onSelected = onSelectObfuscationMode,
onNavigate = navigateToUdp2TcpSettings,
testTag = WIREGUARD_OBFUSCATION_UDP_OVER_TCP_CELL,
)
}
itemWithDivider {
SelectableCell(
title = stringResource(id = R.string.off),
isSelected = state.obfuscationMode == ObfuscationMode.Off,
onCellClicked = { onSelectObfuscationMode(ObfuscationMode.Off) },
testTag = WIREGUARD_OBFUSCATION_OFF_CELL,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const val TOP_BAR_ACCOUNT_BUTTON = "top_bar_account_button"
const val TOP_BAR_SETTINGS_BUTTON = "top_bar_settings_button"

// VpnSettingsScreen
const val LAZY_LIST_VPN_SETTINGS_TEST_TAG = "lazy_list_vpn_settings_test_tag"
const val LAZY_LIST_TEST_TAG = "lazy_list_test_tag"
const val LAZY_LIST_LAST_ITEM_TEST_TAG = "lazy_list_last_item_test_tag"
const val LAZY_LIST_QUANTUM_ITEM_OFF_TEST_TAG = "lazy_list_quantum_item_off_test_tag"
Expand All @@ -18,6 +19,9 @@ const val CUSTOM_PORT_DIALOG_INPUT_TEST_TAG = "custom_port_dialog_input_test_tag
const val LAZY_LIST_WIREGUARD_OBFUSCATION_TITLE_TEST_TAG =
"lazy_list_wireguard_obfuscation_title_test_tag"
const val SWITCH_TEST_TAG = "switch_test_tag"
const val WIREGUARD_OBFUSCATION_OFF_CELL = "wireguard_obfuscation_off_cell_test_tag"
const val WIREGUARD_OBFUSCATION_UDP_OVER_TCP_CELL =
"wireguard_obfuscation_udp_over_tcp_cell_test_tag"

// SelectLocationScreen, ConnectScreen, CustomListLocationsScreen
const val CIRCULAR_PROGRESS_INDICATOR = "circular_progress_indicator"
Expand Down
1 change: 1 addition & 0 deletions android/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ android.nonTransitiveRClass=false
android.useAndroidX=true
kotlin.code.style=official
org.gradle.jvmargs=-Xmx8192M -Dkotlin.daemon.jvm.options\="-Xmx8192M"
test.e2e.enableAccessToLocalApiTests=false
4 changes: 3 additions & 1 deletion android/scripts/run-instrumented-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ if [[ -z $REPORT_DIR || ! -d $REPORT_DIR ]]; then
exit 1
fi

GRADLE_ENVIRONMENT_VARIABLES="TEST_E2E_ENABLEACCESSTOLOCALAPITESTS=$ENABLE_ACCESS_TO_LOCAL_API_TESTS"

INSTRUMENTATION_LOG_FILE_PATH="$REPORT_DIR/instrumentation-log.txt"
LOGCAT_FILE_PATH="$REPORT_DIR/logcat.txt"
LOCAL_SCREENSHOT_PATH="$REPORT_DIR/screenshots"
Expand Down Expand Up @@ -222,7 +224,7 @@ else
-e runnerBuilder de.mannodermaus.junit5.AndroidJUnit5Builder \
$TEST_PACKAGE_NAME/androidx.test.runner.AndroidJUnitRunner"
fi
adb shell "$INSTRUMENTATION_COMMAND" | tee "$INSTRUMENTATION_LOG_FILE_PATH"
adb shell "$GRADLE_ENVIRONMENT_VARIABLES $INSTRUMENTATION_COMMAND" | tee "$INSTRUMENTATION_LOG_FILE_PATH"
echo ""

echo "### Ensure that packages are uninstalled ###"
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 @@ -45,6 +45,8 @@ class ForgetAllVpnAppsInSettingsTestRule : BeforeTestExecutionCallback {
device
.findObjectWithTimeout(By.text(DELETE_VPN_CONFIRM_BUTTON_TEXT_REGEXP))
.click()
} else if (device.hasObjectWithTimeout(By.text(FORGET_VPN_BUTTON_TEXT))) {
device.findObjectWithTimeout(By.text(FORGET_VPN_BUTTON_TEXT)).click()
} else {
fail("Unable to find forget or delete button")
}
Expand All @@ -60,6 +62,7 @@ class ForgetAllVpnAppsInSettingsTestRule : BeforeTestExecutionCallback {
private val HARDCODED_VPN_PROFILE_NAMES = listOf("VPN by Google")

private const val FORGET_VPN_VPN_BUTTON_TEXT = "Forget VPN"
private const val FORGET_VPN_BUTTON_TEXT = "Forget" // Legacy VPN
private const val DELETE_VPN_PROFILE_TEXT = "Delete VPN profile"
private const val FORGET_VPN_VPN_CONFIRM_BUTTON_TEXT = "Forget"
// Samsung S22 shows "Delete"
Expand Down
6 changes: 4 additions & 2 deletions android/test/e2e/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ android {
load(project.file("e2e.properties").inputStream())
addRequiredPropertyAsBuildConfigField("API_VERSION")
addRequiredPropertyAsBuildConfigField("TRAFFIC_GENERATION_IP_ADDRESS")
addRequiredPropertyAsBuildConfigField("PACKET_CAPTURE_API_HOST")
addRequiredPropertyAsBuildConfigField("TEST_ROUTER_API_HOST")
}

fun MutableMap<String, String>.addOptionalPropertyAsArgument(name: String) {
Expand All @@ -52,10 +52,12 @@ android {
testInstrumentationRunnerArguments +=
mutableMapOf<String, String>().apply {
put("clearPackageData", "true")
addOptionalPropertyAsArgument("enable_access_to_local_api_tests")
addOptionalPropertyAsArgument("enable_highly_rate_limited_tests")
addOptionalPropertyAsArgument("valid_test_account_number")
addOptionalPropertyAsArgument("invalid_test_account_number")
project.findProperty("test.e2e.enableAccessToLocalApiTests")?.let {
put("enable_access_to_local_api_tests", it.toString())
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion android/test/e2e/e2e.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
API_VERSION=v1
TRAFFIC_GENERATION_IP_ADDRESS=45.83.223.209
PACKET_CAPTURE_API_HOST=192.168.105.1
TEST_ROUTER_API_HOST=192.168.105.1
Loading

0 comments on commit a0312ca

Please sign in to comment.