Skip to content

Commit

Permalink
Add privacy config version to broken site reports (#989)
Browse files Browse the repository at this point in the history
<!--
Note: This checklist is a reminder of our shared engineering
expectations.
-->

Please review the release process for BrowserServicesKit
[here](https://app.asana.com/0/1200194497630846/1200837094583426).

**Required**:

Task/Issue URL:
https://app.asana.com/0/414709148257752/1208158714445706/f
iOS PR: duckduckgo/iOS#3351
macOS PR: duckduckgo/macos-browser#3256
What kind of version bump will this require?: Major/Minor/Patch

**Optional**:

Tech Design URL:
CC:

**Description**:

<!--
Tagging instructions
If this PR isn't ready to be merged for whatever reason it should be
marked with the `DO NOT MERGE` label (particularly if it's a draft)
If it's pending Product Review/PFR, please add the `Pending Product
Review` label.

If at any point it isn't actively being worked on/ready for
review/otherwise moving forward (besides the above PR/PFR exception)
strongly consider closing it (or not opening it in the first place). If
you decide not to close it, make sure it's labelled to make it clear the
PRs state and comment with more information.
-->

**Steps to test this PR**:
1. Submit a broken site report
1. Set a breakpoint where the report is created or look at the logs for
the pixel
2. Ensure the `remote_config_version` parameter is present and filled
with the config version

<!--
Before submitting a PR, please ensure you have tested the combinations
you expect the reviewer to test, then delete configurations you *know*
do not need explicit testing.

Using a simulator where a physical device is unavailable is acceptable.
-->

**OS Testing**:

* [ ] iOS 14
* [ ] iOS 15
* [ ] iOS 16
* [ ] macOS 10.15
* [ ] macOS 11
* [ ] macOS 12

---
###### Internal references:
[Software Engineering
Expectations](https://app.asana.com/0/59792373528535/199064865822552)
[Technical Design
Template](https://app.asana.com/0/59792373528535/184709971311943)
  • Loading branch information
SlayterDev authored Sep 16, 2024
1 parent f9134f8 commit ae3dbec
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ public struct AppPrivacyConfiguration: PrivacyConfiguration {
self.installDate = installDate
}

public var version: String? {
return data.version
}

public var userUnprotectedDomains: [String] {
return Array(locallyUnprotected.unprotectedDomains).normalizedDomainsForContentBlocking().sorted()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ public protocol PrivacyConfiguration {
/// Identifier of given Privacy Configuration, typically an ETag
var identifier: String { get }

/// Version of config parsed from the `version` key
var version: String? { get }

/// Domains for which user has toggled protection off.
///
/// Use `isUserUnprotected(domain:)` to check if given domain is unprotected.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public struct PrivacyConfigurationData {
case features
case unprotectedTemporary
case trackerAllowlist
case version
}

public struct State {
Expand All @@ -38,6 +39,7 @@ public struct PrivacyConfigurationData {
public let features: [FeatureName: PrivacyFeature]
public let trackerAllowlist: TrackerAllowlist
public let unprotectedTemporary: [ExceptionEntry]
public let version: String?

public init(data: Data) throws {
guard let json = try JSONSerialization.jsonObject(with: data, options: []) as? [String: Any] else {
Expand All @@ -48,6 +50,12 @@ public struct PrivacyConfigurationData {

internal init(json: [String: Any]) {

if let versionInt = json[CodingKeys.version.rawValue] as? Int {
version = String(versionInt)
} else {
version = json[CodingKeys.version.rawValue] as? String
}

if let tempListData = json[CodingKeys.unprotectedTemporary.rawValue] as? [[String: String]] {
unprotectedTemporary = tempListData.compactMap({ ExceptionEntry(json: $0) })
} else {
Expand Down Expand Up @@ -84,10 +92,12 @@ public struct PrivacyConfigurationData {

public init(features: [FeatureName: PrivacyFeature],
unprotectedTemporary: [ExceptionEntry],
trackerAllowlist: TrackerAllowlistData) {
trackerAllowlist: TrackerAllowlistData,
version: String? = nil) {
self.features = features
self.unprotectedTemporary = unprotectedTemporary
self.trackerAllowlist = TrackerAllowlist(entries: trackerAllowlist, state: State.enabled)
self.version = version
}

public class PrivacyFeature {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public struct BrokenSiteReport {
let manufacturer: String
let upgradedHttps: Bool
let tdsETag: String?
let configVersion: String?
let blockedTrackerDomains: [String]
let installedSurrogates: [String]
let isGPCEnabled: Bool
Expand Down Expand Up @@ -112,6 +113,7 @@ public struct BrokenSiteReport {
manufacturer: String,
upgradedHttps: Bool,
tdsETag: String?,
configVersion: String?,
blockedTrackerDomains: [String]?,
installedSurrogates: [String]?,
isGPCEnabled: Bool,
Expand All @@ -134,6 +136,7 @@ public struct BrokenSiteReport {
self.manufacturer = manufacturer
self.upgradedHttps = upgradedHttps
self.tdsETag = tdsETag
self.configVersion = configVersion
self.blockedTrackerDomains = blockedTrackerDomains ?? []
self.installedSurrogates = installedSurrogates ?? []
self.isGPCEnabled = isGPCEnabled
Expand All @@ -160,6 +163,7 @@ public struct BrokenSiteReport {
manufacturer: String,
upgradedHttps: Bool,
tdsETag: String?,
configVersion: String?,
blockedTrackerDomains: [String]?,
installedSurrogates: [String]?,
isGPCEnabled: Bool,
Expand All @@ -186,6 +190,7 @@ public struct BrokenSiteReport {
self.manufacturer = manufacturer
self.upgradedHttps = upgradedHttps
self.tdsETag = tdsETag
self.configVersion = configVersion
self.blockedTrackerDomains = blockedTrackerDomains ?? []
self.installedSurrogates = installedSurrogates ?? []
self.isGPCEnabled = isGPCEnabled
Expand Down Expand Up @@ -215,6 +220,7 @@ public struct BrokenSiteReport {
"siteUrl": siteUrl.trimmingQueryItemsAndFragment().absoluteString,
"upgradedHttps": upgradedHttps.description,
"tds": tdsETag?.trimmingCharacters(in: CharacterSet(charactersIn: "\"")) ?? "",
"remote_config_version": configVersion ?? "",
"blockedTrackers": blockedTrackerDomains.joined(separator: ","),
"surrogates": installedSurrogates.joined(separator: ","),
"gpc": isGPCEnabled.description,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ class PrivacyConfigurationMock: PrivacyConfiguration {
}

var identifier: String = "abcd"
var version: String? = "123456789"
var userUnprotectedDomains: [String] = []
var tempUnprotectedDomains: [String] = []
var trackerAllowlist: PrivacyConfigurationData.TrackerAllowlist = .init(json: ["state": "disabled"])!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class PrivacyConfigurationDataTests: XCTestCase {
let jsonData = data.fromJsonFile("Resources/privacy-config-example.json")
let configData = try PrivacyConfigurationData(data: jsonData)

XCTAssertEqual(configData.version, "2021.6.7")

XCTAssertEqual(configData.unprotectedTemporary.count, 1)
XCTAssertEqual(configData.unprotectedTemporary.first?.domain, "example.com")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ class MockPrivacyConfiguration: PrivacyConfiguration {
}

var identifier: String = "abcd"
var version: String? = "123456789"
var userUnprotectedDomains: [String] = []
var tempUnprotectedDomains: [String] = []
var trackerAllowlist: PrivacyConfigurationData.TrackerAllowlist = .init(json: ["state": "disabled"])!
Expand Down
1 change: 1 addition & 0 deletions Tests/DDGSyncTests/Mocks/Mocks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ class MockPrivacyConfiguration: PrivacyConfiguration {
}

var identifier: String = "abcd"
var version: String? = "123456789"
var userUnprotectedDomains: [String] = []
var tempUnprotectedDomains: [String] = []
var trackerAllowlist: PrivacyConfigurationData.TrackerAllowlist = .init(json: ["state": "disabled"])!
Expand Down
6 changes: 6 additions & 0 deletions Tests/PrivacyDashboardTests/BrokenSiteReportMocks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ struct BrokenSiteReportMocks {
manufacturer: "Apple",
upgradedHttps: true,
tdsETag: "test",
configVersion: "123456789",
blockedTrackerDomains: [],
installedSurrogates: [],
isGPCEnabled: true,
Expand All @@ -55,6 +56,7 @@ struct BrokenSiteReportMocks {
manufacturer: "Apple",
upgradedHttps: true,
tdsETag: "test",
configVersion: "123456789",
blockedTrackerDomains: [],
installedSurrogates: [],
isGPCEnabled: true,
Expand All @@ -80,6 +82,7 @@ struct BrokenSiteReportMocks {
manufacturer: "Apple",
upgradedHttps: true,
tdsETag: "test",
configVersion: "123456789",
blockedTrackerDomains: [],
installedSurrogates: [],
isGPCEnabled: true,
Expand All @@ -105,6 +108,7 @@ struct BrokenSiteReportMocks {
manufacturer: "Apple",
upgradedHttps: true,
tdsETag: "test",
configVersion: "123456789",
blockedTrackerDomains: [],
installedSurrogates: [],
isGPCEnabled: true,
Expand All @@ -130,6 +134,7 @@ struct BrokenSiteReportMocks {
manufacturer: "Apple",
upgradedHttps: true,
tdsETag: "test",
configVersion: "123456789",
blockedTrackerDomains: [],
installedSurrogates: [],
isGPCEnabled: true,
Expand All @@ -155,6 +160,7 @@ struct BrokenSiteReportMocks {
manufacturer: "Apple",
upgradedHttps: true,
tdsETag: "test",
configVersion: "123456789",
blockedTrackerDomains: [],
installedSurrogates: [],
isGPCEnabled: true,
Expand Down

0 comments on commit ae3dbec

Please sign in to comment.