Skip to content

Guard agains non bools in check_revoked + tests #128

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions firebase_admin/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ def verify_id_token(id_token, app=None, check_revoked=False):
initialized with a credentials.Certificate.
AuthError: If check_revoked is requested and the token was revoked.
"""
if not isinstance(check_revoked, bool):
# guard against accidental wrong assignment.
raise ValueError('Illegal check_revoked argument. Argument must be of type '
' bool, but given "{0}".'.format(type(app)))
token_generator = _get_auth_service(app).token_generator
verified_claims = token_generator.verify_id_token(id_token)
if check_revoked:
Expand Down
5 changes: 5 additions & 0 deletions tests/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,11 @@ def test_revoked_token_check_revoked(self, user_mgt_app, id_token):
assert excinfo.value.code == 'ID_TOKEN_REVOKED'
assert str(excinfo.value) == 'The Firebase ID token has been revoked.'

@pytest.mark.parametrize('arg', INVALID_BOOLS)
def test_invalid_check_revoked(self, arg):
with pytest.raises(ValueError):
auth.verify_id_token("id_token", check_revoked=arg)

@pytest.mark.parametrize('id_token', valid_tokens.values(), ids=list(valid_tokens))
def test_revoked_token_do_not_check_revoked(self, user_mgt_app, id_token):
_instrument_user_manager(user_mgt_app, 200, MOCK_GET_USER_REVOKED_TOKENS_RESPONSE)
Expand Down