From 913952ae276bf969e5ee1e6621ea78d836a1d851 Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Fri, 1 Jun 2018 17:06:56 -0400 Subject: [PATCH] Make signed grant tests stable across runs This was preventing us from running tests in parallel, since the names were changing --- auth/test/test_signedgrant.py | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/auth/test/test_signedgrant.py b/auth/test/test_signedgrant.py index 8eacbfac6..e200f0bf1 100644 --- a/auth/test/test_signedgrant.py +++ b/auth/test/test_signedgrant.py @@ -5,16 +5,28 @@ from auth.validateresult import AuthKind, ValidateResult @pytest.mark.parametrize('header, expected_result', [ - ('', ValidateResult(AuthKind.signed_grant, missing=True)), - ('somerandomtoken', ValidateResult(AuthKind.signed_grant, missing=True)), - ('token somerandomtoken', ValidateResult(AuthKind.signed_grant, missing=True)), - ('token ' + SIGNATURE_PREFIX + 'foo', - ValidateResult(AuthKind.signed_grant, error_message='Signed grant could not be validated')), - ('token ' + generate_signed_token({ - 'a': 'b'}, {'c': 'd'}), ValidateResult(AuthKind.signed_grant, signed_data={ - 'grants': { - 'a': 'b'}, - 'user_context': { - 'c': 'd'}})),]) + pytest.param('', ValidateResult(AuthKind.signed_grant, missing=True), id='Missing'), + pytest.param('somerandomtoken', ValidateResult(AuthKind.signed_grant, missing=True), + id='Invalid header'), + pytest.param('token somerandomtoken', ValidateResult(AuthKind.signed_grant, missing=True), + id='Random Token'), + pytest.param('token ' + SIGNATURE_PREFIX + 'foo', + ValidateResult(AuthKind.signed_grant, + error_message='Signed grant could not be validated'), + id='Invalid token'), +]) def test_token(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