aurweb.auth: add user credentials and matcher functions

This clones the behavior already present in the PHP implementation,
but it uses a global dict with credential constant keys to
validation functions to determine if a given user has a credential.

Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
Kevin Morris 2021-01-25 16:30:47 -08:00
parent 670f711b59
commit 07d5907ecd
4 changed files with 154 additions and 1 deletions

View file

@ -4,8 +4,8 @@ import pytest
from starlette.authentication import AuthenticationError
from aurweb.auth import BasicAuthBackend, has_credential
from aurweb.db import query
from aurweb.auth import BasicAuthBackend
from aurweb.models.account_type import AccountType
from aurweb.testing import setup_test_db
from aurweb.testing.models import make_session, make_user
@ -78,3 +78,8 @@ async def test_basic_auth_backend():
LastUpdateTS=now_ts + 5)
_, result = await backend.authenticate(request)
assert result == user
def test_has_fake_credential_fails():
# Fake credential 666 does not exist.
assert not has_credential(user, 666)