9
9
import XCTest
10
10
11
11
class LeakTests : LoggedInWithTimeUITestCase {
12
+ static let capturedStreamStartTimestamp : Double = 8
13
+ static let capturedStreamEndTimestamp : Double = 3
14
+
12
15
override func tearDown( ) {
13
16
FirewallClient ( ) . removeRules ( )
14
17
super. tearDown ( )
15
18
}
16
19
17
- /// Send UDP traffic to a host, connect to relay and make sure while connected to relay no traffic leaked went directly to the host
18
- func testNoLeak( ) throws {
20
+ /// Send UDP traffic to a host, connect to relay and make sure - while connected to relay -
21
+ /// that no leaked traffic went directly to the host
22
+ func testConnectionStartedBeforeTunnelShouldNotLeakOutside( ) throws {
23
+ let skipReason = """
24
+ Connections started before the packet tunnel will leak as long as
25
+ includeAllNetworks is not set to true when starting the tunnel.
26
+ """
27
+ try XCTSkipIf ( true , skipReason)
19
28
let targetIPAddress = Networking . getAlwaysReachableIPAddress ( )
20
29
startPacketCapture ( )
21
30
let trafficGenerator = TrafficGenerator ( destinationHost: targetIPAddress, port: 80 )
@@ -39,12 +48,16 @@ class LeakTests: LoggedInWithTimeUITestCase {
39
48
40
49
var capturedStreams = stopPacketCapture ( )
41
50
// For now cut the beginning and and end of the stream to trim out the part where the tunnel connection was not up
42
- capturedStreams = PacketCaptureClient . trimPackets ( streams: capturedStreams, secondsStart: 8 , secondsEnd: 3 )
51
+ capturedStreams = PacketCaptureClient . trimPackets (
52
+ streams: capturedStreams,
53
+ secondsStart: Self . capturedStreamStartTimestamp,
54
+ secondsEnd: Self . capturedStreamEndTimestamp
55
+ )
43
56
LeakCheck . assertNoLeaks ( streams: capturedStreams, rules: [ NoTrafficToHostLeakRule ( host: targetIPAddress) ] )
44
57
}
45
58
46
59
/// 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
47
- func testShouldLeak ( ) throws {
60
+ func testTrafficCapturedOutsideOfTunnelShouldLeak ( ) throws {
48
61
let targetIPAddress = Networking . getAlwaysReachableIPAddress ( )
49
62
startPacketCapture ( )
50
63
let trafficGenerator = TrafficGenerator ( destinationHost: targetIPAddress, port: 80 )
@@ -72,7 +85,6 @@ class LeakTests: LoggedInWithTimeUITestCase {
72
85
// Keep the tunnel connection for a while
73
86
RunLoop . current. run ( until: . now + 5 )
74
87
75
- app. launch ( )
76
88
TunnelControlPage ( app)
77
89
. tapDisconnectButton ( )
78
90
@@ -82,7 +94,11 @@ class LeakTests: LoggedInWithTimeUITestCase {
82
94
83
95
var capturedStreams = stopPacketCapture ( )
84
96
// For now cut the beginning and and end of the stream to trim out the part where the tunnel connection was not up
85
- capturedStreams = PacketCaptureClient . trimPackets ( streams: capturedStreams, secondsStart: 8 , secondsEnd: 3 )
97
+ capturedStreams = PacketCaptureClient . trimPackets (
98
+ streams: capturedStreams,
99
+ secondsStart: Self . capturedStreamStartTimestamp,
100
+ secondsEnd: Self . capturedStreamEndTimestamp
101
+ )
86
102
LeakCheck . assertLeaks ( streams: capturedStreams, rules: [ NoTrafficToHostLeakRule ( host: targetIPAddress) ] )
87
103
}
88
104
}
0 commit comments