Kaydet (Commit) 40770878 authored tarafından Joffrey F's avatar Joffrey F

Additional tests and small improvement to auth.resolve_authconfig

üst 3d6d5e10
...@@ -3,5 +3,5 @@ from .auth import ( ...@@ -3,5 +3,5 @@ from .auth import (
encode_header, encode_header,
load_config, load_config,
resolve_authconfig, resolve_authconfig,
resolve_repository_name resolve_repository_name,
) # flake8: noqa ) # flake8: noqa
\ No newline at end of file
...@@ -75,7 +75,7 @@ def resolve_authconfig(authconfig, registry=None): ...@@ -75,7 +75,7 @@ def resolve_authconfig(authconfig, registry=None):
# Default to the public index server # Default to the public index server
registry = registry or INDEX_URL registry = registry or INDEX_URL
# Ff its not the index server there are three cases: # If it's not the index server there are three cases:
# #
# 1. this is a full config url -> it should be used as is # 1. this is a full config url -> it should be used as is
# 2. it could be a full url, but with the wrong protocol # 2. it could be a full url, but with the wrong protocol
...@@ -84,7 +84,7 @@ def resolve_authconfig(authconfig, registry=None): ...@@ -84,7 +84,7 @@ def resolve_authconfig(authconfig, registry=None):
# as there is only one auth entry which is fully qualified we need to start # as there is only one auth entry which is fully qualified we need to start
# parsing and matching # parsing and matching
if '/v1/' not in registry: if '/v1/' not in registry:
registry = registry + '/v1/' registry = os.path.join(registry, 'v1/')
if not registry.startswith('http:') and not registry.startswith('https:'): if not registry.startswith('http:') and not registry.startswith('https:'):
registry = 'https://' + registry registry = 'https://' + registry
......
...@@ -8,6 +8,7 @@ from docker.utils import ( ...@@ -8,6 +8,7 @@ from docker.utils import (
parse_repository_tag, parse_host, convert_filters, kwargs_from_env, parse_repository_tag, parse_host, convert_filters, kwargs_from_env,
create_host_config create_host_config
) )
from docker.auth import resolve_authconfig
class UtilsTest(unittest.TestCase): class UtilsTest(unittest.TestCase):
...@@ -100,6 +101,60 @@ class UtilsTest(unittest.TestCase): ...@@ -100,6 +101,60 @@ class UtilsTest(unittest.TestCase):
empty_config = create_host_config() empty_config = create_host_config()
self.assertEqual(empty_config, {}) self.assertEqual(empty_config, {})
def test_resolve_authconfig(self):
auth_config = {
'https://index.docker.io/v1/': {'auth': 'indexuser'},
'http://my.registry.net/v1/': {'auth': 'privateuser'}
}
# hostname only
self.assertEqual(
resolve_authconfig(auth_config, 'my.registry.net'),
{'auth': 'privateuser'}
)
# no protocol
self.assertEqual(
resolve_authconfig(auth_config, 'my.registry.net/v1/'),
{'auth': 'privateuser'}
)
# no path
self.assertEqual(
resolve_authconfig(auth_config, 'http://my.registry.net'),
{'auth': 'privateuser'}
)
# no path, trailing slash
self.assertEqual(
resolve_authconfig(auth_config, 'http://my.registry.net/'),
{'auth': 'privateuser'}
)
# no path, wrong secure protocol
self.assertEqual(
resolve_authconfig(auth_config, 'https://my.registry.net'),
{'auth': 'privateuser'}
)
# no path, wrong insecure protocol
self.assertEqual(
resolve_authconfig(auth_config, 'http://index.docker.io'),
{'auth': 'indexuser'}
)
# with path, wrong protocol
self.assertEqual(
resolve_authconfig(auth_config, 'https://my.registry.net/v1/'),
{'auth': 'privateuser'}
)
# default registry
self.assertEqual(
resolve_authconfig(auth_config), {'auth': 'indexuser'}
)
# default registry (explicit None)
self.assertEqual(
resolve_authconfig(auth_config, None), {'auth': 'indexuser'}
)
# fully explicit
self.assertEqual(
resolve_authconfig(auth_config, 'http://my.registry.net/v1/'),
{'auth': 'privateuser'}
)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment