From d267afc2dd5709fd3eda042f8b4f007bc82a02f5 Mon Sep 17 00:00:00 2001 From: Niklas Berglund Date: Mon, 13 May 2024 18:21:56 +0200 Subject: [PATCH] Not connecting to specific relay but instead any Gothenburg relay --- .../Pages/TunnelControlPage.swift | 13 ++++++- ios/MullvadVPNUITests/RelayTests.swift | 34 ++++++++++++------- 2 files changed, 34 insertions(+), 13 deletions(-) diff --git a/ios/MullvadVPNUITests/Pages/TunnelControlPage.swift b/ios/MullvadVPNUITests/Pages/TunnelControlPage.swift index 48efc42624e7..5b2a35c71890 100644 --- a/ios/MullvadVPNUITests/Pages/TunnelControlPage.swift +++ b/ios/MullvadVPNUITests/Pages/TunnelControlPage.swift @@ -97,7 +97,7 @@ class TunnelControlPage: Page { @discardableResult func waitForSecureConnectionLabel() -> Self { let labelFound = app.staticTexts[.connectionStatusConnectedLabel] .waitForExistence(timeout: BaseUITestCase.veryLongTimeout) - XCTAssertTrue(labelFound, "Found secure connection label") + XCTAssertTrue(labelFound, "Secure connection label presented") return self } @@ -195,4 +195,15 @@ class TunnelControlPage: Page { return String() } } + + func getCurrentRelayName() -> String { + let relayExpandButton = app.buttons[.relayStatusCollapseButton] + + guard let relayName = relayExpandButton.value as? String else { + XCTFail("Failed to read relay name from tunnel control page") + return String() + } + + return relayName + } } diff --git a/ios/MullvadVPNUITests/RelayTests.swift b/ios/MullvadVPNUITests/RelayTests.swift index fdb74479ad64..d0550f3c718c 100644 --- a/ios/MullvadVPNUITests/RelayTests.swift +++ b/ios/MullvadVPNUITests/RelayTests.swift @@ -9,6 +9,11 @@ import Foundation import XCTest +fileprivate struct RelayInfo { + var name: String + var ipAddress: String +} + class RelayTests: LoggedInWithTimeUITestCase { var removeFirewallRulesInTearDown = false @@ -89,15 +94,19 @@ class RelayTests: LoggedInWithTimeUITestCase { removeFirewallRulesInTearDown = true // First get relay IP address - let relayIPAddress = getGot001WireGuardRelayIPAddress() + let relayInfo = getGothenburgRelayInfo() // Run actual test try FirewallAPIClient().createRule( - FirewallRule.makeBlockAllTrafficRule(toIPAddress: relayIPAddress) + FirewallRule.makeBlockAllTrafficRule(toIPAddress: relayInfo.ipAddress) ) TunnelControlPage(app) - .tapSecureConnectionButton() + .tapSelectLocationButton() + + SelectLocationPage(app) + .tapLocationCellExpandButton(withName: "Gothenburg") + .tapLocationCell(withName: relayInfo.name) // Should be two UDP connection attempts but sometimes only one is shown in the UI TunnelControlPage(app) @@ -152,11 +161,11 @@ class RelayTests: LoggedInWithTimeUITestCase { removeFirewallRulesInTearDown = true // First get relay IP address - let relayIPAddress = getGot001WireGuardRelayIPAddress() + let relayInfo = getGothenburgRelayInfo() // Run actual test try FirewallAPIClient().createRule( - FirewallRule.makeBlockUDPTrafficRule(toIPAddress: relayIPAddress) + FirewallRule.makeBlockUDPTrafficRule(toIPAddress: relayInfo.ipAddress) ) HeaderBar(app) @@ -211,22 +220,21 @@ class RelayTests: LoggedInWithTimeUITestCase { .tapDisconnectButton() } - /// Get got001 WireGuard relay IP address by connecting to it and checking which IP address the app connects to. Assumes user is logged on and at tunnel control page. - private func getGot001WireGuardRelayIPAddress() -> String { + /// Get Gothenburg relay IP address and name by connecting to any Gothenburg relay and checking relay and IP address the app connects to. Assumes user is logged on and at tunnel control page. + private func getGothenburgRelayInfo() -> RelayInfo { let wireGuardGot001RelayName = "se-got-wg-001" TunnelControlPage(app) .tapSelectLocationButton() if SelectLocationPage(app).locationCellIsExpanded("Sweden") { - // Already expanded - just make sure correct relay is selected + // Already expanded - just make sure the correct city cell is selected SelectLocationPage(app) - .tapLocationCell(withName: wireGuardGot001RelayName) + .tapLocationCell(withName: "Gothenburg") } else { SelectLocationPage(app) .tapLocationCellExpandButton(withName: "Sweden") - .tapLocationCellExpandButton(withName: "Gothenburg") - .tapLocationCell(withName: wireGuardGot001RelayName) + .tapLocationCell(withName: "Gothenburg") } allowAddVPNConfigurationsIfAsked() @@ -236,10 +244,12 @@ class RelayTests: LoggedInWithTimeUITestCase { .tapRelayStatusExpandCollapseButton() .getInIPAddressFromConnectionStatus() + let relayName = TunnelControlPage(app).getCurrentRelayName() + TunnelControlPage(app) .tapDisconnectButton() - return relayIPAddress + return RelayInfo(name: relayName, ipAddress: relayIPAddress) } func testCustomDNS() throws {