Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add debug information to requests when running UITests #6976

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions ios/MullvadVPNUITests/Networking/PartnerAPIClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@
description: "Completion handler for the request is invoked"
)

printRequestInformation(method: method, request: request, url: url, jsonObject: jsonObject)
var requestError: Error?

let task = URLSession.shared.dataTask(with: request) { data, response, error in
requestError = error

Expand All @@ -97,17 +97,15 @@
if 200 ... 204 ~= response.statusCode {
print("Request successful")
do {
if data.isEmpty {
// Not all requests return JSON data
jsonResponse = [:]
} else {
if data.isEmpty == false {
jsonResponse = try JSONSerialization.jsonObject(with: data) as? [String: Any] ?? [:]
}
} catch {
XCTFail("Failed to deserialize JSON response")
}
} else {
XCTFail("Request failed with status code \(response.statusCode)")
let errorMessage = (try? XCTUnwrap(String(data: data, encoding: .utf8))) ?? "failed to parse error"
XCTFail("Request failed with error message: \(errorMessage) status code \(response.statusCode)")

Check failure on line 108 in ios/MullvadVPNUITests/Networking/PartnerAPIClient.swift

View workflow job for this annotation

GitHub Actions / reuse-e2e-workflow / Run tests (CustomListsTests)

testAddSingleLocationToCustomList, failed - Request failed with error message: {"code":"PERMISSION_DENIED","error":"Invalid API credentials"} status code 403

Check failure on line 108 in ios/MullvadVPNUITests/Networking/PartnerAPIClient.swift

View workflow job for this annotation

GitHub Actions / reuse-e2e-workflow / Run tests (CustomListsTests)

testCreateCustomListPersistAfterAppRestarts, failed - Request failed with error message: {"code":"PERMISSION_DENIED","error":"Invalid API credentials"} status code 403

Check failure on line 108 in ios/MullvadVPNUITests/Networking/PartnerAPIClient.swift

View workflow job for this annotation

GitHub Actions / reuse-e2e-workflow / Run tests (CustomListsTests)

testDeleteCustomList, failed - Request failed with error message: {"code":"PERMISSION_DENIED","error":"Invalid API credentials"} status code 403

Check failure on line 108 in ios/MullvadVPNUITests/Networking/PartnerAPIClient.swift

View workflow job for this annotation

GitHub Actions / reuse-e2e-workflow / Run tests (CustomListsTests)

testEditCustomListLocations, failed - Request failed with error message: {"code":"PERMISSION_DENIED","error":"Invalid API credentials"} status code 403

Check failure on line 108 in ios/MullvadVPNUITests/Networking/PartnerAPIClient.swift

View workflow job for this annotation

GitHub Actions / reuse-e2e-workflow / Run tests (ConnectivityTests)

testAPIReachableWhenBlocked, failed - Request failed with error message: {"code":"PERMISSION_DENIED","error":"Invalid API credentials"} status code 403

Check failure on line 108 in ios/MullvadVPNUITests/Networking/PartnerAPIClient.swift

View workflow job for this annotation

GitHub Actions / reuse-e2e-workflow / Run tests (ConnectivityTests)

testAppStillFunctioningWhenAPIDown, failed - Request failed with error message: {"code":"PERMISSION_DENIED","error":"Invalid API credentials"} status code 403

Check failure on line 108 in ios/MullvadVPNUITests/Networking/PartnerAPIClient.swift

View workflow job for this annotation

GitHub Actions / reuse-e2e-workflow / Run tests (AccountTests)

testDeleteAccount, failed - Request failed with error message: {"code":"PERMISSION_DENIED","error":"Invalid API credentials"} status code 403

Check failure on line 108 in ios/MullvadVPNUITests/Networking/PartnerAPIClient.swift

View workflow job for this annotation

GitHub Actions / reuse-e2e-workflow / Run tests (AccountTests)

testLogin, failed - Request failed with error message: {"code":"PERMISSION_DENIED","error":"Invalid API credentials"} status code 403

Check failure on line 108 in ios/MullvadVPNUITests/Networking/PartnerAPIClient.swift

View workflow job for this annotation

GitHub Actions / reuse-e2e-workflow / Run tests (AccountTests)

testLoginToAccountWithTooManyDevices, failed - Request failed with error message: {"code":"PERMISSION_DENIED","error":"Invalid API credentials"} status code 403

Check failure on line 108 in ios/MullvadVPNUITests/Networking/PartnerAPIClient.swift

View workflow job for this annotation

GitHub Actions / reuse-e2e-workflow / Run tests (AccountTests)

testLogOut, failed - Request failed with error message: {"code":"PERMISSION_DENIED","error":"Invalid API credentials"} status code 403

Check failure on line 108 in ios/MullvadVPNUITests/Networking/PartnerAPIClient.swift

View workflow job for this annotation

GitHub Actions / reuse-e2e-workflow / Run tests (AccountTests)

testTimeLeft, failed - Request failed with error message: {"code":"PERMISSION_DENIED","error":"Invalid API credentials"} status code 403
}

completionHandlerInvokedExpectation.fulfill()
Expand All @@ -120,4 +118,21 @@

return jsonResponse
}

private func printRequestInformation(method: String, request: URLRequest, url: URL, jsonObject: [String: Any]?) {
/// Under no circumstances should the `accessToken` or the account number ever be printed
if #available(iOS 16, *) {
let headers = request.allHTTPHeaderFields?.filter { element in
element.key != "Authorization"
} ?? [:]

let debugMessage = """
Making a \(method) request to \(url) with the following body \(jsonObject ?? [:])
and headers \(headers)
"""
.replacingOccurrences(of: accessToken, with: "[REDACTED]")
.replacing(/[0-9]{16}/, with: "[REDACTED]")
print(debugMessage)
}
}
}
Loading