From c7c2e4d522b8bb9cda90645db7ddad2d24937403 Mon Sep 17 00:00:00 2001 From: Samuel Gaist Date: Sat, 7 Oct 2023 23:06:43 +0200 Subject: [PATCH] test: add authenticate method check --- .../tests/test_multiauthenticator.py | 25 +++++++++++++++++-- pyproject.toml | 2 +- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/multiauthenticator/tests/test_multiauthenticator.py b/multiauthenticator/tests/test_multiauthenticator.py index 83e28de..5ec313a 100644 --- a/multiauthenticator/tests/test_multiauthenticator.py +++ b/multiauthenticator/tests/test_multiauthenticator.py @@ -4,6 +4,7 @@ """Test module for the MultiAuthenticator class""" import pytest +from jupyterhub.auth import DummyAuthenticator from jupyterhub.auth import PAMAuthenticator from oauthenticator.github import GitHubOAuthenticator from oauthenticator.gitlab import GitLabOAuthenticator @@ -205,8 +206,28 @@ def test_username_prefix(): multi_authenticator = MultiAuthenticator() assert len(multi_authenticator._authenticators) == 2 - assert multi_authenticator._authenticators[0].username_prefix == "GitLab:" - assert multi_authenticator._authenticators[1].username_prefix == "PAM:" + assert ( + multi_authenticator._authenticators[0].username_prefix + == f"GitLab{PREFIX_SEPARATOR}" + ) + assert ( + multi_authenticator._authenticators[1].username_prefix + == f"PAM{PREFIX_SEPARATOR}" + ) + + +@pytest.mark.asyncio +async def test_authenticated_username_prefix(): + MultiAuthenticator.authenticators = [ + (DummyAuthenticator, "/pam", {"service_name": "Dummy"}), + ] + + multi_authenticator = MultiAuthenticator() + assert len(multi_authenticator._authenticators) == 1 + username = await multi_authenticator._authenticators[0].authenticate( + None, {"username": "test"} + ) + assert username == f"Dummy{PREFIX_SEPARATOR}test" def test_username_prefix_checks(): diff --git a/pyproject.toml b/pyproject.toml index 249b890..86542b7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -28,7 +28,7 @@ dependencies = [ ] [project.optional-dependencies] -test = ["pytest", "pytest-cov"] +test = ["pytest", "pytest-cov", "pytest-asyncio"] dev = ["pre-commit", "jupyterhub-multiauthenticator[test]"] [tool.setuptools]