Skip to content

Commit a695f0c

Browse files
committed
Fix #627
Docker-py couldn't pull private images if the account have non ascii chars in either user or password. It that case an exception ending with no auth credentials. Instead docker client (golang) don't suffer this issue. Also add a test to check the login or password even with non ascii char have a valid auth dictionary Signed-off-by: Alejandro Brito Monedero <[email protected]>
1 parent 47ab89e commit a695f0c

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

docker/auth/auth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def decode_auth(auth):
9696
auth = auth.encode('ascii')
9797
s = base64.b64decode(auth)
9898
login, pwd = s.split(b':', 1)
99-
return login.decode('ascii'), pwd.decode('ascii')
99+
return login.decode('utf8'), pwd.decode('utf8')
100100

101101

102102
def encode_header(auth):

tests/unit/auth_test.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,3 +316,33 @@ def test_load_config_custom_config_env_with_auths(self):
316316
self.assertEqual(cfg['password'], 'izayoi')
317317
self.assertEqual(cfg['email'], '[email protected]')
318318
self.assertEqual(cfg.get('auth'), None)
319+
320+
def test_load_config_custom_config_env_utf8(self):
321+
folder = tempfile.mkdtemp()
322+
self.addCleanup(shutil.rmtree, folder)
323+
324+
dockercfg_path = os.path.join(folder, 'config.json')
325+
registry = 'https://your.private.registry.io'
326+
auth_ = base64.b64encode(
327+
b'sakuya\xc3\xa6:izayoi\xc3\xa6').decode('ascii')
328+
config = {
329+
'auths': {
330+
registry: {
331+
'auth': '{0}'.format(auth_),
332+
'email': '[email protected]'
333+
}
334+
}
335+
}
336+
337+
with open(dockercfg_path, 'w') as f:
338+
json.dump(config, f)
339+
340+
with mock.patch.dict(os.environ, {'DOCKER_CONFIG': folder}):
341+
cfg = auth.load_config(None)
342+
assert registry in cfg
343+
self.assertNotEqual(cfg[registry], None)
344+
cfg = cfg[registry]
345+
self.assertEqual(cfg['username'], b'sakuya\xc3\xa6'.decode('utf8'))
346+
self.assertEqual(cfg['password'], b'izayoi\xc3\xa6'.decode('utf8'))
347+
self.assertEqual(cfg['email'], '[email protected]')
348+
self.assertEqual(cfg.get('auth'), None)

0 commit comments

Comments
 (0)