mirror of
https://github.com/quay/quay.git
synced 2026-01-27 18:42:52 +03:00
* chore: drop deprecated tables and remove unused code * isort imports * migration: check for table existence before drop
50 lines
1.3 KiB
Python
50 lines
1.3 KiB
Python
import pytest
|
|
|
|
from auth.signedgrant import (
|
|
SIGNATURE_PREFIX,
|
|
generate_signed_token,
|
|
validate_signed_grant,
|
|
)
|
|
from auth.validateresult import AuthKind, ValidateResult
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"header, expected_result",
|
|
[
|
|
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
|