Skip to content

Commit

Permalink
Merge branch 'test-custom-dns-ios-437'
Browse files Browse the repository at this point in the history
  • Loading branch information
buggmagnet committed Apr 8, 2024
2 parents d7bd774 + daa31da commit 6868d3c
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 1 deletion.
1 change: 0 additions & 1 deletion .github/workflows/ios-end-to-end-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ jobs:
toolchain: stable
override: true
target: aarch64-apple-ios

- name: Checkout repository
uses: actions/checkout@v4

Expand Down
73 changes: 73 additions & 0 deletions ios/MullvadVPNUITests/Networking/Networking.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ enum NetworkingError: Error {
case internalError(reason: String)
}

struct DNSServerEntry: Decodable {
let organization: String
let mullvad_dns: Bool
}

/// Class with methods for verifying network connectivity
class Networking {
/// Get IP address of the iOS device under test
Expand Down Expand Up @@ -63,6 +68,18 @@ 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)
Expand Down Expand Up @@ -153,4 +170,60 @@ class Networking {
public static func verifyCannotReachAdServingDomain() throws {
XCTAssertFalse(try Self.canConnectSocket(host: try Self.getAdServingDomain(), port: "80"))
}

/// Verify that the expected DNS server is used by verifying provider name and whether it is a Mullvad DNS server or not
public static func verifyDNSServerProvider(_ providerName: String, isMullvad: Bool) throws {
guard let mullvadDNSLeakURL = URL(string: "https://am.i.mullvad.net/dnsleak") else {
throw NetworkingError.internalError(reason: "Failed to create URL object")
}

var request = URLRequest(url: mullvadDNSLeakURL)
request.setValue("application/json", forHTTPHeaderField: "accept")

var requestData: Data?
var requestResponse: URLResponse?
var requestError: Error?
let completionHandlerInvokedExpectation = XCTestExpectation(
description: "Completion handler for the request is invoked"
)

do {
let dataTask = URLSession.shared.dataTask(with: request) { data, response, error in
requestData = data
requestResponse = response
requestError = error
completionHandlerInvokedExpectation.fulfill()
}

dataTask.resume()

let waitResult = XCTWaiter.wait(for: [completionHandlerInvokedExpectation], timeout: 30)

if waitResult != .completed {
XCTFail("Failed to verify DNS server provider - timeout")
} else {
if let response = requestResponse as? HTTPURLResponse {
if response.statusCode != 200 {
XCTFail("Failed to verify DNS server provider - unexpected server response")
}
}

if let error = requestError {
XCTFail("Failed to verify DNS server provider - encountered error \(error.localizedDescription)")
}

if let requestData = requestData {
let dnsServerEntries = try JSONDecoder().decode([DNSServerEntry].self, from: requestData)
XCTAssertGreaterThanOrEqual(dnsServerEntries.count, 1)

for dnsServerEntry in dnsServerEntries {
XCTAssertEqual(dnsServerEntry.organization, providerName)
XCTAssertEqual(dnsServerEntry.mullvad_dns, isMullvad)
}
}
}
} catch {
XCTFail("Failed to verify DNS server provider - couldn't serialize JSON")
}
}
}
30 changes: 30 additions & 0 deletions ios/MullvadVPNUITests/RelayTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -197,4 +197,34 @@ class RelayTests: LoggedInWithTimeUITestCase {

return relayIPAddress
}

func testCustomDNS() throws {
let dnsServerIPAddress = "8.8.8.8"
let dnsServerProviderName = "GOOGLE"

TunnelControlPage(app)
.tapSecureConnectionButton()

allowAddVPNConfigurations()

HeaderBar(app)
.tapSettingsButton()

SettingsPage(app)
.tapVPNSettingsCell()

VPNSettingsPage(app)
.tapDNSSettingsCell()

DNSSettingsPage(app)
.tapEditButton()
.tapAddAServer()
.tapEnterIPAddressTextField()
.enterText(dnsServerIPAddress)
.dismissKeyboard()
.tapUseCustomDNSSwitch()
.tapDoneButton()

try Networking.verifyDNSServerProvider(dnsServerProviderName, isMullvad: false)
}
}

0 comments on commit 6868d3c

Please sign in to comment.