Skip to content

Commit 432f4e5

Browse files
authored
Guard agains non boolean values in check_revoked + tests (firebase#128)
* Guard agains non bools in check_revoked + tests * lint * whitespace
1 parent d7e8494 commit 432f4e5

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

firebase_admin/auth.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ def verify_id_token(id_token, app=None, check_revoked=False):
9696
initialized with a credentials.Certificate.
9797
AuthError: If check_revoked is requested and the token was revoked.
9898
"""
99+
if not isinstance(check_revoked, bool):
100+
# guard against accidental wrong assignment.
101+
raise ValueError('Illegal check_revoked argument. Argument must be of type '
102+
' bool, but given "{0}".'.format(type(app)))
99103
token_generator = _get_auth_service(app).token_generator
100104
verified_claims = token_generator.verify_id_token(id_token)
101105
if check_revoked:

tests/test_auth.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,11 @@ def test_revoked_token_check_revoked(self, user_mgt_app, id_token):
267267
assert excinfo.value.code == 'ID_TOKEN_REVOKED'
268268
assert str(excinfo.value) == 'The Firebase ID token has been revoked.'
269269

270+
@pytest.mark.parametrize('arg', INVALID_BOOLS)
271+
def test_invalid_check_revoked(self, arg):
272+
with pytest.raises(ValueError):
273+
auth.verify_id_token("id_token", check_revoked=arg)
274+
270275
@pytest.mark.parametrize('id_token', valid_tokens.values(), ids=list(valid_tokens))
271276
def test_revoked_token_do_not_check_revoked(self, user_mgt_app, id_token):
272277
_instrument_user_manager(user_mgt_app, 200, MOCK_GET_USER_REVOKED_TOKENS_RESPONSE)

0 commit comments

Comments
 (0)