Add labels to test cases for invalid JWTs

This commit is contained in:
Brad Ison 2018-02-08 15:54:54 -05:00
parent 5da8744ddf
commit d1ba2dcfc3

View file

@ -110,30 +110,31 @@ def test_token_with_access(access, initialized_db):
@pytest.mark.parametrize('token', [ @pytest.mark.parametrize('token', [
(_token( pytest.param(_token(
_token_data(access=[{ _token_data(access=[{
'toipe': 'repository', 'toipe': 'repository',
'namesies': 'somens/somerepo', 'namesies': 'somens/somerepo',
'akshuns': ['pull', 'push', '*']}]))), 'akshuns': ['pull', 'push', '*']}])), id='bad access'),
(_token(_token_data(audience='someotherapp'))), pytest.param(_token(_token_data(audience='someotherapp')), id='bad aud'),
(_token(_delete_field(_token_data(), 'aud'))), pytest.param(_token(_delete_field(_token_data(), 'aud')), id='no aud'),
(_token(_token_data(nbf=int(time.time()) + 600))), pytest.param(_token(_token_data(nbf=int(time.time()) + 600)), id='future nbf'),
(_token(_delete_field(_token_data(), 'nbf'))), pytest.param(_token(_delete_field(_token_data(), 'nbf')), id='no nbf'),
(_token(_token_data(iat=int(time.time()) + 600))), pytest.param(_token(_token_data(iat=int(time.time()) + 600)), id='future iat'),
(_token(_delete_field(_token_data(), 'iat'))), pytest.param(_token(_delete_field(_token_data(), 'iat')), id='no iat'),
(_token(_token_data(exp=int(time.time()) + MAX_SIGNED_S * 2))), pytest.param(_token(_token_data(exp=int(time.time()) + MAX_SIGNED_S * 2)), id='exp too long'),
(_token(_token_data(exp=int(time.time()) - 60))), pytest.param(_token(_token_data(exp=int(time.time()) - 60)), id='expired'),
(_token(_delete_field(_token_data(), 'exp'))), pytest.param(_token(_delete_field(_token_data(), 'exp')), id='no exp'),
(_token(_delete_field(_token_data(), 'sub'))), pytest.param(_token(_delete_field(_token_data(), 'sub')), id='no sub'),
(_token(_token_data(iss='badissuer'))), pytest.param(_token(_token_data(iss='badissuer')), id='bad iss'),
(_token(_delete_field(_token_data(), 'iss'))), pytest.param(_token(_delete_field(_token_data(), 'iss')), id='no iss'),
(_token(_token_data(), skip_header=True)), pytest.param(_token(_token_data(), skip_header=True), id='no header'),
(_token(_token_data(), key_id='someunknownkey')), pytest.param(_token(_token_data(), key_id='someunknownkey'), id='bad key'),
(_token(_token_data(), key_id='kid7')), pytest.param(_token(_token_data(), key_id='kid7'), id='bad key :: kid7'),
(_token(_token_data(), alg='none', private_key=None)), pytest.param(_token(_token_data(), alg='none', private_key=None), id='none alg'),
('some random token'), pytest.param('some random token', id='random token'),
('Bearer: sometokenhere'), pytest.param('Bearer: sometokenhere', id='extra bearer'),
('\nBearer: dGVzdA'),]) pytest.param('\nBearer: dGVzdA', id='leading newline'),
])
def test_invalid_jwt(token, initialized_db): def test_invalid_jwt(token, initialized_db):
with pytest.raises(InvalidJWTException): with pytest.raises(InvalidJWTException):
_parse_token(token) _parse_token(token)