2017-02-10 00:30:07 +00:00
|
|
|
import pytest
|
|
|
|
|
|
|
|
from util.config.validators import ConfigValidationException
|
|
|
|
from util.config.validators.validate_keystone import KeystoneValidator
|
|
|
|
from util.morecollections import AttrDict
|
|
|
|
|
|
|
|
from test.test_keystone_auth import fake_keystone
|
|
|
|
|
2017-04-24 18:52:30 +00:00
|
|
|
from test.fixtures import *
|
2017-02-10 00:30:07 +00:00
|
|
|
|
|
|
|
@pytest.mark.parametrize('unvalidated_config', [
|
|
|
|
({}),
|
|
|
|
({'AUTHENTICATION_TYPE': 'Database'}),
|
|
|
|
])
|
2017-04-24 18:52:30 +00:00
|
|
|
def test_validate_noop(unvalidated_config, app):
|
2017-02-10 00:30:07 +00:00
|
|
|
KeystoneValidator.validate(unvalidated_config, None, None)
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('unvalidated_config', [
|
|
|
|
({'AUTHENTICATION_TYPE': 'Keystone'}),
|
|
|
|
({'AUTHENTICATION_TYPE': 'Keystone', 'KEYSTONE_AUTH_URL': 'foo'}),
|
|
|
|
({'AUTHENTICATION_TYPE': 'Keystone', 'KEYSTONE_AUTH_URL': 'foo',
|
|
|
|
'KEYSTONE_ADMIN_USERNAME': 'bar'}),
|
|
|
|
({'AUTHENTICATION_TYPE': 'Keystone', 'KEYSTONE_AUTH_URL': 'foo',
|
|
|
|
'KEYSTONE_ADMIN_USERNAME': 'bar', 'KEYSTONE_ADMIN_PASSWORD': 'baz'}),
|
|
|
|
])
|
2017-04-24 18:52:30 +00:00
|
|
|
def test_invalid_config(unvalidated_config, app):
|
2017-02-10 00:30:07 +00:00
|
|
|
with pytest.raises(ConfigValidationException):
|
|
|
|
KeystoneValidator.validate(unvalidated_config, None, None)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('username, password, expected_exception', [
|
|
|
|
('invaliduser', 'invalidpass', ConfigValidationException),
|
|
|
|
('cool.user', 'invalidpass', ConfigValidationException),
|
|
|
|
('invaliduser', 'somepass', ConfigValidationException),
|
|
|
|
('cool.user', 'password', None),
|
|
|
|
])
|
2017-04-24 18:52:30 +00:00
|
|
|
def test_validated_keystone(username, password, expected_exception, app):
|
2017-02-10 00:30:07 +00:00
|
|
|
with fake_keystone(2) as keystone_auth:
|
|
|
|
auth_url = keystone_auth.auth_url
|
|
|
|
|
|
|
|
config = {}
|
|
|
|
config['AUTHENTICATION_TYPE'] = 'Keystone'
|
|
|
|
config['KEYSTONE_AUTH_URL'] = auth_url
|
|
|
|
config['KEYSTONE_ADMIN_USERNAME'] = 'adminuser'
|
|
|
|
config['KEYSTONE_ADMIN_PASSWORD'] = 'adminpass'
|
|
|
|
config['KEYSTONE_ADMIN_TENANT'] = 'admintenant'
|
|
|
|
|
|
|
|
if expected_exception is not None:
|
|
|
|
with pytest.raises(ConfigValidationException):
|
|
|
|
KeystoneValidator.validate(config, AttrDict(dict(username=username)), password)
|
|
|
|
else:
|
|
|
|
KeystoneValidator.validate(config, AttrDict(dict(username=username)), password)
|