From 554327222f5803316858b7e25f270e920c13afa3 Mon Sep 17 00:00:00 2001 From: Jacky Jiang Date: Thu, 23 May 2024 11:50:48 -0700 Subject: [PATCH] Implement RRAPI prevention test Summary: Implement RRAPI prevention test for CoreKit_Basics. Reviewed By: ryantobinmeta Differential Revision: D57597444 fbshipit-source-id: cc9320a029b9bbbb3e15b20a299c9f3b703ed121 --- .../PrivacyManifestTests.swift | 46 ++++++++++++++++++- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/FBSDKCoreKit_Basics/FBSDKCoreKit_BasicsTests/PrivacyManifestTests.swift b/FBSDKCoreKit_Basics/FBSDKCoreKit_BasicsTests/PrivacyManifestTests.swift index 40d9cbbad..c0f018c3d 100644 --- a/FBSDKCoreKit_Basics/FBSDKCoreKit_BasicsTests/PrivacyManifestTests.swift +++ b/FBSDKCoreKit_Basics/FBSDKCoreKit_BasicsTests/PrivacyManifestTests.swift @@ -11,9 +11,20 @@ import XCTest final class PrivacyManifestTests: XCTestCase { - func testTrackingDomains() { + var manifestUrl: URL? + + override func setUp() { + super.setUp() let bundle = Bundle(for: BasicUtility.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") } @@ -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") + } }