primary email change functionality
Build LinkLog Development Image / development-image (push) Successful in 12s
Build LinkLog Development Image / development-image (push) Successful in 12s
This commit is contained in:
@@ -10,7 +10,7 @@ def test_database_migrations_are_versioned_and_idempotent():
|
||||
connection = sqlite3.connect(':memory:')
|
||||
|
||||
apply_migrations(connection)
|
||||
assert get_schema_version(connection) == 11
|
||||
assert get_schema_version(connection) == 13
|
||||
tables = {
|
||||
row[0]
|
||||
for row in connection.execute(
|
||||
@@ -27,6 +27,6 @@ def test_database_migrations_are_versioned_and_idempotent():
|
||||
assert set(DEFAULT_TAGS) <= seeded_tags
|
||||
|
||||
apply_migrations(connection)
|
||||
assert get_schema_version(connection) == 11
|
||||
assert get_schema_version(connection) == 13
|
||||
|
||||
connection.close()
|
||||
@@ -2,8 +2,10 @@
|
||||
## SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from fastapi.testclient import TestClient
|
||||
from unittest.mock import patch
|
||||
|
||||
from backend.app.main import app
|
||||
from backend.app.database import get_connection
|
||||
from backend.app.services.otp_service import current_code
|
||||
|
||||
|
||||
@@ -45,6 +47,7 @@ def test_user_config_api_and_profile_page():
|
||||
assert '<a id="auth-username" class="user-name" href="/">' in page_response.text
|
||||
assert 'id="auth-avatar"' not in page_response.text
|
||||
assert 'name="new_password_confirmation"' in page_response.text
|
||||
assert 'id="additional-email-form"' in page_response.text
|
||||
|
||||
bob_login = client.post('/api/auth/login', json={
|
||||
'email': 'bob@example.com',
|
||||
@@ -104,3 +107,38 @@ def test_user_can_enable_and_use_otp():
|
||||
})
|
||||
assert disabled.status_code == 200
|
||||
assert disabled.json()['enabled'] is False
|
||||
|
||||
|
||||
def test_verified_alternative_can_become_primary():
|
||||
login = client.post('/api/auth/login', json={'email': 'alice@example.com', 'password': 'secret123'}).json()
|
||||
headers = {'Authorization': f"Bearer {login['access_token']}"}
|
||||
with get_connection() as conn:
|
||||
address = conn.execute(
|
||||
'INSERT INTO user_email_addresses (id, user_id, email, verified) VALUES (?, ?, ?, 1) RETURNING id',
|
||||
('alternative-test', 'user-1', 'alice-alternative@example.com'),
|
||||
).fetchone()
|
||||
conn.commit()
|
||||
promoted = client.post(f"/api/user/emails/{address['id']}/make-primary", headers=headers)
|
||||
assert promoted.status_code == 200
|
||||
assert client.post('/api/auth/login', json={'email': 'alice-alternative@example.com', 'password': 'secret123'}).status_code == 200
|
||||
assert client.post('/api/auth/login', json={'email': 'alice@example.com', 'password': 'secret123'}).status_code == 200
|
||||
with get_connection() as conn:
|
||||
conn.execute('DELETE FROM user_email_addresses WHERE email IN (?, ?)', ('alice@example.com', 'alice-alternative@example.com'))
|
||||
conn.execute('UPDATE users SET email = ?, email_verified = 1 WHERE id = ?', ('alice@example.com', 'user-1'))
|
||||
conn.commit()
|
||||
|
||||
|
||||
def test_unverified_alternative_cannot_become_primary():
|
||||
login = client.post('/api/auth/login', json={'email': 'alice@example.com', 'password': 'secret123'}).json()
|
||||
headers = {'Authorization': f"Bearer {login['access_token']}"}
|
||||
with get_connection() as conn:
|
||||
address = conn.execute(
|
||||
'INSERT INTO user_email_addresses (id, user_id, email, verified) VALUES (?, ?, ?, 0) RETURNING id',
|
||||
('unverified-alternative-test', 'user-1', 'alice-unverified@example.com'),
|
||||
).fetchone()
|
||||
conn.commit()
|
||||
rejected = client.post(f"/api/user/emails/{address['id']}/make-primary", headers=headers)
|
||||
assert rejected.status_code == 400
|
||||
with get_connection() as conn:
|
||||
conn.execute('DELETE FROM user_email_addresses WHERE id = ?', (address['id'],))
|
||||
conn.commit()
|
||||
|
||||
Reference in New Issue
Block a user