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 HTTP errors and status codes to site breakage reports #2477

Merged
merged 10 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from 8 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
4 changes: 2 additions & 2 deletions DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9891,8 +9891,8 @@
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/DuckDuckGo/BrowserServicesKit";
requirement = {
kind = exactVersion;
version = 107.0.1;
kind = revision;
revision = aea703f144eca1116a8019fb5bd4f1fcbdb4b45c;
};
};
C14882EB27F211A000D59F0C /* XCRemoteSwiftPackageReference "SwiftSoup" */ = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/DuckDuckGo/BrowserServicesKit",
"state" : {
"revision" : "93a9a4153429de38c8b9f186617ff34db84f9250",
"version" : "107.0.1"
"revision" : "aea703f144eca1116a8019fb5bd4f1fcbdb4b45c"
}
},
{
Expand Down
15 changes: 12 additions & 3 deletions DuckDuckGo/PrivacyDashboard/PrivacyDashboardViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,16 @@ extension PrivacyDashboardViewController {
let blockedTrackerDomains = privacyInfo.trackerInfo.trackersBlocked.compactMap { $0.domain }
let configuration = ContentBlocking.shared.privacyConfigurationManager.privacyConfig
let protectionsState = configuration.isFeature(.contentBlocking, enabledForDomain: breakageAdditionalInfo.currentURL.host)


var errors: [Error]?
var statusCodes: [Int]?
if let error = breakageAdditionalInfo.error {
errors = [error]
}
if let httpStatusCode = breakageAdditionalInfo.httpStatusCode {
statusCodes = [httpStatusCode]
}

return WebsiteBreakage(siteUrl: breakageAdditionalInfo.currentURL,
category: category,
description: description,
Expand All @@ -255,7 +264,7 @@ extension PrivacyDashboardViewController {
siteType: breakageAdditionalInfo.isDesktop ? .desktop : .mobile,
atb: StatisticsUserDefaults().atb ?? "",
model: UIDevice.current.model,
error: breakageAdditionalInfo.error,
httpStatusCode: breakageAdditionalInfo.httpStatusCode)
errors: errors,
httpStatusCodes: statusCodes)
}
}
39 changes: 34 additions & 5 deletions DuckDuckGoTests/BrokenSiteReportingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,22 @@ final class BrokenSiteReportingTests: XCTestCase {
static let tests = "privacy-reference-tests/broken-site-reporting/tests.json"
}

struct MockError: LocalizedError {
let description: String

init(_ description: String) {
self.description = description
}

var errorDescription: String? {
description
}

var localizedDescription: String? {
description
}
}

override func setUp() {
super.setUp()

Expand Down Expand Up @@ -73,10 +89,15 @@ final class BrokenSiteReportingTests: XCTestCase {
}

os_log("Testing [%s]", type: .info, test.name)


var errors: [Error]?
if let errs = test.errorDescriptions {
errors = errs.map { MockError($0) }
}

let websiteBreakage = WebsiteBreakage(siteUrl: URL(string: test.siteURL)!,
category: test.category,
description: "",
description: test.providedDescription,
osVersion: test.os ?? "",
manufacturer: test.manufacturer ?? "",
upgradedHttps: test.wasUpgraded,
Expand All @@ -91,16 +112,21 @@ final class BrokenSiteReportingTests: XCTestCase {
siteType: .mobile,
atb: "",
model: test.model ?? "",
error: nil,
httpStatusCode: nil)
errors: errors,
httpStatusCodes: test.httpErrorCodes ?? [])

let reporter = WebsiteBreakageReporter(pixelHandler: { params in

for expectedParam in test.expectReportURLParams {

if let actualValue = params[expectedParam.name],
let expectedCleanValue = expectedParam.value.removingPercentEncoding {
if actualValue != expectedCleanValue {
if expectedParam.name == "errorDescriptions" {
// `localizedDescription` includes class information. This format is likely to differ per platform
// anyway. So we'll just check if the value contains an array of strings
XCTAssert(actualValue.split(separator: ",").count > 1,
"Param \(expectedParam.name) expected to be an array of strings. Received: \(actualValue)")
} else if actualValue != expectedCleanValue {
XCTFail("Mismatching param: \(expectedParam.name) => \(expectedCleanValue) != \(actualValue)")
}
} else {
Expand Down Expand Up @@ -133,6 +159,7 @@ private struct Test: Codable {
let siteURL: String
let wasUpgraded: Bool
let category: String
let providedDescription: String?
let blockedTrackers, surrogates: [String]
let atb, blocklistVersion: String
let expectReportURLPrefix: String
Expand All @@ -141,6 +168,8 @@ private struct Test: Codable {
let manufacturer, model, os: String?
let gpcEnabled: Bool?
let protectionsEnabled: Bool
let errorDescriptions: [String]?
let httpErrorCodes: [Int]?
}

// MARK: - ExpectReportURLParam
Expand Down
2 changes: 1 addition & 1 deletion LocalPackages/DuckUI/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ let package = Package(
targets: ["DuckUI"])
],
dependencies: [
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "107.0.1"),
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", revision: "aea703f144eca1116a8019fb5bd4f1fcbdb4b45c"),
],
targets: [
.target(
Expand Down
2 changes: 1 addition & 1 deletion LocalPackages/SyncUI/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ let package = Package(
],
dependencies: [
.package(path: "../DuckUI"),
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "107.0.1"),
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", revision: "aea703f144eca1116a8019fb5bd4f1fcbdb4b45c"),
.package(url: "https://github.com/duckduckgo/DesignResourcesKit", exact: "2.0.0")
],
targets: [
Expand Down
2 changes: 1 addition & 1 deletion LocalPackages/Waitlist/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ let package = Package(
targets: ["Waitlist", "WaitlistMocks"])
],
dependencies: [
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "107.0.1"),
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", revision: "aea703f144eca1116a8019fb5bd4f1fcbdb4b45c"),
.package(url: "https://github.com/duckduckgo/DesignResourcesKit", exact: "2.0.0")
],
targets: [
Expand Down