Skip to content

Commit

Permalink
Remove LeakRule protocol for now, improve leak test names
Browse files Browse the repository at this point in the history
  • Loading branch information
buggmagnet committed Jan 31, 2025
1 parent 23b3c23 commit 1d35da3
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 17 deletions.
4 changes: 2 additions & 2 deletions ios/MullvadVPNUITests/Base/BaseUITestCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,11 @@ class BaseUITestCase: XCTestCase {
packetCaptureClient.stopCapture(session: packetCaptureSession)
}

let pcap = packetCaptureClient.getPCAP(session: packetCaptureSession)
let pcapFileContents = packetCaptureClient.getPCAP(session: packetCaptureSession)
let parsedCapture = packetCaptureClient.getParsedCapture(session: packetCaptureSession)
self.packetCaptureSession = nil

let pcapAttachment = XCTAttachment(data: pcap)
let pcapAttachment = XCTAttachment(data: pcapFileContents)
pcapAttachment.name = self.name + ".pcap"
pcapAttachment.lifetime = .keepAlways
self.add(pcapAttachment)
Expand Down
9 changes: 7 additions & 2 deletions ios/MullvadVPNUITests/LeakTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ class LeakTests: LoggedInWithTimeUITestCase {
}

/// Send UDP traffic to a host, connect to relay and make sure while connected to relay no traffic leaked went directly to the host
func testNoLeak() throws {
func testConnectionStartedBeforeTunnelShouldNotLeakOutside() throws {
let skipReason = """
Connections started before the packet tunnel will leak as long as
includeAllNetworks is not set to true when starting the tunnel.
"""
try XCTSkipIf(true, skipReason)
let targetIPAddress = Networking.getAlwaysReachableIPAddress()
startPacketCapture()
let trafficGenerator = TrafficGenerator(destinationHost: targetIPAddress, port: 80)
Expand Down Expand Up @@ -44,7 +49,7 @@ class LeakTests: LoggedInWithTimeUITestCase {
}

/// Send UDP traffic to a host, connect to relay and then disconnect to intentionally leak traffic and make sure that the test catches the leak
func testShouldLeak() throws {
func testTrafficCapturedOutsideOfTunnelShouldLeak() throws {
let targetIPAddress = Networking.getAlwaysReachableIPAddress()
startPacketCapture()
let trafficGenerator = TrafficGenerator(destinationHost: targetIPAddress, port: 80)
Expand Down
14 changes: 5 additions & 9 deletions ios/MullvadVPNUITests/Networking/LeakCheck.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,26 @@
import XCTest

class LeakCheck {
static func assertNoLeaks(streams: [Stream], rules: [LeakRule]) {
static func assertNoLeaks(streams: [Stream], rules: [NoTrafficToHostLeakRule]) {
XCTAssertFalse(streams.isEmpty, "No streams to leak check")
XCTAssertFalse(rules.isEmpty, "No leak rules to check")

for rule in rules where rule.isViolated(streams: streams) {
XCTFail("Leak rule violated")
XCTFail("Leaked traffic destined to \(rule.host) outside of the tunnel connection")
}
}

static func assertLeaks(streams: [Stream], rules: [LeakRule]) {
static func assertLeaks(streams: [Stream], rules: [NoTrafficToHostLeakRule]) {
XCTAssertFalse(streams.isEmpty, "No streams to leak check")
XCTAssertFalse(rules.isEmpty, "No leak rules to check")

for rule in rules where rule.isViolated(streams: streams) == false {
XCTFail("Leak rule unexpectedly not violated when asserting leak")
XCTFail("Expected to leak traffic to \(rule.host) outside of tunnel")
}
}
}

protocol LeakRule {
func isViolated(streams: [Stream]) -> Bool
}

class NoTrafficToHostLeakRule: LeakRule {
class NoTrafficToHostLeakRule {
let host: String

init(host: String) {
Expand Down
4 changes: 0 additions & 4 deletions ios/MullvadVPNUITests/Networking/TestRouterAPIClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ class TestRouterAPIClient {
)!
// swiftlint:enable force_cast

static func getIPAddress() throws -> String {
return ""
}

/// Gets the IP address of the device under test
public func getDeviceIPAddress() throws -> String {
let deviceIPURL = TestRouterAPIClient.baseURL.appendingPathComponent("own-ip")
Expand Down

0 comments on commit 1d35da3

Please sign in to comment.