Skip to content

Commit

Permalink
Not connecting to specific relay but instead any Gothenburg relay
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasberglund committed May 13, 2024
1 parent c054f5b commit d267afc
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 13 deletions.
13 changes: 12 additions & 1 deletion ios/MullvadVPNUITests/Pages/TunnelControlPage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
}
34 changes: 22 additions & 12 deletions ios/MullvadVPNUITests/RelayTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
import Foundation
import XCTest

fileprivate struct RelayInfo {
var name: String
var ipAddress: String
}

class RelayTests: LoggedInWithTimeUITestCase {
var removeFirewallRulesInTearDown = false

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand All @@ -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 {
Expand Down

0 comments on commit d267afc

Please sign in to comment.