first commit

This commit is contained in:
Matteo Benedetto
2025-06-10 23:50:06 +02:00
commit 142f3aff25
25 changed files with 1018 additions and 0 deletions
View File
+1
View File
@@ -0,0 +1 @@
pytest_plugins = ['nicegui.testing.plugin']
+46
View File
@@ -0,0 +1,46 @@
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