diff --git a/test/functional/__init__.py b/test/functional/__init__.py index cd32a210f3..2adb15b66c 100644 --- a/test/functional/__init__.py +++ b/test/functional/__init__.py @@ -16,7 +16,7 @@ from __future__ import print_function import mock import os -from six.moves.urllib.parse import urlparse +from six.moves.urllib.parse import urlparse, urlsplit, urlunsplit import sys import pickle import socket @@ -574,10 +574,7 @@ def in_process_setup(the_object_server=object_server): "Content-Language, Expires, X-Robots-Tag", # Below are values used by the functional test framework, as well as # by the various in-process swift servers - 'auth_host': '127.0.0.1', - 'auth_port': str(prolis.getsockname()[1]), - 'auth_ssl': 'no', - 'auth_prefix': '/auth/', + 'auth_uri': 'http://127.0.0.1:%d/auth/v1.0' % prolis.getsockname()[1], # Primary functional test account (needs admin access to the # account) 'account': 'test', @@ -844,23 +841,39 @@ def setup_package(): if config: swift_test_auth_version = str(config.get('auth_version', '1')) - swift_test_auth = 'http' - if config_true_value(config.get('auth_ssl', 'no')): - swift_test_auth = 'https' - if 'auth_prefix' not in config: - config['auth_prefix'] = '/' - try: - suffix = '://%(auth_host)s:%(auth_port)s%(auth_prefix)s' % config - swift_test_auth += suffix - except KeyError: - pass # skip + if 'auth_uri' in config: + swift_test_auth = config['auth_uri'] + # Back-fill the individual parts -- really, we should just need + # host and port for s3_test_client, and that's only until we + # improve it to take a s3_storage_url option + parsed = urlsplit(config['auth_uri']) + config.update({ + 'auth_ssl': parsed.scheme == 'https', + 'auth_host': parsed.hostname, + 'auth_port': (parsed.port if parsed.port is not None else + 443 if parsed.scheme == 'https' else 80), + 'auth_prefix': parsed.path, + }) + elif 'auth_host' in config: + scheme = 'http' + if config_true_value(config.get('auth_ssl', 'no')): + scheme = 'https' + netloc = config['auth_host'] + if 'auth_port' in config: + netloc += ':' + config['auth_port'] + auth_prefix = config.get('auth_prefix', '/') + if swift_test_auth_version == "1": + auth_prefix += 'v1.0' + config['auth_uri'] = swift_test_auth = urlunsplit( + (scheme, netloc, auth_prefix, None, None)) + # else, neither auth_uri nor auth_host; swift_test_auth will be unset + # and we'll skip everything later if 'service_prefix' in config: swift_test_service_prefix = utils.append_underscore( config['service_prefix']) if swift_test_auth_version == "1": - swift_test_auth += 'v1.0' try: if 'account' in config: diff --git a/test/functional/swift_test_client.py b/test/functional/swift_test_client.py index ae00644d9c..df8a851b5e 100644 --- a/test/functional/swift_test_client.py +++ b/test/functional/swift_test_client.py @@ -198,16 +198,13 @@ def putrequest(self, method, url, skip_host=False, skip_accept_encoding=False): class Connection(object): def __init__(self, config): - for key in 'auth_host auth_port auth_ssl username password'.split(): + for key in 'auth_uri username password'.split(): if key not in config: raise SkipTest( "Missing required configuration parameter: %s" % key) - self.auth_host = config['auth_host'] - self.auth_port = int(config['auth_port']) - self.auth_ssl = config['auth_ssl'] in ('on', 'true', 'yes', '1') + self.auth_url = config['auth_uri'] self.insecure = config_true_value(config.get('insecure', 'false')) - self.auth_prefix = config.get('auth_prefix', '/') self.auth_version = str(config.get('auth_version', '1')) self.account = config.get('account') @@ -256,18 +253,10 @@ class Connection(object): return Account(self, self.account) def authenticate(self): - if self.auth_version == "1": - auth_path = '%sv1.0' % (self.auth_prefix) - if self.account: - auth_user = '%s:%s' % (self.account, self.username) - else: - auth_user = self.username + if self.auth_version == "1" and self.account: + auth_user = '%s:%s' % (self.account, self.username) else: auth_user = self.username - auth_path = self.auth_prefix - auth_scheme = 'https://' if self.auth_ssl else 'http://' - auth_netloc = "%s:%d" % (self.auth_host, self.auth_port) - auth_url = auth_scheme + auth_netloc + auth_path if self.insecure: try: @@ -283,7 +272,7 @@ class Connection(object): auth_version=self.auth_version, os_options={}, insecure=self.insecure) (storage_url, storage_token) = get_auth( - auth_url, auth_user, self.password, **authargs) + self.auth_url, auth_user, self.password, **authargs) if not (storage_url and storage_token): raise AuthenticationFailed() diff --git a/test/sample.conf b/test/sample.conf index d33be75486..1f55fc7b0b 100644 --- a/test/sample.conf +++ b/test/sample.conf @@ -1,17 +1,11 @@ [func_test] # Sample config for Swift with tempauth -auth_host = 127.0.0.1 -auth_port = 8080 -auth_ssl = no -auth_prefix = /auth/ +auth_uri = http://127.0.0.1:8080/auth/v1.0 # Sample config for Swift with Keystone v2 API. # For keystone v2 change auth_version to 2 and auth_prefix to /v2.0/. # And "allow_account_management" should not be set "true". #auth_version = 3 -#auth_host = localhost -#auth_port = 5000 -#auth_ssl = no -#auth_prefix = /v3/ +#auth_uri = http://localhost:5000/v3/ # Primary functional test account (needs admin access to the account) account = test