feat(auth): add oauth_identities table for Google/Microsoft sign-in
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
39
backend/tests/test_oauth_identity_model.py
Normal file
39
backend/tests/test_oauth_identity_model.py
Normal file
@@ -0,0 +1,39 @@
|
||||
import uuid
|
||||
|
||||
import pytest
|
||||
from sqlalchemy import select
|
||||
|
||||
from app.models.oauth_identity import OAuthIdentity
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_oauth_identity_unique_provider_subject(test_db, test_user):
|
||||
"""Two rows with same provider+subject should violate uniqueness."""
|
||||
user_id = uuid.UUID(test_user["user_data"]["id"])
|
||||
|
||||
row1 = OAuthIdentity(
|
||||
user_id=user_id,
|
||||
provider="google",
|
||||
provider_subject="abc-123",
|
||||
provider_email_at_link="alex@acmemsp.com",
|
||||
)
|
||||
test_db.add(row1)
|
||||
await test_db.commit()
|
||||
|
||||
row2 = OAuthIdentity(
|
||||
user_id=user_id,
|
||||
provider="google",
|
||||
provider_subject="abc-123",
|
||||
provider_email_at_link="alex@acmemsp.com",
|
||||
)
|
||||
test_db.add(row2)
|
||||
with pytest.raises(Exception): # IntegrityError
|
||||
await test_db.commit()
|
||||
await test_db.rollback()
|
||||
|
||||
rows = (
|
||||
await test_db.execute(
|
||||
select(OAuthIdentity).where(OAuthIdentity.user_id == user_id)
|
||||
)
|
||||
).scalars().all()
|
||||
assert len(rows) == 1
|
||||
Reference in New Issue
Block a user