Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add end to end test for custom shadowsocks port selection #7714

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 77 additions & 13 deletions ios/MullvadVPNUITests/RelayTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -183,24 +183,63 @@ class RelayTests: LoggedInWithTimeUITestCase {

try Networking.verifyCanAccessInternet()

let targetIPAddress = Networking.getAlwaysReachableIPAddress()
let trafficGenerator = TrafficGenerator(destinationHost: targetIPAddress, port: 80)
trafficGenerator.startGeneratingUDPTraffic(interval: 0.1)
try generateTraffic(to: connectedToIPAddress, on: 80, assertProtocol: .TCP)
}

RunLoop.current.run(until: .now + 1)
trafficGenerator.stopGeneratingUDPTraffic()
func testWireGuardOverShadowsocksCustomPort() 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()
.tapShadowsocksPortSelectorButton()

ShadowsocksObfuscationSettingsPage(app)
.tapCustomCell()
.typeTextIntoCustomField("51900")
.tapBackButton()

VPNSettingsPage(app)
.tapBackButton()

SettingsPage(app)
.tapDoneButton()

// The packet capture has to start before the tunnel is up,
// otherwise the device cannot reach the in-house router anymore
startPacketCapture()

TunnelControlPage(app)
.tapDisconnectButton()
let capturedStreams = stopPacketCapture()
.tapConnectButton()

// The capture will contain several streams where `other_addr` contains the IP the device connected to
// One stream will be for the source port, the other for the destination port
let streamFromPeeerToRelay = try XCTUnwrap(
capturedStreams.filter { $0.destinationAddress == connectedToIPAddress && $0.destinationPort == 80 }.first
)
allowAddVPNConfigurationsIfAsked()

TunnelControlPage(app)
.waitForConnectedLabel()

let connectedToIPAddress = TunnelControlPage(app)
.tapRelayStatusExpandCollapseButton()
.getInIPv4AddressLabel()

try Networking.verifyCanAccessInternet()

XCTAssertTrue(streamFromPeeerToRelay.transportProtocol == .TCP)
try generateTraffic(to: connectedToIPAddress, on: 51900, assertProtocol: .UDP)
}

func testWireGuardOverTCPManually() throws {
Expand Down Expand Up @@ -508,4 +547,29 @@ extension RelayTests {

return RelayInfo(name: relayName, ipAddress: relayIPAddress)
}

private func generateTraffic(
to connectedToIPAddress: String,
on port: Int,
assertProtocol transportProtocol: NetworkTransportProtocol
) throws {
let targetIPAddress = Networking.getAlwaysReachableIPAddress()
let trafficGenerator = TrafficGenerator(destinationHost: targetIPAddress, port: 80)
trafficGenerator.startGeneratingUDPTraffic(interval: 0.1)

RunLoop.current.run(until: .now + 1)
trafficGenerator.stopGeneratingUDPTraffic()

TunnelControlPage(app)
.tapDisconnectButton()
let capturedStreams = stopPacketCapture()

// The capture will contain several streams where `other_addr` contains the IP the device connected to
// One stream will be for the source port, the other for the destination port
let streamFromPeeerToRelay = try XCTUnwrap(
capturedStreams.filter { $0.destinationAddress == connectedToIPAddress && $0.destinationPort == port }.first
)

XCTAssertTrue(streamFromPeeerToRelay.transportProtocol == transportProtocol)
}
} // swiftlint:disable:this file_length
Loading