Skip to content

Commit

Permalink
Implement RRAPI prevention test
Browse files Browse the repository at this point in the history
Summary: Implement RRAPI prevention test for AEMKit.

Reviewed By: ryantobinmeta

Differential Revision: D57597445

fbshipit-source-id: f5180cd3214efc4a13d00488b62f4e06985b5014
  • Loading branch information
jjiang10 authored and facebook-github-bot committed May 23, 2024
1 parent 5543272 commit 8d3dbb8
Showing 1 changed file with 44 additions and 2 deletions.
46 changes: 44 additions & 2 deletions FBAEMKit/FBAEMKitTests/PrivacyManifestTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,20 @@
import XCTest

final class PrivacyManifestTests: XCTestCase {
func testTrackingDomains() {
var manifestUrl: URL?

override func setUp() {
super.setUp()
let bundle = Bundle(for: AEMConfiguration.self)
let manifestUrl = bundle.url(forResource: "PrivacyInfo", withExtension: "xcprivacy")
manifestUrl = bundle.url(forResource: "PrivacyInfo", withExtension: "xcprivacy")
}

override func tearDown() {
manifestUrl = nil
super.tearDown()
}

func testTrackingDomains() {
guard let manifestUrl else {
return XCTFail("Could not find Privacy Manifest file")
}
Expand All @@ -22,4 +33,35 @@ final class PrivacyManifestTests: XCTestCase {
XCTFail("Should not contain tracking domains")
}
}

func testRequiredReasonAPIs() {
guard let manifestUrl else {
return XCTFail("Could not find Privacy Manifest file")
}
let manifest = NSDictionary(contentsOf: manifestUrl)
guard let rrAPIs = manifest?["NSPrivacyAccessedAPITypes"] as? NSArray else {
return XCTFail("Could not find Privacy Accessed API Types")
}
XCTAssertTrue(rrAPIs.count == 1, "Should only expect to have one API in the Privacy Manifest file")
guard let rrAPIDict = rrAPIs[0] as? NSDictionary else {
return XCTFail("Could not find items in Privacy Accessed API Types")
}

XCTAssertEqual(
rrAPIDict["NSPrivacyAccessedAPIType"] as? String,
"NSPrivacyAccessedAPICategoryUserDefaults",
"Should match UserDefaults category"
)
guard let reasons = rrAPIDict["NSPrivacyAccessedAPITypeReasons"] as? NSArray else {
return XCTFail("Could not find Privacy Accessed API Reasons")
}
XCTAssertTrue(
reasons.count == 1,
"""
Should only expect to have one reason for UserDefaults
in the Privacy Manifest file
"""
)
XCTAssertEqual(reasons[0] as? String, "CA92.1", "Reason should match CA92.1")
}
}

0 comments on commit 8d3dbb8

Please sign in to comment.