36 lines
1.2 KiB
Python
36 lines
1.2 KiB
Python
import pytest
|
|
|
|
from mock import patch
|
|
|
|
from data.database import model
|
|
from data.users.federated import DISABLED_MESSAGE
|
|
from test.test_ldap import mock_ldap
|
|
from test.test_keystone_auth import fake_keystone
|
|
|
|
from test.fixtures import *
|
|
|
|
@pytest.mark.parametrize('auth_system_builder, user1, user2', [
|
|
(mock_ldap, ('someuser', 'somepass'), ('testy', 'password')),
|
|
(fake_keystone, ('cool.user', 'password'), ('some.neat.user', 'foobar')),
|
|
])
|
|
def test_auth_createuser(auth_system_builder, user1, user2, config, app):
|
|
with auth_system_builder() as auth:
|
|
# Login as a user and ensure a row in the database is created for them.
|
|
user, err = auth.verify_and_link_user(*user1)
|
|
assert err is None
|
|
assert user
|
|
|
|
federated_info = model.user.lookup_federated_login(user, auth.federated_service)
|
|
assert federated_info is not None
|
|
|
|
# Disable user creation.
|
|
with patch('features.USER_CREATION', False):
|
|
# Ensure that the existing user can login.
|
|
user_again, err = auth.verify_and_link_user(*user1)
|
|
assert err is None
|
|
assert user_again.id == user.id
|
|
|
|
# Ensure that a new user cannot.
|
|
new_user, err = auth.verify_and_link_user(*user2)
|
|
assert new_user is None
|
|
assert err == DISABLED_MESSAGE
|