Jotley / app · jotley.ai / Tests / signing_identity_tests.py
| 1 | """Signing selection tests; no private-key use or keychain mutation.""" |
| 2 | import importlib.util |
| 3 | from pathlib import Path |
| 4 | import unittest |
| 5 | from unittest.mock import patch |
| 6 | from types import SimpleNamespace |
| 7 | |
| 8 | spec = importlib.util.spec_from_file_location("signing_identity", Path(__file__).resolve().parents[1] / "scripts/signing_identity.py") |
| 9 | signing = importlib.util.module_from_spec(spec) |
| 10 | spec.loader.exec_module(signing) |
| 11 | |
| 12 | |
| 13 | class SigningIdentityTests(unittest.TestCase): |
| 14 | def test_exact_identity_and_fingerprint(self) -> None: |
| 15 | listing = ' 1) ' + 'A' * 40 + ' "Developer ID Application: Example (TEAM)"\n' |
| 16 | self.assertEqual(signing.resolve_identity(listing, 'a' * 40, 'developer-id'), 'A' * 40) |
| 17 | self.assertEqual(signing.resolve_identity(listing, 'Developer ID Application: Example (TEAM)'), 'A' * 40) |
| 18 | |
| 19 | def test_absent_and_revoked_do_not_fall_back(self) -> None: |
| 20 | for listing in ['', ' 1) ' + 'A' * 40 + ' "Developer ID Application: Example (TEAM)" (CSSMERR_TP_CERT_REVOKED)']: |
| 21 | with self.assertRaisesRegex(ValueError, 'System keychain fallback is disabled'): |
| 22 | signing.resolve_identity(listing, 'Developer ID Application') |
| 23 | |
| 24 | def test_distribution_classes_are_not_interchangeable(self) -> None: |
| 25 | listing = ' 1) ' + 'B' * 40 + ' "Apple Distribution: Example (TEAM)"' |
| 26 | self.assertEqual(signing.resolve_identity(listing, 'Apple Distribution', 'app-store'), 'B' * 40) |
| 27 | with self.assertRaisesRegex(ValueError, 'requires a Developer ID Application'): |
| 28 | signing.resolve_identity(listing, 'B' * 40, 'developer-id') |
| 29 | |
| 30 | def test_ambiguous_generic_name_requires_exact_choice(self) -> None: |
| 31 | listing = '\n'.join(' 1) ' + char * 40 + f' "Apple Development: Example {char}"' for char in ['A', 'B']) |
| 32 | with self.assertRaisesRegex(ValueError, 'More than one'): |
| 33 | signing.resolve_identity(listing, 'Apple Development') |
| 34 | |
| 35 | def test_preflight_queries_only_login_and_never_signs(self) -> None: |
| 36 | listing = ' 1) ' + 'A' * 40 + ' "Developer ID Application: Example (TEAM)"' |
| 37 | with patch.object(signing.subprocess, 'run', return_value=SimpleNamespace(returncode=0, stdout=listing)) as run: |
| 38 | self.assertEqual(signing.local_signing_identity('Developer ID Application'), 'A' * 40) |
| 39 | self.assertEqual(run.call_count, 1) |
| 40 | self.assertEqual(run.call_args.args[0], ['/usr/bin/security', 'find-identity', '-v', '-p', 'codesigning', str(Path.home() / 'Library/Keychains/login.keychain-db')]) |
| 41 | |
| 42 | |
| 43 | if __name__ == '__main__': |
| 44 | unittest.main() |