test(auth): fix test isolation for verification tests
Clear pre-existing verified domains at the start of each test that expects an unverified domain to ensure proper test isolation. This prevents test failures caused by verified domains persisting from earlier tests in the test session. Fixes: - test_dns_failure_shows_instructions - test_email_discovery_failure_shows_instructions - test_full_flow_new_domain - test_unverified_domain_never_sees_consent_directly 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -292,8 +292,18 @@ class TestDNSFailureHandling:
|
|||||||
self, configured_app, valid_auth_params
|
self, configured_app, valid_auth_params
|
||||||
):
|
):
|
||||||
"""Test that DNS verification failure shows helpful instructions."""
|
"""Test that DNS verification failure shows helpful instructions."""
|
||||||
app, _ = configured_app
|
app, db_path = configured_app
|
||||||
from gondulf.dependencies import get_verification_service, get_happ_parser
|
from gondulf.dependencies import get_verification_service, get_happ_parser, get_database
|
||||||
|
from gondulf.database.connection import Database
|
||||||
|
from sqlalchemy import text
|
||||||
|
|
||||||
|
# Clear any pre-existing verified domain to ensure test isolation
|
||||||
|
db = Database(f"sqlite:///{db_path}")
|
||||||
|
db.initialize()
|
||||||
|
with db.get_engine().begin() as conn:
|
||||||
|
conn.execute(text("DELETE FROM domains WHERE domain = :domain"), {"domain": "user.example.com"})
|
||||||
|
|
||||||
|
app.dependency_overrides[get_database] = lambda: db
|
||||||
|
|
||||||
mock_service = create_mock_verification_service(start_success=False, start_error="dns_verification_failed")
|
mock_service = create_mock_verification_service(start_success=False, start_error="dns_verification_failed")
|
||||||
mock_parser = create_mock_happ_parser()
|
mock_parser = create_mock_happ_parser()
|
||||||
@@ -321,8 +331,18 @@ class TestEmailFailureHandling:
|
|||||||
self, configured_app, valid_auth_params
|
self, configured_app, valid_auth_params
|
||||||
):
|
):
|
||||||
"""Test that email discovery failure shows helpful instructions."""
|
"""Test that email discovery failure shows helpful instructions."""
|
||||||
app, _ = configured_app
|
app, db_path = configured_app
|
||||||
from gondulf.dependencies import get_verification_service, get_happ_parser
|
from gondulf.dependencies import get_verification_service, get_happ_parser, get_database
|
||||||
|
from gondulf.database.connection import Database
|
||||||
|
from sqlalchemy import text
|
||||||
|
|
||||||
|
# Clear any pre-existing verified domain to ensure test isolation
|
||||||
|
db = Database(f"sqlite:///{db_path}")
|
||||||
|
db.initialize()
|
||||||
|
with db.get_engine().begin() as conn:
|
||||||
|
conn.execute(text("DELETE FROM domains WHERE domain = :domain"), {"domain": "user.example.com"})
|
||||||
|
|
||||||
|
app.dependency_overrides[get_database] = lambda: db
|
||||||
|
|
||||||
mock_service = create_mock_verification_service(start_success=False, start_error="email_discovery_failed")
|
mock_service = create_mock_verification_service(start_success=False, start_error="email_discovery_failed")
|
||||||
mock_parser = create_mock_happ_parser()
|
mock_parser = create_mock_happ_parser()
|
||||||
@@ -348,8 +368,18 @@ class TestFullVerificationFlow:
|
|||||||
self, configured_app, valid_auth_params
|
self, configured_app, valid_auth_params
|
||||||
):
|
):
|
||||||
"""Test complete flow: unverified domain -> verify code -> consent."""
|
"""Test complete flow: unverified domain -> verify code -> consent."""
|
||||||
app, _ = configured_app
|
app, db_path = configured_app
|
||||||
from gondulf.dependencies import get_verification_service, get_happ_parser
|
from gondulf.dependencies import get_verification_service, get_happ_parser, get_database
|
||||||
|
from gondulf.database.connection import Database
|
||||||
|
from sqlalchemy import text
|
||||||
|
|
||||||
|
# Clear any pre-existing verified domain to ensure test isolation
|
||||||
|
db = Database(f"sqlite:///{db_path}")
|
||||||
|
db.initialize()
|
||||||
|
with db.get_engine().begin() as conn:
|
||||||
|
conn.execute(text("DELETE FROM domains WHERE domain = :domain"), {"domain": "user.example.com"})
|
||||||
|
|
||||||
|
app.dependency_overrides[get_database] = lambda: db
|
||||||
|
|
||||||
mock_service = create_mock_verification_service(start_success=True, verify_success=True)
|
mock_service = create_mock_verification_service(start_success=True, verify_success=True)
|
||||||
mock_parser = create_mock_happ_parser()
|
mock_parser = create_mock_happ_parser()
|
||||||
@@ -444,8 +474,18 @@ class TestSecurityRequirements:
|
|||||||
self, configured_app, valid_auth_params
|
self, configured_app, valid_auth_params
|
||||||
):
|
):
|
||||||
"""Critical: Unverified domains must NEVER see consent page directly."""
|
"""Critical: Unverified domains must NEVER see consent page directly."""
|
||||||
app, _ = configured_app
|
app, db_path = configured_app
|
||||||
from gondulf.dependencies import get_verification_service, get_happ_parser
|
from gondulf.dependencies import get_verification_service, get_happ_parser, get_database
|
||||||
|
from gondulf.database.connection import Database
|
||||||
|
from sqlalchemy import text
|
||||||
|
|
||||||
|
# Clear any pre-existing verified domain to ensure test isolation
|
||||||
|
db = Database(f"sqlite:///{db_path}")
|
||||||
|
db.initialize()
|
||||||
|
with db.get_engine().begin() as conn:
|
||||||
|
conn.execute(text("DELETE FROM domains WHERE domain = :domain"), {"domain": "user.example.com"})
|
||||||
|
|
||||||
|
app.dependency_overrides[get_database] = lambda: db
|
||||||
|
|
||||||
mock_service = create_mock_verification_service(start_success=True)
|
mock_service = create_mock_verification_service(start_success=True)
|
||||||
mock_parser = create_mock_happ_parser()
|
mock_parser = create_mock_happ_parser()
|
||||||
|
|||||||
Reference in New Issue
Block a user