-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dea2660
commit 80632f1
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import sys | ||
|
||
import bcrypt | ||
import pytest | ||
|
||
from fastagency.logging import get_logger | ||
|
||
logger = get_logger(__name__) | ||
|
||
if sys.version_info >= (3, 10): | ||
from fastagency.ui.mesop.auth.basic_auth import BasicAuth | ||
|
||
class TestBasicAuthMesopHomePage: | ||
@pytest.fixture | ||
def basic_auth(self): | ||
"""Fixture to create a BasicAuth instance with test users.""" | ||
# Create test users with hashed passwords | ||
test_password = "test_password" | ||
hashed_password = bcrypt.hashpw( | ||
test_password.encode("utf-8"), bcrypt.gensalt() | ||
).decode("utf-8") | ||
|
||
allowed_users = { | ||
"test_user": hashed_password, | ||
"another_user": hashed_password, | ||
} | ||
|
||
return BasicAuth(allowed_users) | ||
|
||
def test_is_authorized_valid_credentials(self, basic_auth): | ||
"""Test authorization with valid username and password.""" | ||
assert basic_auth.is_authorized("test_user", "test_password") is True | ||
|
||
def test_is_authorized_invalid_username(self, basic_auth): | ||
"""Test authorization with invalid username.""" | ||
assert basic_auth.is_authorized("invalid_user", "test_password") is False |