Skip to content

Commit

Permalink
Merge pull request #171 from WeTransfer/chore/raph/tmob-5314/privacy-…
Browse files Browse the repository at this point in the history
…manifest-update

Add Privacy Manifest
  • Loading branch information
raphkoebraam authored Apr 17, 2024
2 parents 7cf3501 + 82f8539 commit 2b6a279
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 19 deletions.
19 changes: 14 additions & 5 deletions DiagnosticsTests/Reporters/AppSystemMetadataReporterTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,30 @@
// Copyright © 2019 WeTransfer. All rights reserved.
//

import XCTest
@testable import Diagnostics
import XCTest

final class AppSystemMetadataReporterTests: XCTestCase {

/// It should correctly add the metadata.
func testMetadata() {
let metadata = AppSystemMetadataReporter().report().diagnostics as! [String: String]

XCTAssertEqual(metadata[AppSystemMetadataReporter.MetadataKey.appName.rawValue], Bundle.appName)
XCTAssertEqual(metadata[AppSystemMetadataReporter.MetadataKey.appVersion.rawValue], "\(Bundle.appVersion) (\(Bundle.appBuildNumber))")
XCTAssertEqual(metadata[AppSystemMetadataReporter.MetadataKey.appLanguage.rawValue], "en")
XCTAssertEqual(
metadata[AppSystemMetadataReporter.MetadataKey.appName.rawValue],
Bundle.appName
)
XCTAssertEqual(
metadata[AppSystemMetadataReporter.MetadataKey.appVersion.rawValue],
"\(Bundle.appVersion) (\(Bundle.appBuildNumber))"
)
XCTAssertEqual(
metadata[AppSystemMetadataReporter.MetadataKey.appLanguage.rawValue],
"en"
)

AppSystemMetadataReporter.MetadataKey.allCases.forEach { key in
XCTAssertNotNil(metadata[key.rawValue])
XCTAssertNotNil(metadata[key.rawValue], "Metadata not found for \(key).")
}
}
}
30 changes: 25 additions & 5 deletions DiagnosticsTests/Reporters/UserDefaultsReporterTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,36 @@
// Copyright © 2019 WeTransfer. All rights reserved.
//

import XCTest
@testable import Diagnostics
import XCTest

final class UserDefaultsReporterTests: XCTestCase {

/// It should show the user defaults in the report.
func testReportUserDefaults() {
let expectedValue = UUID().uuidString
UserDefaults.standard.set(expectedValue, forKey: "test_key")
let diagnostics = UserDefaultsReporter().report().diagnostics as! [String: Any]
XCTAssertEqual(diagnostics["test_key"] as? String, expectedValue)
let userDefaults = UserDefaults.standard

let expectedValue1 = UUID().uuidString
let key1 = "test_key_1"
userDefaults.set(expectedValue1, forKey: key1)

let expectedValue2 = UUID().uuidString
let key2 = "test_key_2"
userDefaults.set(expectedValue2, forKey: key2)

let unexpectedValue = UUID().uuidString
let unexpectedKey = "unexpected_key"
userDefaults.set(unexpectedValue, forKey: unexpectedKey)

let diagnostics = UserDefaultsReporter(
userDefaults: userDefaults,
keys: [key1, key2]
).report().diagnostics as! [String: Any]

XCTAssertEqual(diagnostics.count, 2)
XCTAssertEqual(diagnostics[key1] as? String, expectedValue1)
XCTAssertEqual(diagnostics[key2] as? String, expectedValue2)
XCTAssertNil(diagnostics[unexpectedKey])
}

}
3 changes: 2 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ let package = Package(name: "Diagnostics",
path: "Sources",
resources: [
.process("style.css"),
.process("functions.js")
.process("functions.js"),
.process("PrivacyInfo.xcprivacy")
]),
.testTarget(name: "DiagnosticsTests", dependencies: ["Diagnostics"], path: "DiagnosticsTests")
],
Expand Down
3 changes: 0 additions & 3 deletions Sources/DiagnosticsReporter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public enum DiagnosticsReporter {
case appSystemMetadata
case smartInsights
case logs
case userDefaults

public var reporter: DiagnosticsReporting {
switch self {
Expand All @@ -32,8 +31,6 @@ public enum DiagnosticsReporter {
return SmartInsightsReporter()
case .logs:
return LogsReporter()
case .userDefaults:
return UserDefaultsReporter()
}
}

Expand Down
40 changes: 40 additions & 0 deletions Sources/PrivacyInfo.xcprivacy
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSPrivacyCollectedDataTypes</key>
<array>
<dict>
<key>NSPrivacyCollectedDataType</key>
<string>NSPrivacyCollectedDataTypeOtherDiagnosticData</string>
<key>NSPrivacyCollectedDataTypeLinked</key>
<false/>
<key>NSPrivacyCollectedDataTypeTracking</key>
<false/>
<key>NSPrivacyCollectedDataTypePurposes</key>
<array>
<string>NSPrivacyCollectedDataTypePurposeAppFunctionality</string>
</array>
</dict>
</array>
<key>NSPrivacyAccessedAPITypes</key>
<array>
<dict>
<key>NSPrivacyAccessedAPIType</key>
<string>NSPrivacyAccessedAPICategoryDiskSpace</string>
<key>NSPrivacyAccessedAPITypeReasons</key>
<array>
<string>7D9E.1</string>
</array>
</dict>
<dict>
<key>NSPrivacyAccessedAPIType</key>
<string>NSPrivacyAccessedAPICategoryUserDefaults</string>
<key>NSPrivacyAccessedAPITypeReasons</key>
<array>
<string>C56D.1</string>
</array>
</dict>
</array>
</dict>
</plist>
3 changes: 3 additions & 0 deletions Sources/Reporters/AppSystemMetadataReporter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ public struct AppSystemMetadataReporter: DiagnosticsReporting {
case freeSpace = "Free space"
case deviceLanguage = "Device Language"
case appLanguage = "App Language"

#if os(iOS) && !targetEnvironment(macCatalyst)
case cellularAllowed = "Cellular Allowed"
#endif
}

static let hardwareName: [String: String] = [
Expand Down
18 changes: 13 additions & 5 deletions Sources/Reporters/UserDefaultsReporter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,22 @@ import Foundation
/// Generates a report from all the registered UserDefault keys.
public final class UserDefaultsReporter: DiagnosticsReporting {

/// Defaults to `standard`. Can be used to override and return a different user defaults.
public static var userDefaults: UserDefaults = .standard
private let userDefaults: UserDefaults

public init() { }
/// All the keys that should be read from the given `UserDefaults` instance.
public let keys: [String]

public init(userDefaults: UserDefaults, keys: [String]) {
self.userDefaults = userDefaults
self.keys = keys
}

public func report() -> DiagnosticsChapter {
let userDefaults = Self.userDefaults.dictionaryRepresentation()
return DiagnosticsChapter(title: "UserDefaults", diagnostics: userDefaults, formatter: Self.self)
let userDefaultsDiagnostics = keys.reduce(into: [:]) { dictionary, key in
dictionary[key] = userDefaults.object(forKey: key)
}

return DiagnosticsChapter(title: "UserDefaults", diagnostics: userDefaultsDiagnostics, formatter: Self.self)
}
}

Expand Down

0 comments on commit 2b6a279

Please sign in to comment.