Skip to content

Commit

Permalink
Stop relying on interface name to get local IP address in UITests
Browse files Browse the repository at this point in the history
  • Loading branch information
buggmagnet committed Nov 21, 2024
1 parent 5664a1e commit 50283f0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
28 changes: 14 additions & 14 deletions ios/MullvadVPNUITests/Networking/Networking.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,19 @@ class Networking {
interfaceAddress.sa_family == UInt8(AF_INET) {
// Check if interface is en0 which is the WiFi connection on the iPhone
let name = String(cString: interfacePointer.pointee.ifa_name)
if name == "en0" {
// Convert interface address to a human readable string:
var hostname = [CChar](repeating: 0, count: Int(NI_MAXHOST))
if getnameinfo(
interfacePointer.pointee.ifa_addr,
socklen_t(interfaceAddress.sa_len),
&hostname,
socklen_t(hostname.count),
nil,
socklen_t(0),
NI_NUMERICHOST
) == 0 {
ipAddress = String(cString: hostname)
// Convert interface address to a human readable string:
var hostname = [CChar](repeating: 0, count: Int(NI_MAXHOST))
if getnameinfo(
interfacePointer.pointee.ifa_addr,
socklen_t(interfaceAddress.sa_len),
&hostname,
socklen_t(hostname.count),
nil,
socklen_t(0),
NI_NUMERICHOST
) == 0 {
ipAddress = String(cString: hostname)
if ipAddress.starts(with: "192.168") {
return ipAddress
}
}
Expand All @@ -65,7 +65,7 @@ class Networking {

freeifaddrs(interfaceList)

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

/// Get configured ad serving domain
Expand Down
4 changes: 2 additions & 2 deletions ios/MullvadVPNUITests/Pages/TunnelControlPage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class TunnelControlPage: Page {

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

Expand All @@ -169,7 +169,7 @@ class TunnelControlPage: Page {
/// of connection attempts.
if connectionAttempts.last?.protocolName == "UDP" {
connectionAttempts.removeLast()
totalAttemptsOffset = -1
totalAttemptsOffset = 1
}
for (attemptIndex, attempt) in connectionAttempts.enumerated() {
if attemptIndex < 3 - totalAttemptsOffset {
Expand Down

0 comments on commit 50283f0

Please sign in to comment.