Skip to content

Commit a7a0e2d

Browse files
committed
fix: unseal_event_response returns correct EventResponse structure
BREAKING CHANGE: rename `unseal_events_response` to `unseal_event_response` to keep proper naming
1 parent 1ed2fa3 commit a7a0e2d

File tree

8 files changed

+68
-48
lines changed

8 files changed

+68
-48
lines changed

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,17 +182,16 @@ import os
182182

183183
from dotenv import load_dotenv
184184

185-
from fingerprint_pro_server_api_sdk import EventResponse
186-
from fingerprint_pro_server_api_sdk.sealed import unseal_events_response, DecryptionKey, DecryptionAlgorithm
185+
from fingerprint_pro_server_api_sdk import unseal_event_response, DecryptionKey, DecryptionAlgorithm
187186

188187
load_dotenv()
189188

190189
sealed_result = base64.b64decode(os.environ["BASE64_SEALED_RESULT"])
191190
key = base64.b64decode(os.environ["BASE64_KEY"])
192191

193192
try:
194-
events_response: EventResponse = unseal_events_response(sealed_result, [DecryptionKey(key, DecryptionAlgorithm['Aes256Gcm'])])
195-
print("\n\n\nEvent response: \n", events_response.products)
193+
event_response = unseal_event_response(sealed_result, [DecryptionKey(key, DecryptionAlgorithm['Aes256Gcm'])])
194+
print("\n\n\nEvent response: \n", event_response.products)
196195
except Exception as e:
197196
print("Exception when calling unsealing events response: %s\n" % e)
198197
exit(1)

docs/SealedResults.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Sealed results
22

3-
## **UnsealEventsResponse**
4-
> unseal_events_response(sealed bytes, keys DecryptionKey[]) -> EventResponse
3+
## **UnsealEventResponse**
4+
> unseal_event_response(sealed: bytes, keys: DecryptionKey[]) -> EventResponse
55
66
Decrypts the sealed response with provided keys.
77
### Required Parameters

fingerprint_pro_server_api_sdk/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,5 @@
113113
from fingerprint_pro_server_api_sdk.models.webhook_visit import WebhookVisit
114114
# import custom methods into sdk package
115115
from fingerprint_pro_server_api_sdk.webhook import Webhook
116+
from fingerprint_pro_server_api_sdk.sealed import ApiClientDeserializer, DecryptionAlgorithm, DecryptionKey, \
117+
UnsealError, UnsealAggregateError, unseal_event_response

fingerprint_pro_server_api_sdk/sealed.py

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import json
2+
from typing import List
3+
24
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
35
from cryptography.hazmat.backends import default_backend
46
import zlib
57

8+
from fingerprint_pro_server_api_sdk.api_client import ApiClientDeserializer
69
from fingerprint_pro_server_api_sdk.models.event_response import EventResponse
710

811
SEALED_HEADER = bytes([0x9e, 0x85, 0xdc, 0xed])
@@ -12,49 +15,61 @@
1215

1316

1417
class DecryptionKey:
15-
def __init__(self, key, algorithm):
18+
"""Key for decryption of sealed data."""
19+
exception: Exception
20+
algorithm: str
21+
22+
def __init__(self, key: bytes, algorithm: str):
1623
self.key = key
1724
self.algorithm = algorithm
1825

1926

2027
class UnsealError(Exception):
28+
"""Error during unsealing."""
2129
exception: Exception
2230
key: DecryptionKey
2331

24-
def __init__(self, exception, key):
32+
def __init__(self, exception: Exception, key: DecryptionKey):
2533
self.exception = exception
2634
self.key = key
2735

2836

2937
class UnsealAggregateError(Exception):
30-
def __init__(self, errors):
38+
"""Aggregated error during unsealing."""
39+
errors: List[UnsealError]
40+
41+
def __init__(self, errors: List[UnsealError]):
3142
self.errors = errors
3243
super().__init__("Unable to decrypt sealed data")
3344

3445

35-
def parse_events_response(unsealed):
36-
json_data = json.loads(unsealed)
46+
def unseal_event_response(sealed_data: bytes, decryption_keys: List[DecryptionKey]) -> EventResponse:
47+
"""Unseal event response with one of the provided keys."""
48+
unsealed = __unseal(sealed_data, decryption_keys)
49+
return __parse_event_response(unsealed)
3750

38-
if 'products' not in json_data:
39-
raise ValueError('Sealed data is not valid events response')
4051

41-
return EventResponse(json_data['products'])
52+
def __parse_event_response(unsealed: str) -> EventResponse:
53+
"""Parse event response from unsealed data."""
54+
json_data = json.loads(unsealed)
4255

56+
if 'products' not in json_data:
57+
raise ValueError('Sealed data is not valid event response')
4358

44-
def unseal_events_response(sealed_data, decryption_keys):
45-
unsealed = unseal(sealed_data, decryption_keys)
46-
return parse_events_response(unsealed)
59+
result: EventResponse = ApiClientDeserializer.deserialize(json_data, 'EventResponse')
60+
return result
4761

4862

49-
def unseal(sealed_data, decryption_keys):
63+
def __unseal(sealed_data: bytes, decryption_keys: List[DecryptionKey]) -> str:
64+
"""Unseal data with one of the provided keys."""
5065
if sealed_data[:len(SEALED_HEADER)].hex() != SEALED_HEADER.hex():
5166
raise ValueError('Invalid sealed data header')
5267

5368
errors = []
5469
for decryption_key in decryption_keys:
5570
if decryption_key.algorithm == DecryptionAlgorithm['Aes256Gcm']:
5671
try:
57-
return unseal_aes256gcm(sealed_data, decryption_key.key)
72+
return __unseal_aes256gcm(sealed_data, decryption_key.key)
5873
except Exception as e:
5974
errors.append(UnsealError(e, decryption_key))
6075
continue
@@ -64,7 +79,8 @@ def unseal(sealed_data, decryption_keys):
6479
raise UnsealAggregateError(errors)
6580

6681

67-
def unseal_aes256gcm(sealed_data, decryption_key):
82+
def __unseal_aes256gcm(sealed_data: bytes, decryption_key: bytes) -> str:
83+
"""Unseal data with AES-256-GCM."""
6884
nonce_length = 12
6985
nonce = sealed_data[len(SEALED_HEADER):len(SEALED_HEADER) + nonce_length]
7086

sealed_results_example.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,16 @@
33

44
from dotenv import load_dotenv
55

6-
from fingerprint_pro_server_api_sdk import EventResponse
7-
from fingerprint_pro_server_api_sdk.sealed import unseal_events_response, DecryptionKey, DecryptionAlgorithm
6+
from fingerprint_pro_server_api_sdk.sealed import unseal_event_response, DecryptionKey, DecryptionAlgorithm
87

98
load_dotenv()
109

1110
sealed_result = base64.b64decode(os.environ["BASE64_SEALED_RESULT"])
1211
key = base64.b64decode(os.environ["BASE64_KEY"])
1312

1413
try:
15-
events_response: EventResponse = unseal_events_response(sealed_result, [DecryptionKey(key, DecryptionAlgorithm['Aes256Gcm'])])
16-
print("\n\n\nEvent response: \n", events_response.products)
14+
event_response = unseal_event_response(sealed_result, [DecryptionKey(key, DecryptionAlgorithm['Aes256Gcm'])])
15+
print("\n\n\nEvent response: \n", event_response.products)
1716
except Exception as e:
1817
print("Exception when calling unsealing events response: %s\n" % e)
1918
exit(1)

template/README.mustache

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,17 +188,16 @@ import os
188188

189189
from dotenv import load_dotenv
190190

191-
from fingerprint_pro_server_api_sdk import EventResponse
192-
from fingerprint_pro_server_api_sdk.sealed import unseal_events_response, DecryptionKey, DecryptionAlgorithm
191+
from fingerprint_pro_server_api_sdk import unseal_event_response, DecryptionKey, DecryptionAlgorithm
193192

194193
load_dotenv()
195194

196195
sealed_result = base64.b64decode(os.environ["BASE64_SEALED_RESULT"])
197196
key = base64.b64decode(os.environ["BASE64_KEY"])
198197

199198
try:
200-
events_response: EventResponse = unseal_events_response(sealed_result, [DecryptionKey(key, DecryptionAlgorithm['Aes256Gcm'])])
201-
print("\n\n\nEvent response: \n", events_response.products)
199+
event_response = unseal_event_response(sealed_result, [DecryptionKey(key, DecryptionAlgorithm['Aes256Gcm'])])
200+
print("\n\n\nEvent response: \n", event_response.products)
202201
except Exception as e:
203202
print("Exception when calling unsealing events response: %s\n" % e)
204203
exit(1)

template/__init__package.mustache

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,5 @@ from {{packageName}}.base_model import BaseModel
1717
{{/model}}{{/models}}
1818
# import custom methods into sdk package
1919
from {{packageName}}.webhook import Webhook
20+
from {{packageName}}.sealed import ApiClientDeserializer, DecryptionAlgorithm, DecryptionKey, \
21+
UnsealError, UnsealAggregateError, unseal_event_response

test/test_sealed.py

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,38 @@
33
import json
44
import unittest
55

6-
from fingerprint_pro_server_api_sdk import EventResponse
7-
from fingerprint_pro_server_api_sdk.sealed import DecryptionAlgorithm, DecryptionKey, unseal_events_response, \
8-
UnsealError, UnsealAggregateError
9-
6+
from fingerprint_pro_server_api_sdk import ApiClientDeserializer, DecryptionAlgorithm, DecryptionKey, \
7+
unseal_event_response, UnsealError, UnsealAggregateError, EventResponse, ProductsResponse, \
8+
ProductsResponseIdentification, BrowserDetails
109

1110
class TestSealed(unittest.TestCase):
1211
valid_key = base64.b64decode('p2PA7MGy5tx56cnyJaFZMr96BCFwZeHjZV2EqMvTq53=')
1312
invalid_key = base64.b64decode('a2PA7MGy5tx56cnyJaFZMr96BCFwZeHjZV2EqMvTq53=')
1413

1514
def test_unseal_aes256gcm(self):
1615
with io.open("./test/mocks/sealed_result.json", 'r', encoding='utf-8') as f:
17-
expected_result = EventResponse(json.load(f)['products'])
16+
expected_result = ApiClientDeserializer.deserialize(json.load(f), 'EventResponse')
1817

1918
sealed_data = base64.b64decode(
2019
'noXc7SXO+mqeAGrvBMgObi/S0fXTpP3zupk8qFqsO/1zdtWCD169iLA3VkkZh9ICHpZ0oWRzqG0M9/TnCeKFohgBLqDp6O0zEfXOv6i5q++aucItznQdLwrKLP+O0blfb4dWVI8/aSbd4ELAZuJJxj9bCoVZ1vk+ShbUXCRZTD30OIEAr3eiG9aw00y1UZIqMgX6CkFlU9L9OnKLsNsyomPIaRHTmgVTI5kNhrnVNyNsnzt9rY7fUD52DQxJILVPrUJ1Q+qW7VyNslzGYBPG0DyYlKbRAomKJDQIkdj/Uwa6bhSTq4XYNVvbk5AJ/dGwvsVdOnkMT2Ipd67KwbKfw5bqQj/cw6bj8Cp2FD4Dy4Ud4daBpPRsCyxBM2jOjVz1B/lAyrOp8BweXOXYugwdPyEn38MBZ5oL4D38jIwR/QiVnMHpERh93jtgwh9Abza6i4/zZaDAbPhtZLXSM5ztdctv8bAb63CppLU541Kf4OaLO3QLvfLRXK2n8bwEwzVAqQ22dyzt6/vPiRbZ5akh8JB6QFXG0QJF9DejsIspKF3JvOKjG2edmC9o+GfL3hwDBiihYXCGY9lElZICAdt+7rZm5UxMx7STrVKy81xcvfaIp1BwGh/HyMsJnkE8IczzRFpLlHGYuNDxdLoBjiifrmHvOCUDcV8UvhSV+UAZtAVejdNGo5G/bz0NF21HUO4pVRPu6RqZIs/aX4hlm6iO/0Ru00ct8pfadUIgRcephTuFC2fHyZxNBC6NApRtLSNLfzYTTo/uSjgcu6rLWiNo5G7yfrM45RXjalFEFzk75Z/fu9lCJJa5uLFgDNKlU+IaFjArfXJCll3apbZp4/LNKiU35ZlB7ZmjDTrji1wLep8iRVVEGht/DW00MTok7Zn7Fv+MlxgWmbZB3BuezwTmXb/fNw==')
2120

22-
result = unseal_events_response(sealed_data, [
21+
result = unseal_event_response(sealed_data, [
2322
DecryptionKey(self.invalid_key, DecryptionAlgorithm['Aes256Gcm']),
2423
DecryptionKey(self.valid_key, DecryptionAlgorithm['Aes256Gcm']),
2524
])
2625

2726
self.assertEqual(result, expected_result)
27+
self.assertIsInstance(result, EventResponse)
28+
self.assertIsInstance(result.products, ProductsResponse)
29+
self.assertIsInstance(result.products.identification, ProductsResponseIdentification)
30+
self.assertIsInstance(result.products.identification.data.browser_details, BrowserDetails)
2831

2932
def test_unseal_invalid_header(self):
3033
sealed_data = base64.b64decode(
3134
'xzXc7SXO+mqeAGrvBMgObi/S0fXTpP3zupk8qFqsO/1zdtWCD169iLA3VkkZh9ICHpZ0oWRzqG0M9/TnCeKFohgBLqDp6O0zEfXOv6i5q++aucItznQdLwrKLP+O0blfb4dWVI8/aSbd4ELAZuJJxj9bCoVZ1vk+ShbUXCRZTD30OIEAr3eiG9aw00y1UZIqMgX6CkFlU9L9OnKLsNsyomPIaRHTmgVTI5kNhrnVNyNsnzt9rY7fUD52DQxJILVPrUJ1Q+qW7VyNslzGYBPG0DyYlKbRAomKJDQIkdj/Uwa6bhSTq4XYNVvbk5AJ/dGwvsVdOnkMT2Ipd67KwbKfw5bqQj/cw6bj8Cp2FD4Dy4Ud4daBpPRsCyxBM2jOjVz1B/lAyrOp8BweXOXYugwdPyEn38MBZ5oL4D38jIwR/QiVnMHpERh93jtgwh9Abza6i4/zZaDAbPhtZLXSM5ztdctv8bAb63CppLU541Kf4OaLO3QLvfLRXK2n8bwEwzVAqQ22dyzt6/vPiRbZ5akh8JB6QFXG0QJF9DejsIspKF3JvOKjG2edmC9o+GfL3hwDBiihYXCGY9lElZICAdt+7rZm5UxMx7STrVKy81xcvfaIp1BwGh/HyMsJnkE8IczzRFpLlHGYuNDxdLoBjiifrmHvOCUDcV8UvhSV+UAZtAVejdNGo5G/bz0NF21HUO4pVRPu6RqZIs/aX4hlm6iO/0Ru00ct8pfadUIgRcephTuFC2fHyZxNBC6NApRtLSNLfzYTTo/uSjgcu6rLWiNo5G7yfrM45RXjalFEFzk75Z/fu9lCJJa5uLFgDNKlU+IaFjArfXJCll3apbZp4/LNKiU35ZlB7ZmjDTrji1wLep8iRVVEGht/DW00MTok7Zn7Fv+MlxgWmbZB3BuezwTmXb/fNw==')
3235

33-
with self.assertRaisesRegex(Exception, "Invalid sealed data header"):
34-
unseal_events_response(sealed_data, [
36+
with self.assertRaisesRegex(ValueError, "Invalid sealed data header"):
37+
unseal_event_response(sealed_data, [
3538
DecryptionKey(self.invalid_key, DecryptionAlgorithm['Aes256Gcm']),
3639
DecryptionKey(self.valid_key, DecryptionAlgorithm['Aes256Gcm']),
3740
])
@@ -40,8 +43,8 @@ def test_unseal_invalid_algorithm(self):
4043
sealed_data = base64.b64decode(
4144
'noXc7SXO+mqeAGrvBMgObi/S0fXTpP3zupk8qFqsO/1zdtWCD169iLA3VkkZh9ICHpZ0oWRzqG0M9/TnCeKFohgBLqDp6O0zEfXOv6i5q++aucItznQdLwrKLP+O0blfb4dWVI8/aSbd4ELAZuJJxj9bCoVZ1vk+ShbUXCRZTD30OIEAr3eiG9aw00y1UZIqMgX6CkFlU9L9OnKLsNsyomPIaRHTmgVTI5kNhrnVNyNsnzt9rY7fUD52DQxJILVPrUJ1Q+qW7VyNslzGYBPG0DyYlKbRAomKJDQIkdj/Uwa6bhSTq4XYNVvbk5AJ/dGwvsVdOnkMT2Ipd67KwbKfw5bqQj/cw6bj8Cp2FD4Dy4Ud4daBpPRsCyxBM2jOjVz1B/lAyrOp8BweXOXYugwdPyEn38MBZ5oL4D38jIwR/QiVnMHpERh93jtgwh9Abza6i4/zZaDAbPhtZLXSM5ztdctv8bAb63CppLU541Kf4OaLO3QLvfLRXK2n8bwEwzVAqQ22dyzt6/vPiRbZ5akh8JB6QFXG0QJF9DejsIspKF3JvOKjG2edmC9o+GfL3hwDBiihYXCGY9lElZICAdt+7rZm5UxMx7STrVKy81xcvfaIp1BwGh/HyMsJnkE8IczzRFpLlHGYuNDxdLoBjiifrmHvOCUDcV8UvhSV+UAZtAVejdNGo5G/bz0NF21HUO4pVRPu6RqZIs/aX4hlm6iO/0Ru00ct8pfadUIgRcephTuFC2fHyZxNBC6NApRtLSNLfzYTTo/uSjgcu6rLWiNo5G7yfrM45RXjalFEFzk75Z/fu9lCJJa5uLFgDNKlU+IaFjArfXJCll3apbZp4/LNKiU35ZlB7ZmjDTrji1wLep8iRVVEGht/DW00MTok7Zn7Fv+MlxgWmbZB3BuezwTmXb/fNw==')
4245

43-
with self.assertRaisesRegex(Exception, "Unsupported decryption algorithm: invalid"):
44-
unseal_events_response(sealed_data, [
46+
with self.assertRaisesRegex(ValueError, "Unsupported decryption algorithm: invalid"):
47+
unseal_event_response(sealed_data, [
4548
DecryptionKey(self.invalid_key, 'invalid'),
4649
DecryptionKey(self.valid_key, DecryptionAlgorithm['Aes256Gcm']),
4750
])
@@ -51,8 +54,8 @@ def test_unseal_invalid_data(self):
5154
# "{\"invalid\":true}"
5255
'noXc7VOpBstjjcavDKSKr4HTavt4mdq8h6NC32T0hUtw9S0jXT8lPjZiWL8SyHxmrF3uTGqO+g==')
5356

54-
with self.assertRaisesRegex(Exception, "Sealed data is not valid events response"):
55-
unseal_events_response(sealed_data, [
57+
with self.assertRaisesRegex(ValueError, "Sealed data is not valid event response"):
58+
unseal_event_response(sealed_data, [
5659
DecryptionKey(self.invalid_key, DecryptionAlgorithm['Aes256Gcm']),
5760
DecryptionKey(self.valid_key, DecryptionAlgorithm['Aes256Gcm']),
5861
])
@@ -61,8 +64,8 @@ def test_unseal_not_compressed_data(self):
6164
sealed_data = base64.b64decode(
6265
'noXc7dtuk0smGE+ZbaoXzrp6Rq8ySxLepejTsu7+jUXlPhV1w+WuHx9gbPhaENJnOQo8BcGmsaRhL5k2NVj+DRNzYO9cQD7wHxmXKCyTbl/dvSYOMoHziUZ2VbQ7tmaorFny26v8jROr/UBGfvPE0dLKC36IN9ZlJ3X0NZJO8SY+8bCr4mTrkVZsv/hpvZp+OjC4h7e5vxcpmnBWXzxfaO79Lq3aMRIEf9XfK7/bVIptHaEqtPKCTwl9rz1KUpUUNQSHTPM0NlqJe9bjYf5mr1uYvWHhcJoXSyRyVMxIv/quRiw3SKJzAMOTBiAvFICpWuRFa+T/xIMHK0g96w/IMQo0jdY1E067ZEvBUOBmsJnGJg1LllS3rbJVe+E2ClFNL8SzFphyvtlcfvYB+SVSD4bzI0w/YCldv5Sq42BFt5bn4n4aE5A6658DYsfSRYWqP6OpqPJx96cY34W7H1t/ZG0ulez6zF5NvWhc1HDQ1gMtXd+K/ogt1n+FyFtn8xzvtSGkmrc2jJgYNI5Pd0Z0ent73z0MKbJx9v2ta/emPEzPr3cndN5amdr6TmRkDU4bq0vyhAh87DJrAnJQLdrvYLddnrr8xTdeXxj1i1Yug6SGncPh9sbTYkdOfuamPAYOuiJVBAMcfYsYEiQndZe8mOQ4bpCr+hxAAqixhZ16pQ8CeUwa247+D2scRymLB8qJXlaERuFZtWGVAZ8VP/GS/9EXjrzpjGX9vlrIPeJP8fh2S5QPzw55cGNJ7JfAdOyManXnoEw2/QzDhSZQARVl+akFgSO0Y13YmbiL7H6HcKWGcJ2ipDKIaj2fJ7GE0Vzyt+CBEezSQR99Igd8x3p2JtvsVKp35iLPksjS1VqtSCTbuIRUlINlfQHNjeQiE/B/61jo3Mf7SmjYjqtvXt5e9RKb+CQku2qH4ZU8xN3DSg+4mLom3BgKBkm/MoyGBpMK41c96d2tRp3tp4hV0F6ac02Crg7P2lw8IUct+i2VJ8VUjcbRfTIPQs0HjNjM6/gLfLCkWOHYrlFjwusXWQCJz91Kq+hVxj7M9LtplPO4AUq6RUMNhlPGUmyOI2tcUMrjq9vMLXGlfdkH185zM4Mk+O7DRLC8683lXZFZvcBEmxr855PqLLH/9SpYKHBoGRatDRdQe3oRp6gHS0jpQ1SW/si4kvLKiUNjiBExvbQVOUV7/VFXvG1RpM9wbzSoOd40gg7ZzD/72QshUC/25DkM/Pm7RBzwtjgmnRKjT+mROeC/7VQLoz3amv09O8Mvbt+h/lX5+51Q834F7NgIGagbB20WtWcMtrmKrvCEZlaoiZrmYVSbi1RfknRK7CTPJkopw9IjO7Ut2EhKZ+jL4rwk6TlVm6EC6Kuj7KNqp6wB/UNe9eM2Eym/aiHAcja8XN4YQhSIuJD2Wxb0n3LkKnAjK1/GY65c8K6rZsVYQ0MQL1j4lMl0UZPjG/vzKyetIsVDyXc4J9ZhOEMYnt/LaxEeSt4EMJGBA9wpTmz33X4h3ij0Y3DY/rH7lrEScUknw20swTZRm5T6q1bnimj7M1OiOkebdI09MZ0nyaTWRHdB7B52C/moh89Q7qa2Fulp5h8Us1FYRkWBLt37a5rGI1IfVeP38KaPbagND+XzWpNqX4HVrAVPLQVK5EwUvGamED3ooJ0FMieTc0IH0N+IeUYG7Q8XmrRVBcw32W8pEfYLO9L71An/J0jQZCIP8DuQnUG0mOvunOuloBGvP/9LvkBlkamh68F0a5f5ny1jloyIFJhRh5dt2SBlbsXS9AKqUwARYSSsA9Ao4WJWOZMyjp8A+qIBAfW65MdhhUDKYMBgIAbMCc3uiptzElQQopE5TT5xIhwfYxa503jVzQbz1Q==')
6366

64-
with self.assertRaisesRegex(Exception, "Unable to decrypt sealed data") as context:
65-
unseal_events_response(sealed_data, [
67+
with self.assertRaisesRegex(UnsealAggregateError, "Unable to decrypt sealed data") as context:
68+
unseal_event_response(sealed_data, [
6669
DecryptionKey(self.invalid_key, DecryptionAlgorithm['Aes256Gcm']),
6770
DecryptionKey(self.valid_key, DecryptionAlgorithm['Aes256Gcm']),
6871
])
@@ -76,26 +79,26 @@ def test_unseal_all_keys_invalid(self):
7679
sealed_data = base64.b64decode(
7780
'noXc7SXO+mqeAGrvBMgObi/S0fXTpP3zupk8qFqsO/1zdtWCD169iLA3VkkZh9ICHpZ0oWRzqG0M9/TnCeKFohgBLqDp6O0zEfXOv6i5q++aucItznQdLwrKLP+O0blfb4dWVI8/aSbd4ELAZuJJxj9bCoVZ1vk+ShbUXCRZTD30OIEAr3eiG9aw00y1UZIqMgX6CkFlU9L9OnKLsNsyomPIaRHTmgVTI5kNhrnVNyNsnzt9rY7fUD52DQxJILVPrUJ1Q+qW7VyNslzGYBPG0DyYlKbRAomKJDQIkdj/Uwa6bhSTq4XYNVvbk5AJ/dGwvsVdOnkMT2Ipd67KwbKfw5bqQj/cw6bj8Cp2FD4Dy4Ud4daBpPRsCyxBM2jOjVz1B/lAyrOp8BweXOXYugwdPyEn38MBZ5oL4D38jIwR/QiVnMHpERh93jtgwh9Abza6i4/zZaDAbPhtZLXSM5ztdctv8bAb63CppLU541Kf4OaLO3QLvfLRXK2n8bwEwzVAqQ22dyzt6/vPiRbZ5akh8JB6QFXG0QJF9DejsIspKF3JvOKjG2edmC9o+GfL3hwDBiihYXCGY9lElZICAdt+7rZm5UxMx7STrVKy81xcvfaIp1BwGh/HyMsJnkE8IczzRFpLlHGYuNDxdLoBjiifrmHvOCUDcV8UvhSV+UAZtAVejdNGo5G/bz0NF21HUO4pVRPu6RqZIs/aX4hlm6iO/0Ru00ct8pfadUIgRcephTuFC2fHyZxNBC6NApRtLSNLfzYTTo/uSjgcu6rLWiNo5G7yfrM45RXjalFEFzk75Z/fu9lCJJa5uLFgDNKlU+IaFjArfXJCll3apbZp4/LNKiU35ZlB7ZmjDTrji1wLep8iRVVEGht/DW00MTok7Zn7Fv+MlxgWmbZB3BuezwTmXb/fNw==')
7881

79-
with self.assertRaisesRegex(Exception, 'Unable to decrypt sealed data'):
80-
unseal_events_response(sealed_data, [
82+
with self.assertRaisesRegex(UnsealAggregateError, 'Unable to decrypt sealed data'):
83+
unseal_event_response(sealed_data, [
8184
DecryptionKey(self.invalid_key, DecryptionAlgorithm['Aes256Gcm']),
8285
DecryptionKey(self.invalid_key, DecryptionAlgorithm['Aes256Gcm']),
8386
])
8487

8588
def test_unseal_empty_data(self):
8689
sealed_data = bytearray(b'')
8790

88-
with self.assertRaisesRegex(Exception, 'Invalid sealed data header'):
89-
unseal_events_response(sealed_data, [
91+
with self.assertRaisesRegex(ValueError, 'Invalid sealed data header'):
92+
unseal_event_response(sealed_data, [
9093
DecryptionKey(self.invalid_key, DecryptionAlgorithm['Aes256Gcm']),
9194
DecryptionKey(self.valid_key, DecryptionAlgorithm['Aes256Gcm']),
9295
])
9396

9497
def test_unseal_invalid_nonce(self):
9598
sealed_data = bytes([0x9E, 0x85, 0xDC, 0xED, 0xAA, 0xBB, 0xCC])
9699

97-
with self.assertRaisesRegex(Exception, 'Unable to decrypt sealed data') as context:
98-
unseal_events_response(sealed_data, [
100+
with self.assertRaisesRegex(UnsealAggregateError, 'Unable to decrypt sealed data') as context:
101+
unseal_event_response(sealed_data, [
99102
DecryptionKey(self.invalid_key, DecryptionAlgorithm['Aes256Gcm']),
100103
DecryptionKey(self.valid_key, DecryptionAlgorithm['Aes256Gcm']),
101104
])

0 commit comments

Comments
 (0)