From 50283f00c732aff28535d6e5584d53d7e8e25dd1 Mon Sep 17 00:00:00 2001 From: Bug Magnet Date: Thu, 21 Nov 2024 08:17:41 +0100 Subject: [PATCH] Stop relying on interface name to get local IP address in UITests --- .../Networking/Networking.swift | 28 +++++++++---------- .../Pages/TunnelControlPage.swift | 4 +-- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/ios/MullvadVPNUITests/Networking/Networking.swift b/ios/MullvadVPNUITests/Networking/Networking.swift index 6e75925d940a..42bac4a243e7 100644 --- a/ios/MullvadVPNUITests/Networking/Networking.swift +++ b/ios/MullvadVPNUITests/Networking/Networking.swift @@ -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 } } @@ -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 diff --git a/ios/MullvadVPNUITests/Pages/TunnelControlPage.swift b/ios/MullvadVPNUITests/Pages/TunnelControlPage.swift index 0cf0b64d88f8..5b9bf715c00d 100644 --- a/ios/MullvadVPNUITests/Pages/TunnelControlPage.swift +++ b/ios/MullvadVPNUITests/Pages/TunnelControlPage.swift @@ -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) @@ -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 {