PulseCanvas / app · pulsecanvas.ai / scripts / test-creators-cloud-profile.py
| 1 | #!/usr/bin/env python3 |
| 2 | """Offline fixtures only: no credentials, signing or Apple account calls.""" |
| 3 | from datetime import datetime, timedelta, timezone |
| 4 | import importlib.util |
| 5 | from pathlib import Path |
| 6 | import unittest |
| 7 | |
| 8 | spec = importlib.util.spec_from_file_location("cloud_profile", Path(__file__).with_name("prepare-creators-icloud.py")) |
| 9 | cloud = importlib.util.module_from_spec(spec) |
| 10 | spec.loader.exec_module(cloud) |
| 11 | |
| 12 | |
| 13 | class ProfileTests(unittest.TestCase): |
| 14 | def setUp(self) -> None: |
| 15 | self.profile = { |
| 16 | "ExpirationDate": datetime.now(timezone.utc) + timedelta(days=1), |
| 17 | "TeamIdentifier": [cloud.TEAM], "ProvisionsAllDevices": True, |
| 18 | "Entitlements": { |
| 19 | "com.apple.application-identifier": cloud.TEAM + ".com.protomota.pulsecanvas", |
| 20 | "com.apple.developer.icloud-services": ["CloudDocuments"], |
| 21 | "com.apple.developer.icloud-container-identifiers": [cloud.CONTAINER], |
| 22 | "com.apple.developer.ubiquity-container-identifiers": [cloud.CONTAINER], |
| 23 | }, |
| 24 | } |
| 25 | |
| 26 | def test_valid_profile(self) -> None: |
| 27 | result = cloud.entitlements(self.profile, "com.protomota.pulsecanvas") |
| 28 | self.assertEqual(result["com.apple.developer.icloud-services"], ["CloudDocuments"]) |
| 29 | self.assertNotIn("get-task-allow", result) |
| 30 | |
| 31 | def test_apple_service_wildcard_signs_only_cloud_documents(self) -> None: |
| 32 | entitlements = self.profile["Entitlements"] |
| 33 | entitlements["com.apple.developer.icloud-services"] = "*" |
| 34 | result = cloud.entitlements(self.profile, "com.protomota.pulsecanvas") |
| 35 | self.assertEqual(result["com.apple.developer.icloud-services"], ["CloudDocuments"]) |
| 36 | entitlements["com.apple.developer.icloud-container-identifiers"] = "*" |
| 37 | with self.assertRaises(ValueError): |
| 38 | cloud.entitlements(self.profile, "com.protomota.pulsecanvas") |
| 39 | |
| 40 | def test_invalid_identity_or_type(self) -> None: |
| 41 | for key, value in [("TeamIdentifier", ["OTHERTEAM"]), ("ProvisionsAllDevices", False), |
| 42 | ("ExpirationDate", datetime.now(timezone.utc) - timedelta(days=1))]: |
| 43 | with self.subTest(key=key), self.assertRaises(ValueError): |
| 44 | cloud.entitlements(dict(self.profile, **{key: value}), "com.protomota.pulsecanvas") |
| 45 | with self.assertRaises(ValueError): |
| 46 | cloud.entitlements(self.profile, "wrong.bundle") |
| 47 | |
| 48 | def test_missing_capability_or_debug(self) -> None: |
| 49 | del self.profile["Entitlements"]["com.apple.developer.ubiquity-container-identifiers"] |
| 50 | with self.assertRaises(ValueError): |
| 51 | cloud.entitlements(self.profile, "com.protomota.pulsecanvas") |
| 52 | self.setUp() |
| 53 | self.profile["Entitlements"]["get-task-allow"] = True |
| 54 | with self.assertRaises(ValueError): |
| 55 | cloud.entitlements(self.profile, "com.protomota.pulsecanvas") |
| 56 | |
| 57 | |
| 58 | if __name__ == "__main__": |
| 59 | unittest.main() |