Make signed grant tests stable across runs

This was preventing us from running tests in parallel, since the names were changing
This commit is contained in:
Joseph Schorr 2018-06-01 17:06:56 -04:00
parent 65f08c25cf
commit 913952ae27

View file

@ -5,16 +5,28 @@ from auth.validateresult import AuthKind, ValidateResult
@pytest.mark.parametrize('header, expected_result', [ @pytest.mark.parametrize('header, expected_result', [
('', ValidateResult(AuthKind.signed_grant, missing=True)), pytest.param('', ValidateResult(AuthKind.signed_grant, missing=True), id='Missing'),
('somerandomtoken', ValidateResult(AuthKind.signed_grant, missing=True)), pytest.param('somerandomtoken', ValidateResult(AuthKind.signed_grant, missing=True),
('token somerandomtoken', ValidateResult(AuthKind.signed_grant, missing=True)), id='Invalid header'),
('token ' + SIGNATURE_PREFIX + 'foo', pytest.param('token somerandomtoken', ValidateResult(AuthKind.signed_grant, missing=True),
ValidateResult(AuthKind.signed_grant, error_message='Signed grant could not be validated')), id='Random Token'),
('token ' + generate_signed_token({ pytest.param('token ' + SIGNATURE_PREFIX + 'foo',
'a': 'b'}, {'c': 'd'}), ValidateResult(AuthKind.signed_grant, signed_data={ ValidateResult(AuthKind.signed_grant,
'grants': { error_message='Signed grant could not be validated'),
'a': 'b'}, id='Invalid token'),
'user_context': { ])
'c': 'd'}})),])
def test_token(header, expected_result): def test_token(header, expected_result):
assert validate_signed_grant(header) == expected_result assert validate_signed_grant(header) == expected_result
def test_valid_grant():
header = 'token ' + generate_signed_token({'a': 'b'}, {'c': 'd'})
expected = ValidateResult(AuthKind.signed_grant, signed_data={
'grants': {
'a': 'b',
},
'user_context': {
'c': 'd'
},
})
assert validate_signed_grant(header) == expected