Skip to content

Commit 0957eed

Browse files
committed
replace the broad exceptions.FirebaseError assertion with more specific error types
1 parent 5ce0edb commit 0957eed

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

‎tests/test_app_check.py‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,8 +353,26 @@ def test_verify_token_with_consume_true_backend_error(self, mocker):
353353
req_exc = requests.exceptions.RequestException("Backend error")
354354
mocker.patch.object(app_check_service._http_client, "body", side_effect=req_exc)
355355

356-
with pytest.raises(exceptions.FirebaseError):
356+
with pytest.raises(exceptions.UnknownError) as excinfo:
357+
app_check.verify_token("encoded", app=app, consume=True)
358+
assert "Unknown error while making a remote service call" in str(excinfo.value)
359+
360+
def test_verify_token_with_consume_true_http_error(self, mocker):
361+
mocker.patch("jwt.decode", return_value=JWT_PAYLOAD_SAMPLE)
362+
mocker.patch("jwt.PyJWKClient.get_signing_key_from_jwt", return_value=PyJWK(signing_key))
363+
mocker.patch("jwt.get_unverified_header", return_value=JWT_PAYLOAD_SAMPLE.get("headers"))
364+
app = firebase_admin.get_app()
365+
app_check_service = app_check._get_app_check_service(app)
366+
367+
response = requests.Response()
368+
response.status_code = 403
369+
response._content = b'{"error": {"status": "PERMISSION_DENIED", "message": "Permission denied."}}'
370+
http_exc = requests.exceptions.HTTPError(response=response)
371+
mocker.patch.object(app_check_service._http_client, "body", side_effect=http_exc)
372+
373+
with pytest.raises(exceptions.PermissionDeniedError) as excinfo:
357374
app_check.verify_token("encoded", app=app, consume=True)
375+
assert "Permission denied." in str(excinfo.value)
358376

359377
@pytest.mark.parametrize('malformed_body', ['string_response', [1, 2], 123, None])
360378
def test_verify_token_with_consume_true_malformed_response_raises_error(

0 commit comments

Comments
 (0)