|
7 | 7 | NotFoundError, |
8 | 8 | RateLimitError, |
9 | 9 | ShadeError, |
| 10 | + SignatureVerificationError, |
10 | 11 | ) |
11 | 12 | from shade.errors import raise_for_invalid_request |
12 | 13 |
|
@@ -69,6 +70,7 @@ def test_package_root_exports_error_classes(): |
69 | 70 | assert shade.NetworkError is NetworkError |
70 | 71 | assert shade.NotFoundError is NotFoundError |
71 | 72 | assert shade.RateLimitError is RateLimitError |
| 73 | + assert shade.SignatureVerificationError is SignatureVerificationError |
72 | 74 |
|
73 | 75 |
|
74 | 76 | def test_invalid_request_error_parses_param_from_body(): |
@@ -211,3 +213,40 @@ def test_not_found_error_invalid_json_body(): |
211 | 213 |
|
212 | 214 | assert error.resource_type is None |
213 | 215 | assert error.resource_id is None |
| 216 | + |
| 217 | + |
| 218 | +def test_signature_verification_error_is_shade_error(): |
| 219 | + error = SignatureVerificationError("bad signature", header="t=1,v1=abc") |
| 220 | + |
| 221 | + assert isinstance(error, ShadeError) |
| 222 | + assert str(error) == "bad signature" |
| 223 | + assert error.header == "t=1,v1=abc" |
| 224 | + |
| 225 | + |
| 226 | +def test_signature_verification_error_header_optional(): |
| 227 | + error = SignatureVerificationError("bad signature") |
| 228 | + |
| 229 | + assert error.header is None |
| 230 | + |
| 231 | + |
| 232 | +def test_signature_verification_error_from_mismatch_stores_header(): |
| 233 | + error = SignatureVerificationError.from_mismatch(header="t=1,v1=deadbeef") |
| 234 | + |
| 235 | + assert isinstance(error, ShadeError) |
| 236 | + assert error.header == "t=1,v1=deadbeef" |
| 237 | + |
| 238 | + |
| 239 | +def test_signature_verification_error_from_mismatch_explains_causes(): |
| 240 | + error = SignatureVerificationError.from_mismatch(header="t=1,v1=deadbeef") |
| 241 | + |
| 242 | + message = str(error) |
| 243 | + assert "secret" in message |
| 244 | + assert "payload" in message |
| 245 | + |
| 246 | + |
| 247 | +def test_signature_verification_error_never_includes_expected_signature(): |
| 248 | + expected_signature = "supersecrethmacvalue" |
| 249 | + error = SignatureVerificationError.from_mismatch(header="t=1,v1=deadbeef") |
| 250 | + |
| 251 | + assert expected_signature not in str(error) |
| 252 | + assert not hasattr(error, "expected_signature") |
0 commit comments