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 CoreKit.

Reviewed By: User9109348102340981

Differential Revision: D57597448

fbshipit-source-id: 240304e86a55aa5b6017ad89a8c84b11f1fbc99e
  • Loading branch information
jjiang10 authored and facebook-github-bot committed May 22, 2024
1 parent cfe38f8 commit 01f945d
Showing 1 changed file with 44 additions and 2 deletions.
46 changes: 44 additions & 2 deletions FBSDKCoreKit/FBSDKCoreKitTests/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: Settings.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 @@ -24,4 +35,35 @@ final class PrivacyManifestTests: XCTestCase {
XCTAssertTrue(trackingDomains.count == 1)
XCTAssertTrue(trackingDomains.contains("ep1.facebook.com"))
}

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 01f945d

Please sign in to comment.