Skip to content

Commit

Permalink
Fix UITests about Obufscation and add support for Shadowsocks
Browse files Browse the repository at this point in the history
  • Loading branch information
buggmagnet committed Nov 20, 2024
1 parent b62e29c commit 7f6aaac
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 39 deletions.
53 changes: 17 additions & 36 deletions ios/MullvadVPNUITests/Pages/TunnelControlPage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,67 +127,48 @@ class TunnelControlPage: Page {

/// Verify that the app attempts to connect over UDP before switching to TCP. For testing blocked UDP traffic.
@discardableResult func verifyConnectingOverTCPAfterUDPAttempts() -> Self {
let connectionAttempts = waitForConnectionAttempts(3, timeout: 15)
let connectionAttempts = waitForConnectionAttempts(4, timeout: 30)

// Should do three connection attempts but due to UI bug sometimes only two are displayed, sometimes all three
if connectionAttempts.count == 3 { // Expected retries flow
// Should do four connection attempts but due to UI bug sometimes only two are displayed, sometimes all four
if connectionAttempts.count == 4 { // Expected retries flow
for (attemptIndex, attempt) in connectionAttempts.enumerated() {
if attemptIndex == 0 || attemptIndex == 1 {
if attemptIndex == 0 || attemptIndex == 1 || attemptIndex == 2 {
XCTAssertEqual(attempt.protocolName, "UDP")
} else if attemptIndex == 2 {
} else if attemptIndex == 3 {
XCTAssertEqual(attempt.protocolName, "TCP")
} else {
XCTFail("Unexpected connection attempt")
}
}
} else if connectionAttempts.count == 2 { // Most of the times this incorrect flow is shown
} else if connectionAttempts.count == 3 { // Most of the times this incorrect flow is shown
for (attemptIndex, attempt) in connectionAttempts.enumerated() {
if attemptIndex == 0 {
if attemptIndex == 0 || attemptIndex == 1 {
XCTAssertEqual(attempt.protocolName, "UDP")
} else if attemptIndex == 1 {
} else if attemptIndex == 2 {
XCTAssertEqual(attempt.protocolName, "TCP")
} else {
XCTFail("Unexpected connection attempt")
}
}
} else {
XCTFail("Unexpected number of connection attempts")
XCTFail("Unexpected number of connection attempts, expected 3~4, got \(connectionAttempts.count)")
}

return self
}

/// Verify that connection attempts are made in the correct order
@discardableResult func verifyConnectionAttemptsOrder() -> Self {
let connectionAttempts = waitForConnectionAttempts(4, timeout: 50)
let connectionAttempts = waitForConnectionAttempts(4, timeout: 70)
XCTAssertEqual(connectionAttempts.count, 4)

if connectionAttempts.last?.protocolName == "UDP" {
// If last attempt is over UDP it means we have encountered the UI bug where only one UDP attempt is shown and then the two TCP attempts
for (attemptIndex, attempt) in connectionAttempts.enumerated() {
if attemptIndex == 0 {
XCTAssertEqual(attempt.protocolName, "UDP")
} else if attemptIndex == 1 {
XCTAssertEqual(attempt.protocolName, "TCP")
XCTAssertEqual(attempt.port, "80")
} else if attemptIndex == 2 {
XCTAssertEqual(attempt.protocolName, "TCP")
XCTAssertEqual(attempt.port, "5001")
} // Ignore the 4th attempt which is the first attempt of new attempt cycle
}
} else {
for (attemptIndex, attempt) in connectionAttempts.enumerated() {
if attemptIndex == 0 {
XCTAssertEqual(attempt.protocolName, "UDP")
} else if attemptIndex == 1 {
XCTAssertEqual(attempt.protocolName, "UDP")
} else if attemptIndex == 2 {
XCTAssertEqual(attempt.protocolName, "TCP")
XCTAssertEqual(attempt.port, "80")
} else if attemptIndex == 3 {
XCTAssertEqual(attempt.protocolName, "TCP")
XCTAssertEqual(attempt.port, "5001")
}
for (attemptIndex, attempt) in connectionAttempts.enumerated() {
if attemptIndex < 3 {
XCTAssertEqual(attempt.protocolName, "UDP")

Check failure on line 167 in ios/MullvadVPNUITests/Pages/TunnelControlPage.swift

View workflow job for this annotation

GitHub Actions / Run tests (RelayTests)

testConnectionRetryLogic, XCTAssertEqual failed: ("TCP") is not equal to ("UDP")
} else {
XCTAssertEqual(attempt.protocolName, "TCP")
let validPorts = ["80", "5001"]
XCTAssertTrue(validPorts.contains(attempt.port))
}
}

Expand Down
8 changes: 7 additions & 1 deletion ios/MullvadVPNUITests/Pages/VPNSettingsPage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,18 @@ class VPNSettingsPage: Page {
return self
}

@discardableResult func tapWireGuardObfuscationOnCell() -> Self {
@discardableResult func tapWireGuardObfuscationUdpOverTcpCell() -> Self {
app.cells[AccessibilityIdentifier.wireGuardObfuscationUdpOverTcp].tap()

return self
}

@discardableResult func tapWireGuardObfuscationShadowsocksCell() -> Self {
app.cells[AccessibilityIdentifier.wireGuardObfuscationShadowsocks].tap()

return self
}

@discardableResult func tapWireGuardObfuscationOffCell() -> Self {
app.cells[AccessibilityIdentifier.wireGuardObfuscationOff].tap()

Expand Down
43 changes: 42 additions & 1 deletion ios/MullvadVPNUITests/RelayTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,48 @@ class RelayTests: LoggedInWithTimeUITestCase {

VPNSettingsPage(app)
.tapWireGuardObfuscationExpandButton()
.tapWireGuardObfuscationOnCell()
.tapWireGuardObfuscationUdpOverTcpCell()
.tapBackButton()

SettingsPage(app)
.tapDoneButton()

TunnelControlPage(app)
.tapSecureConnectionButton()

allowAddVPNConfigurationsIfAsked()

TunnelControlPage(app)
.waitForSecureConnectionLabel()

try Networking.verifyCanAccessInternet()

TunnelControlPage(app)
.tapDisconnectButton()
}

func testWireGuardOverShadowsocksManually() throws {
addTeardownBlock {
HeaderBar(self.app)
.tapSettingsButton()

SettingsPage(self.app)
.tapVPNSettingsCell()

VPNSettingsPage(self.app)
.tapWireGuardObfuscationExpandButton()
.tapWireGuardObfuscationOffCell()
}

HeaderBar(app)
.tapSettingsButton()

SettingsPage(app)
.tapVPNSettingsCell()

VPNSettingsPage(app)
.tapWireGuardObfuscationExpandButton()
.tapWireGuardObfuscationShadowsocksCell()
.tapBackButton()

SettingsPage(app)
Expand Down
2 changes: 1 addition & 1 deletion ios/MullvadVPNUITests/SettingsMigrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class SettingsMigrationTests: BaseUITestCase {
.enterText(wireGuardPort)
.dismissKeyboard()
.tapWireGuardObfuscationExpandButton()
.tapWireGuardObfuscationOnCell()
.tapWireGuardObfuscationUdpOverTcpCell()
.tapUDPOverTCPPortExpandButton()
.tapUDPOverTCPPort80Cell()
.tapQuantumResistantTunnelExpandButton()
Expand Down

0 comments on commit 7f6aaac

Please sign in to comment.