@@ -282,22 +282,64 @@ def test_load_config_no_file(self):
282
282
cfg = auth .load_config (folder )
283
283
assert cfg is not None
284
284
285
- def test_load_config (self ):
285
+ def test_load_legacy_config (self ):
286
286
folder = tempfile .mkdtemp ()
287
287
self .addCleanup (shutil .rmtree , folder )
288
- dockercfg_path = os .path .join (folder , '.dockercfg' )
289
- with open ( dockercfg_path , 'w' ) as f :
290
- auth_ = base64 . b64encode ( b'sakuya:izayoi' ). decode ( 'ascii' )
288
+ cfg_path = os .path .join (folder , '.dockercfg' )
289
+ auth_ = base64 . b64encode ( b'sakuya:izayoi' ). decode ( 'ascii' )
290
+ with open ( cfg_path , 'w' ) as f :
291
291
f .write ('auth = {0}\n ' .format (auth_ ))
292
292
f .
write (
'email = [email protected] ' )
293
- cfg = auth .load_config (dockercfg_path )
294
- assert auth .INDEX_NAME in cfg
295
- assert cfg [auth .INDEX_NAME ] is not None
296
- cfg = cfg [auth .INDEX_NAME ]
293
+
294
+ cfg = auth .load_config (cfg_path )
295
+ assert auth .resolve_authconfig (cfg ) is not None
296
+ assert cfg ['auths' ][auth .INDEX_NAME ] is not None
297
+ cfg = cfg ['auths' ][auth .INDEX_NAME ]
297
298
assert cfg ['username' ] == 'sakuya'
298
299
assert cfg ['password' ] == 'izayoi'
299
300
assert cfg [
'email' ]
== '[email protected] '
300
- assert cfg .get ('auth' ) is None
301
+ assert cfg .get ('Auth' ) is None
302
+
303
+ def test_load_json_config (self ):
304
+ folder = tempfile .mkdtemp ()
305
+ self .addCleanup (shutil .rmtree , folder )
306
+ cfg_path = os .path .join (folder , '.dockercfg' )
307
+ auth_ = base64 .b64encode (b'sakuya:izayoi' ).decode ('ascii' )
308
+
309
+ with open (cfg_path , 'w' ) as f :
310
+ json .dump (
311
+ {auth .INDEX_URL : {'auth' : auth_ , 'email' : email }}, f
312
+ )
313
+ cfg = auth .load_config (cfg_path )
314
+ assert auth .resolve_authconfig (cfg ) is not None
315
+ assert cfg ['auths' ][auth .INDEX_URL ] is not None
316
+ cfg = cfg ['auths' ][auth .INDEX_URL ]
317
+ assert cfg ['username' ] == 'sakuya'
318
+ assert cfg ['password' ] == 'izayoi'
319
+ assert cfg ['email' ] == email
320
+ assert cfg .get ('Auth' ) is None
321
+
322
+ def test_load_modern_json_config (self ):
323
+ folder = tempfile .mkdtemp ()
324
+ self .addCleanup (shutil .rmtree , folder )
325
+ cfg_path = os .path .join (folder , 'config.json' )
326
+ auth_ = base64 .b64encode (b'sakuya:izayoi' ).decode ('ascii' )
327
+
328
+ with open (cfg_path , 'w' ) as f :
329
+ json .dump ({
330
+ 'auths' : {
331
+ auth .INDEX_URL : {
332
+ 'auth' : auth_ , 'email' : email
333
+ }
334
+ }
335
+ }, f )
336
+ cfg = auth .load_config (cfg_path )
337
+ assert auth .resolve_authconfig (cfg ) is not None
338
+ assert cfg ['auths' ][auth .INDEX_URL ] is not None
339
+ cfg = cfg ['auths' ][auth .INDEX_URL ]
340
+ assert cfg ['username' ] == 'sakuya'
341
+ assert cfg ['password' ] == 'izayoi'
342
+ assert cfg ['email' ] == email
301
343
302
344
def test_load_config_with_random_name (self ):
303
345
folder = tempfile .mkdtemp ()
@@ -318,7 +360,7 @@ def test_load_config_with_random_name(self):
318
360
with open (dockercfg_path , 'w' ) as f :
319
361
json .dump (config , f )
320
362
321
- cfg = auth .load_config (dockercfg_path )
363
+ cfg = auth .load_config (dockercfg_path )[ 'auths' ]
322
364
assert registry in cfg
323
365
assert cfg [registry ] is not None
324
366
cfg = cfg [registry ]
@@ -345,7 +387,7 @@ def test_load_config_custom_config_env(self):
345
387
json .dump (config , f )
346
388
347
389
with mock .patch .dict (os .environ , {'DOCKER_CONFIG' : folder }):
348
- cfg = auth .load_config (None )
390
+ cfg = auth .load_config (None )[ 'auths' ]
349
391
assert registry in cfg
350
392
assert cfg [registry ] is not None
351
393
cfg = cfg [registry ]
@@ -422,7 +464,7 @@ def test_load_config_unknown_keys(self):
422
464
json .dump (config , f )
423
465
424
466
cfg = auth .load_config (dockercfg_path )
425
- assert cfg == {}
467
+ assert cfg == {'auths' : {} }
426
468
427
469
def test_load_config_invalid_auth_dict (self ):
428
470
folder = tempfile .mkdtemp ()
0 commit comments