|
29 | 29 |
|
30 | 30 | class TestSharing(unittest.TestCase): |
31 | 31 | def setup_sharing_and_encrypt(self, id_scope=IdentityScope.UID2): |
32 | | - client = Uid2Client("endpoint", "key", _client_secret) |
| 32 | + client = Uid2Client("endpoint", "key", _client_secret, id_scope) |
33 | 33 | json = self._key_set_to_json_for_sharing([_master_key, _site_key]) |
34 | 34 | keys = client.refresh_json(json) |
35 | 35 |
|
36 | | - ad_token = encrypt(_example_uid, id_scope, keys) |
| 36 | + ad_token = client.encrypt(_example_uid, keys) |
37 | 37 |
|
38 | 38 | return ad_token, keys |
39 | 39 |
|
@@ -75,12 +75,12 @@ def test_can_encrypt_and_decrypt_for_sharing(self): |
75 | 75 |
|
76 | 76 | def test_can_decrypt_another_clients_encrypted_token(self): |
77 | 77 | ad_token, keys = self.setup_sharing_and_encrypt() |
78 | | - receiving_client = Uid2Client("endpoint2", "authkey2", _client_secret) |
| 78 | + receiving_client = Uid2Client("endpoint2", "authkey2", _client_secret, IdentityScope.UID2) |
79 | 79 | keys_json = self._key_set_to_json_for_sharing_with_header('"default_keyset_id": 12345,', 4874, [_master_key, _site_key]) |
80 | 80 |
|
81 | 81 | receiving_keys = receiving_client.refresh_json(keys_json) |
82 | 82 |
|
83 | | - result = decrypt(ad_token, receiving_keys) |
| 83 | + result = receiving_client.decrypt(ad_token, receiving_keys) |
84 | 84 | self.assertEqual(_example_uid, result.uid2) |
85 | 85 |
|
86 | 86 | def test_sharing_token_is_v4(self): |
@@ -121,51 +121,51 @@ def test_multiple_keys_per_keyset(self): |
121 | 121 | _master_secret, keyset_id=1) |
122 | 122 | site_key2 = EncryptionKey(_site_key_id, _site_id, _now - dt.timedelta(days=-2), _now - dt.timedelta(days=-1), _now - dt.timedelta(hours=-1), |
123 | 123 | _site_secret, keyset_id=99999) |
124 | | - client = Uid2Client("endpoint", "authkey", _client_secret) |
| 124 | + client = Uid2Client("endpoint", "authkey", _client_secret, IdentityScope.UID2) |
125 | 125 | json_body = self._key_set_to_json_for_sharing([_master_key, master_key2, _site_key, site_key2]) |
126 | 126 | keys = client.refresh_json(json_body) |
127 | 127 |
|
128 | | - ad_token = encrypt(_example_uid, IdentityScope.UID2, keys) |
| 128 | + ad_token = client.encrypt(_example_uid, keys) |
129 | 129 |
|
130 | | - result = decrypt(ad_token, keys) |
| 130 | + result = client.decrypt(ad_token, keys) |
131 | 131 |
|
132 | 132 | self.assertEqual(_example_uid, result.uid2) |
133 | 133 |
|
134 | 134 | def test_cannot_encrypt_if_no_key_from_default_keyset(self): |
135 | | - client = Uid2Client("endpoint", "authkey", _client_secret) |
| 135 | + client = Uid2Client("endpoint", "authkey", _client_secret, IdentityScope.UID2) |
136 | 136 | json_body = self._key_set_to_json_for_sharing([_master_key]) |
137 | 137 | keys = client.refresh_json(json_body) |
138 | 138 |
|
139 | 139 | self.assertRaises(EncryptionError, encrypt, _example_uid, IdentityScope.UID2, keys) |
140 | 140 |
|
141 | 141 | def test_cannot_encrypt_if_theres_no_default_keyset_header(self): |
142 | | - client = Uid2Client("endpoint", "authkey", _client_secret) |
| 142 | + client = Uid2Client("endpoint", "authkey", _client_secret, IdentityScope.UID2) |
143 | 143 | json_body = self._key_set_to_json_for_sharing_with_header("", _site_id, [_master_key, _site_key]) |
144 | 144 | keys = client.refresh_json(json_body) |
145 | 145 | self.assertRaises(EncryptionError, encrypt, _example_uid, IdentityScope.UID2, keys) |
146 | 146 |
|
147 | 147 |
|
148 | 148 | def test_expiry_in_token_matches_expiry_in_reponse(self): |
149 | | - client = Uid2Client("endpoint", "authkey", _client_secret) |
| 149 | + client = Uid2Client("endpoint", "authkey", _client_secret, IdentityScope.UID2) |
150 | 150 | json_body = self._key_set_to_json_for_sharing_with_header('"default_keyset_id": 99999, "token_expiry_seconds": 2,', 99999, [_master_key, _site_key]) |
151 | 151 | keys = client.refresh_json(json_body) |
152 | 152 |
|
153 | 153 | now = dt.datetime.now(tz=timezone.utc) |
154 | | - ad_token = encrypt(_example_uid, IdentityScope.UID2, keys) |
| 154 | + ad_token = client.encrypt(_example_uid, keys) |
155 | 155 |
|
156 | | - result = decrypt(ad_token, keys, now=now + dt.timedelta(seconds=1)) |
| 156 | + result = client.decrypt(ad_token, keys, now=now + dt.timedelta(seconds=1)) |
157 | 157 | self.assertEqual(_example_uid, result.uid2) |
158 | 158 |
|
159 | 159 | self.assertRaises(EncryptionError, decrypt, ad_token, keys, now=now + dt.timedelta(seconds=3)) |
160 | 160 |
|
161 | 161 | def test_encrypt_key_inactive(self): |
162 | | - client = Uid2Client("endpoint", "authkey", _client_secret) |
| 162 | + client = Uid2Client("endpoint", "authkey", _client_secret, IdentityScope.UID2) |
163 | 163 | key = EncryptionKey(245, _site_id, _now, _now + dt.timedelta(days=1), _now +dt.timedelta(days=2), _site_secret, keyset_id=99999) |
164 | 164 | keys = client.refresh_json(self._key_set_to_json_for_sharing([_master_key, key])) |
165 | 165 | self.assertRaises(EncryptionError, encrypt, _example_uid, IdentityScope.UID2, keys) |
166 | 166 |
|
167 | 167 | def test_encrypt_key_expired(self): |
168 | | - client = Uid2Client("endpoint", "authkey", _client_secret) |
| 168 | + client = Uid2Client("endpoint", "authkey", _client_secret, IdentityScope.UID2) |
169 | 169 | key = EncryptionKey(245, _site_id, _now, _now, _now - dt.timedelta(days=1), _site_secret, keyset_id=99999) |
170 | 170 | keys = client.refresh_json(self._key_set_to_json_for_sharing([_master_key, key])) |
171 | 171 | self.assertRaises(EncryptionError, encrypt, _example_uid, IdentityScope.UID2, keys) |
|
0 commit comments