|
| 1 | +import { deepEqual } from "node:assert/strict"; |
| 2 | +import { afterEach, describe, it } from "node:test"; |
| 3 | +import { generatePrivacyManifest as generatePrivacyManifestActual } from "../../ios/privacyManifest.mjs"; |
| 4 | +import type { JSONObject } from "../../scripts/types.ts"; |
| 5 | +import { fs, setMockFiles } from "../fs.mock.ts"; |
| 6 | + |
| 7 | +const macosOnly = { skip: process.platform === "win32" }; |
| 8 | + |
| 9 | +describe("generatePrivacyManifest()", macosOnly, () => { |
| 10 | + function generatePrivacyManifest(config: JSONObject): Promise<void> { |
| 11 | + const destination = "."; |
| 12 | + fs.mkdirSync(destination, { recursive: true, mode: 0o755 }); |
| 13 | + return generatePrivacyManifestActual(config, "ios", destination, fs); |
| 14 | + } |
| 15 | + |
| 16 | + function readPrivacyManifest() { |
| 17 | + return fs |
| 18 | + .readFileSync("PrivacyInfo.xcprivacy", { encoding: "utf-8" }) |
| 19 | + .split("\n"); |
| 20 | + } |
| 21 | + |
| 22 | + afterEach(() => { |
| 23 | + setMockFiles(); |
| 24 | + }); |
| 25 | + |
| 26 | + it("generates a default manifest", async () => { |
| 27 | + await generatePrivacyManifest({}); |
| 28 | + |
| 29 | + deepEqual(readPrivacyManifest(), DEFAULT_PRIVACY_MANIFEST); |
| 30 | + }); |
| 31 | + |
| 32 | + it("handles invalid configuration", async () => { |
| 33 | + await generatePrivacyManifest({ ios: { privacyManifest: "YES" } }); |
| 34 | + |
| 35 | + deepEqual(readPrivacyManifest(), DEFAULT_PRIVACY_MANIFEST); |
| 36 | + }); |
| 37 | + |
| 38 | + it("appends to default manifest", async () => { |
| 39 | + await generatePrivacyManifest({ |
| 40 | + ios: { |
| 41 | + privacyManifest: { |
| 42 | + NSPrivacyTracking: true, |
| 43 | + NSPrivacyTrackingDomains: ["test"], |
| 44 | + NSPrivacyAccessedAPITypes: ["test"], |
| 45 | + }, |
| 46 | + }, |
| 47 | + }); |
| 48 | + |
| 49 | + deepEqual(readPrivacyManifest(), [ |
| 50 | + '<?xml version="1.0" encoding="UTF-8"?>', |
| 51 | + '<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">', |
| 52 | + '<plist version="1.0">', |
| 53 | + "<dict>", |
| 54 | + " <key>NSPrivacyAccessedAPITypes</key>", |
| 55 | + " <array>", |
| 56 | + " <dict>", |
| 57 | + " <key>NSPrivacyAccessedAPIType</key>", |
| 58 | + " <string>NSPrivacyAccessedAPICategoryFileTimestamp</string>", |
| 59 | + " <key>NSPrivacyAccessedAPITypeReasons</key>", |
| 60 | + " <array>", |
| 61 | + " <string>C617.1</string>", |
| 62 | + " </array>", |
| 63 | + " </dict>", |
| 64 | + " <dict>", |
| 65 | + " <key>NSPrivacyAccessedAPIType</key>", |
| 66 | + " <string>NSPrivacyAccessedAPICategorySystemBootTime</string>", |
| 67 | + " <key>NSPrivacyAccessedAPITypeReasons</key>", |
| 68 | + " <array>", |
| 69 | + " <string>35F9.1</string>", |
| 70 | + " </array>", |
| 71 | + " </dict>", |
| 72 | + " <dict>", |
| 73 | + " <key>NSPrivacyAccessedAPIType</key>", |
| 74 | + " <string>NSPrivacyAccessedAPICategoryUserDefaults</string>", |
| 75 | + " <key>NSPrivacyAccessedAPITypeReasons</key>", |
| 76 | + " <array>", |
| 77 | + " <string>CA92.1</string>", |
| 78 | + " </array>", |
| 79 | + " </dict>", |
| 80 | + " <string>test</string>", |
| 81 | + " </array>", |
| 82 | + " <key>NSPrivacyCollectedDataTypes</key>", |
| 83 | + " <array/>", |
| 84 | + " <key>NSPrivacyTracking</key>", |
| 85 | + " <true/>", |
| 86 | + " <key>NSPrivacyTrackingDomains</key>", |
| 87 | + " <array>", |
| 88 | + " <string>test</string>", |
| 89 | + " </array>", |
| 90 | + "</dict>", |
| 91 | + "</plist>", |
| 92 | + "", |
| 93 | + ]); |
| 94 | + }); |
| 95 | +}); |
| 96 | + |
| 97 | +const DEFAULT_PRIVACY_MANIFEST = [ |
| 98 | + '<?xml version="1.0" encoding="UTF-8"?>', |
| 99 | + '<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">', |
| 100 | + '<plist version="1.0">', |
| 101 | + "<dict>", |
| 102 | + " <key>NSPrivacyAccessedAPITypes</key>", |
| 103 | + " <array>", |
| 104 | + " <dict>", |
| 105 | + " <key>NSPrivacyAccessedAPIType</key>", |
| 106 | + " <string>NSPrivacyAccessedAPICategoryFileTimestamp</string>", |
| 107 | + " <key>NSPrivacyAccessedAPITypeReasons</key>", |
| 108 | + " <array>", |
| 109 | + " <string>C617.1</string>", |
| 110 | + " </array>", |
| 111 | + " </dict>", |
| 112 | + " <dict>", |
| 113 | + " <key>NSPrivacyAccessedAPIType</key>", |
| 114 | + " <string>NSPrivacyAccessedAPICategorySystemBootTime</string>", |
| 115 | + " <key>NSPrivacyAccessedAPITypeReasons</key>", |
| 116 | + " <array>", |
| 117 | + " <string>35F9.1</string>", |
| 118 | + " </array>", |
| 119 | + " </dict>", |
| 120 | + " <dict>", |
| 121 | + " <key>NSPrivacyAccessedAPIType</key>", |
| 122 | + " <string>NSPrivacyAccessedAPICategoryUserDefaults</string>", |
| 123 | + " <key>NSPrivacyAccessedAPITypeReasons</key>", |
| 124 | + " <array>", |
| 125 | + " <string>CA92.1</string>", |
| 126 | + " </array>", |
| 127 | + " </dict>", |
| 128 | + " </array>", |
| 129 | + " <key>NSPrivacyCollectedDataTypes</key>", |
| 130 | + " <array/>", |
| 131 | + " <key>NSPrivacyTracking</key>", |
| 132 | + " <false/>", |
| 133 | + " <key>NSPrivacyTrackingDomains</key>", |
| 134 | + " <array/>", |
| 135 | + "</dict>", |
| 136 | + "</plist>", |
| 137 | + "", |
| 138 | +]; |
0 commit comments