Login now based on email
Build LinkLog Development Image / development-image (push) Successful in 10s
Build LinkLog Development Image / development-image (push) Successful in 10s
This commit is contained in:
@@ -22,7 +22,7 @@ client = TestClient(app)
|
||||
|
||||
def login_headers(username='alice'):
|
||||
token = client.post('/api/auth/login', json={
|
||||
'username': username,
|
||||
'email': 'alice@example.com' if username == 'alice' else f'{username}@example.com',
|
||||
'password': 'secret123',
|
||||
}).json()['access_token']
|
||||
return {'Authorization': f'Bearer {token}'}
|
||||
@@ -31,7 +31,7 @@ def login_headers(username='alice'):
|
||||
def test_login_returns_token():
|
||||
assert app.version == '0.1.0'
|
||||
response = client.post('/api/auth/login', json={
|
||||
'username': 'alice',
|
||||
'email': 'alice@example.com',
|
||||
'password': 'secret123',
|
||||
})
|
||||
assert response.status_code == 200
|
||||
@@ -44,7 +44,7 @@ def test_login_returns_token():
|
||||
assert admin_session.json()['is_admin'] is True
|
||||
|
||||
user_token = client.post('/api/auth/login', json={
|
||||
'username': 'bob',
|
||||
'email': 'bob@example.com',
|
||||
'password': 'secret123',
|
||||
}).json()['access_token']
|
||||
user_session = client.get('/api/auth/me', params={'token': user_token})
|
||||
@@ -71,7 +71,7 @@ def test_password_hashes_are_salted_and_legacy_hashes_upgrade_on_login():
|
||||
(str(uuid4()), legacy_username, f'{legacy_username}@example.com', legacy_hash),
|
||||
)
|
||||
conn.commit()
|
||||
response = client.post('/api/auth/login', json={'username': legacy_username, 'password': 'legacy-password'})
|
||||
response = client.post('/api/auth/login', json={'email': legacy_username + '@example.com', 'password': 'legacy-password'})
|
||||
assert response.status_code == 200
|
||||
with get_connection() as conn:
|
||||
upgraded = conn.execute('SELECT password_hash FROM users WHERE username = ?', (legacy_username,)).fetchone()['password_hash']
|
||||
@@ -203,7 +203,7 @@ def test_new_user_must_verify_email_before_login():
|
||||
assert created.status_code == 201
|
||||
assert created.json()['email_verified'] is False
|
||||
|
||||
login = client.post('/api/auth/login', json={'username': username, 'password': 'secret123'})
|
||||
login = client.post('/api/auth/login', json={'email': f'{username}@example.com', 'password': 'secret123'})
|
||||
assert login.status_code == 403
|
||||
assert login.json()['detail'] == 'Email address is not verified'
|
||||
|
||||
@@ -223,7 +223,7 @@ def test_email_verification_link_enables_login():
|
||||
|
||||
verified = client.get('/api/auth/verify-email', params={'token': verification_token})
|
||||
assert verified.status_code == 200
|
||||
assert client.post('/api/auth/login', json={'username': username, 'password': 'secret123'}).status_code == 200
|
||||
assert client.post('/api/auth/login', json={'email': f'{username}@example.com', 'password': 'secret123'}).status_code == 200
|
||||
assert client.get('/api/auth/verify-email', params={'token': verification_token}).status_code == 400
|
||||
|
||||
|
||||
@@ -242,7 +242,7 @@ def test_mistyped_password_sends_reset_link_without_changing_login_error():
|
||||
with patch('backend.app.api.auth.smtp_configured', return_value=True), \
|
||||
patch('backend.app.api.auth.create_reset_token', return_value='reset-token') as create_token, \
|
||||
patch('backend.app.api.auth.send_password_reset_email') as send_email:
|
||||
response = client.post('/api/auth/login', json={'username': username, 'password': 'wrong-password'})
|
||||
response = client.post('/api/auth/login', json={'email': f'{username}@example.com', 'password': 'wrong-password'})
|
||||
|
||||
assert response.status_code == 401
|
||||
assert response.json()['detail'] == 'Invalid username or password'
|
||||
@@ -267,7 +267,7 @@ def test_password_reset_is_single_use_and_revokes_sessions():
|
||||
reset = client.post('/api/auth/reset-password', json={'token': token, 'password': 'new-secret123'})
|
||||
assert reset.status_code == 200
|
||||
assert client.post('/api/auth/reset-password', json={'token': token, 'password': 'another-secret'}).status_code == 400
|
||||
assert client.post('/api/auth/login', json={'username': username, 'password': 'new-secret123'}).status_code == 200
|
||||
assert client.post('/api/auth/login', json={'email': f'{username}@example.com', 'password': 'new-secret123'}).status_code == 200
|
||||
|
||||
|
||||
def test_admin_can_remove_user_with_owned_data():
|
||||
|
||||
Reference in New Issue
Block a user