You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.5 KiB
46 lines
1.5 KiB
import pytest |
|
from unittest.mock import patch, MagicMock |
|
from nicegui.testing import User |
|
from app import main |
|
|
|
# pylint: disable=missing-function-docstring |
|
|
|
|
|
@pytest.mark.module_under_test(main) |
|
async def test_login_redirect_to_oidc(user: User) -> None: |
|
"""Test that login page redirects to OIDC provider""" |
|
await user.open('/') |
|
await user.should_see('Log in with OIDC') |
|
|
|
|
|
@pytest.mark.module_under_test(main) |
|
async def test_subpage_access_redirect(user: User) -> None: |
|
"""Test that protected pages redirect to login""" |
|
await user.open('/subpage') |
|
await user.should_see('Authentication Required') |
|
|
|
|
|
@pytest.mark.module_under_test(main) |
|
@patch('auth.oidc.oidc_config.exchange_code_for_tokens') |
|
@patch('auth.oidc.oidc_config.validate_token') |
|
async def test_oidc_callback_success(mock_validate, mock_exchange, user: User) -> None: |
|
"""Test successful OIDC callback""" |
|
# Mock successful token exchange |
|
mock_exchange.return_value = { |
|
'access_token': 'fake_access_token', |
|
'id_token': 'fake_id_token', |
|
'refresh_token': 'fake_refresh_token', |
|
'expires_in': 3600 |
|
} |
|
|
|
# Mock successful token validation |
|
mock_validate.return_value = { |
|
'sub': 'user123', |
|
'preferred_username': 'testuser', |
|
'email': 'test@example.com', |
|
'exp': 9999999999 # Far future |
|
} |
|
|
|
# Simulate OIDC callback |
|
await user.open('/auth/callback?code=test_code&state=test_state') |
|
# Note: This test would need to be adapted based on your OIDC flow
|
|
|