47 lines
2.0 KiB
Python
47 lines
2.0 KiB
Python
import copy
|
|
import datetime
|
|
import importlib.util
|
|
import pathlib
|
|
import unittest
|
|
|
|
spec = importlib.util.spec_from_file_location('verify_profile', pathlib.Path(__file__).resolve().parents[1] / 'scripts/verify_profile.py')
|
|
module = importlib.util.module_from_spec(spec)
|
|
spec.loader.exec_module(module)
|
|
|
|
class ProfileTests(unittest.TestCase):
|
|
def setUp(self):
|
|
self.app = {'CFBundleIdentifier': 'net.absdev.Tarnax'}
|
|
self.profile = {
|
|
'ApplicationIdentifierPrefix': ['TESTTEAM'],
|
|
'Entitlements': {'application-identifier': 'TESTTEAM.net.absdev.Tarnax'},
|
|
'ExpirationDate': datetime.datetime.now(datetime.timezone.utc) + datetime.timedelta(days=1),
|
|
'ProvisionedDevices': ['test-phone'],
|
|
}
|
|
|
|
def test_exact(self):
|
|
module.validate(self.app, self.profile, 'test-phone', True)
|
|
|
|
def test_wildcard(self):
|
|
for identifier in ['TESTTEAM.*', 'TESTTEAM.net.absdev.*']:
|
|
with self.subTest(identifier=identifier):
|
|
self.profile['Entitlements']['application-identifier'] = identifier
|
|
module.validate(self.app, self.profile, 'test-phone')
|
|
|
|
def test_rejections(self):
|
|
for mutation, options in [
|
|
({'Entitlements': {'application-identifier': 'OTHERTEAM.*'}}, {}),
|
|
({'Entitlements': {'application-identifier': 'TESTTEAM.net.other.*'}}, {}),
|
|
({'ProvisionedDevices': ['other-phone']}, {'device': 'test-phone'}),
|
|
({'ExpirationDate': datetime.datetime(2000, 1, 1)}, {}),
|
|
({'ProvisionedDevices': []}, {}),
|
|
({'Entitlements': {'application-identifier': 'TESTTEAM.*', 'get-task-allow': True}}, {'distribution': True}),
|
|
]:
|
|
with self.subTest(mutation=mutation):
|
|
profile = copy.deepcopy(self.profile)
|
|
profile.update(mutation)
|
|
with self.assertRaises(ValueError):
|
|
module.validate(self.app, profile, **options)
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|