mirror of https://github.com/docker/docker-py.git
				
				
				
			Additional tests and small improvement to auth.resolve_authconfig
This commit is contained in:
		
							parent
							
								
									3d6d5e1012
								
							
						
					
					
						commit
						40770878ad
					
				|  | @ -3,5 +3,5 @@ from .auth import ( | |||
|     encode_header, | ||||
|     load_config, | ||||
|     resolve_authconfig, | ||||
|     resolve_repository_name | ||||
|     resolve_repository_name, | ||||
| )  # flake8: noqa | ||||
|  | @ -75,7 +75,7 @@ def resolve_authconfig(authconfig, registry=None): | |||
|     # Default to the public index server | ||||
|     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 | ||||
|     # 2. it could be a full url, but with the wrong protocol | ||||
|  | @ -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 | ||||
|     # parsing and matching | ||||
|     if '/v1/' not in registry: | ||||
|         registry = registry + '/v1/' | ||||
|         registry = os.path.join(registry, 'v1/') | ||||
|     if not registry.startswith('http:') and not registry.startswith('https:'): | ||||
|         registry = 'https://' + registry | ||||
| 
 | ||||
|  |  | |||
|  | @ -8,6 +8,7 @@ from docker.utils import ( | |||
|     parse_repository_tag, parse_host, convert_filters, kwargs_from_env, | ||||
|     create_host_config | ||||
| ) | ||||
| from docker.auth import resolve_authconfig | ||||
| 
 | ||||
| 
 | ||||
| class UtilsTest(unittest.TestCase): | ||||
|  | @ -100,6 +101,60 @@ class UtilsTest(unittest.TestCase): | |||
|         empty_config = create_host_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__': | ||||
|     unittest.main() | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue