Skip to content

Commit 84d25b6

Browse files
committed
Stop relying on interface name to get local IP address in UITests
1 parent 2ffaac2 commit 84d25b6

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

ios/MullvadVPNUITests/Networking/Networking.swift

+13-13
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,19 @@ class Networking {
4444
interfaceAddress.sa_family == UInt8(AF_INET) {
4545
// Check if interface is en0 which is the WiFi connection on the iPhone
4646
let name = String(cString: interfacePointer.pointee.ifa_name)
47-
if name == "en0" {
4847
// Convert interface address to a human readable string:
49-
var hostname = [CChar](repeating: 0, count: Int(NI_MAXHOST))
50-
if getnameinfo(
51-
interfacePointer.pointee.ifa_addr,
52-
socklen_t(interfaceAddress.sa_len),
53-
&hostname,
54-
socklen_t(hostname.count),
55-
nil,
56-
socklen_t(0),
57-
NI_NUMERICHOST
58-
) == 0 {
59-
ipAddress = String(cString: hostname)
48+
var hostname = [CChar](repeating: 0, count: Int(NI_MAXHOST))
49+
if getnameinfo(
50+
interfacePointer.pointee.ifa_addr,
51+
socklen_t(interfaceAddress.sa_len),
52+
&hostname,
53+
socklen_t(hostname.count),
54+
nil,
55+
socklen_t(0),
56+
NI_NUMERICHOST
57+
) == 0 {
58+
ipAddress = String(cString: hostname)
59+
if ipAddress.starts(with: "192.168") {
6060
return ipAddress
6161
}
6262
}
@@ -65,7 +65,7 @@ class Networking {
6565

6666
freeifaddrs(interfaceList)
6767

68-
throw NetworkingError.internalError(reason: "Failed to determine device's IP address")
68+
throw NetworkingError.internalError(reason: "No local IP found")
6969
}
7070

7171
/// Get configured ad serving domain

ios/MullvadVPNUITests/Pages/TunnelControlPage.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ class TunnelControlPage: Page {
159159

160160
/// Verify that connection attempts are made in the correct order
161161
@discardableResult func verifyConnectionAttemptsOrder() -> Self {
162-
var connectionAttempts = waitForConnectionAttempts(4, timeout: 70)
162+
var connectionAttempts = waitForConnectionAttempts(4, timeout: 80)
163163
var totalAttemptsOffset = 0
164164
XCTAssertEqual(connectionAttempts.count, 4)
165165

@@ -169,7 +169,7 @@ class TunnelControlPage: Page {
169169
/// of connection attempts.
170170
if connectionAttempts.last?.protocolName == "UDP" {
171171
connectionAttempts.removeLast()
172-
totalAttemptsOffset = -1
172+
totalAttemptsOffset = 1
173173
}
174174
for (attemptIndex, attempt) in connectionAttempts.enumerated() {
175175
if attemptIndex < 3 - totalAttemptsOffset {

0 commit comments

Comments
 (0)