diff options
| author | Niklas Berglund <niklas.berglund@gmail.com> | 2024-03-14 10:23:48 +0100 |
|---|---|---|
| committer | Niklas Berglund <niklas.berglund@gmail.com> | 2024-04-12 15:52:44 +0200 |
| commit | 3a4acfb16cf86c5b0a9ccfcae855a3df22a4342f (patch) | |
| tree | 8db00a873a9f59a5e4ebb46b190c97aa537a9599 | |
| parent | 7cfc90251636fb66661ca85a79463029209141fc (diff) | |
| download | mullvadvpn-3a4acfb16cf86c5b0a9ccfcae855a3df22a4342f.tar.xz mullvadvpn-3a4acfb16cf86c5b0a9ccfcae855a3df22a4342f.zip | |
Add iOS app connection test
3 files changed, 90 insertions, 12 deletions
diff --git a/ios/MullvadVPN.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/ios/MullvadVPN.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved new file mode 100644 index 0000000000..02691892fe --- /dev/null +++ b/ios/MullvadVPN.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -0,0 +1,22 @@ +{ + "pins" : [ + { + "identity" : "swift-log", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-log.git", + "state" : { + "revision" : "173f567a2dfec11d74588eea82cecea555bdc0bc", + "version" : "1.4.0" + } + }, + { + "identity" : "wireguard-apple", + "kind" : "remoteSourceControl", + "location" : "https://github.com/mullvad/wireguard-apple.git", + "state" : { + "revision" : "11a00c20dc03f2751db47e94f585c0778c7bde82" + } + } + ], + "version" : 2 +} diff --git a/ios/MullvadVPNUITests/Networking/Networking.swift b/ios/MullvadVPNUITests/Networking/Networking.swift index 4af87b5523..003cc4386c 100644 --- a/ios/MullvadVPNUITests/Networking/Networking.swift +++ b/ios/MullvadVPNUITests/Networking/Networking.swift @@ -68,18 +68,6 @@ class Networking { throw NetworkingError.internalError(reason: "Failed to determine device's IP address") } - /// Get configured ad serving domain as URL object - private static func getAdServingDomainURL() -> URL? { - guard let adServingDomain = Bundle(for: BaseUITestCase.self) - .infoDictionary?["AdServingDomain"] as? String, - let adServingDomainURL = URL(string: adServingDomain) else { - XCTFail("Ad serving domain not configured") - return nil - } - - return adServingDomainURL - } - /// Get configured ad serving domain private static func getAdServingDomain() throws -> String { guard let adServingDomain = Bundle(for: Networking.self) @@ -226,4 +214,59 @@ class Networking { XCTFail("Failed to verify DNS server provider - couldn't serialize JSON") } } + + public static func verifyConnectedThroughMullvad() { + let mullvadConnectionJsonEndpoint = "https://am.i.mullvad.net/json" + guard let url = URL(string: mullvadConnectionJsonEndpoint) else { + XCTFail("Failed to unwrap URL") + return + } + + let request = URLRequest(url: url) + let completionHandlerInvokedExpectation = XCTestExpectation( + description: "Completion handler for the request is invoked" + ) + + let dataTask = URLSession.shared.dataTask(with: request) { data, response, error in + if let response = response as? HTTPURLResponse { + if response.statusCode != 200 { + XCTFail("Request to connection check API failed - unexpected server response") + } + } + + if let error = error { + XCTFail("Request to connection check API failed - encountered error \(error.localizedDescription)") + } + + guard let data = data else { + XCTFail("Didn't receive any data") + return + } + + do { + let jsonObject = try JSONSerialization.jsonObject(with: data) + + if let dictionary = jsonObject as? [String: Any] { + guard let isConnectedThroughMullvad = dictionary["mullvad_exit_ip"] as? Bool else { + XCTFail("Unexpected JSON format") + return + } + + XCTAssertTrue(isConnectedThroughMullvad) + } + } catch { + XCTFail("Failed to verify whether connected through Mullvad or not") + } + + completionHandlerInvokedExpectation.fulfill() + } + + dataTask.resume() + + let waitResult = XCTWaiter.wait(for: [completionHandlerInvokedExpectation], timeout: 30) + + if waitResult != .completed { + XCTFail("Request to connection check API failed - timeout") + } + } } diff --git a/ios/MullvadVPNUITests/RelayTests.swift b/ios/MullvadVPNUITests/RelayTests.swift index 99b36175ee..6db6dd5f61 100644 --- a/ios/MullvadVPNUITests/RelayTests.swift +++ b/ios/MullvadVPNUITests/RelayTests.swift @@ -26,6 +26,19 @@ class RelayTests: LoggedInWithTimeUITestCase { } } + func testAppConnection() throws { + TunnelControlPage(app) + .tapSecureConnectionButton() + + allowAddVPNConfigurationsIfAsked() + + TunnelControlPage(app) + .waitForSecureConnectionLabel() + + try Networking.verifyCanAccessInternet() + Networking.verifyConnectedThroughMullvad() + } + func testAdBlockingViaDNS() throws { HeaderBar(app) .tapSettingsButton() |
