Skip to content

Commit cce0954

Browse files
fluetmchris-crone
authored andcommitted
Fix for empty auth keys in config.json
Signed-off-by: Matt Fluet <[email protected]>
1 parent 73ad8b8 commit cce0954

File tree

2 files changed

+118
-0
lines changed

2 files changed

+118
-0
lines changed

docker/auth.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,12 +303,14 @@ def get_all_credentials(self):
303303
auth_data[k] = self._resolve_authconfig_credstore(
304304
k, self.creds_store
305305
)
306+
auth_data[convert_to_hostname(k)] = auth_data[k]
306307

307308
# credHelpers entries take priority over all others
308309
for reg, store_name in self.cred_helpers.items():
309310
auth_data[reg] = self._resolve_authconfig_credstore(
310311
reg, store_name
311312
)
313+
auth_data[convert_to_hostname(reg)] = auth_data[reg]
312314

313315
return auth_data
314316

tests/unit/auth_test.py

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,11 +530,21 @@ def test_get_all_credentials_credstore_only(self):
530530
'Password': 'izayoi',
531531
'ServerAddress': 'https://gensokyo.jp/v2',
532532
},
533+
'gensokyo.jp': {
534+
'Username': 'sakuya',
535+
'Password': 'izayoi',
536+
'ServerAddress': 'https://gensokyo.jp/v2',
537+
},
533538
'https://default.com/v2': {
534539
'Username': 'user',
535540
'Password': 'hunter2',
536541
'ServerAddress': 'https://default.com/v2',
537542
},
543+
'default.com': {
544+
'Username': 'user',
545+
'Password': 'hunter2',
546+
'ServerAddress': 'https://default.com/v2',
547+
},
538548
}
539549

540550
def test_get_all_credentials_with_empty_credhelper(self):
@@ -548,11 +558,21 @@ def test_get_all_credentials_with_empty_credhelper(self):
548558
'Password': 'izayoi',
549559
'ServerAddress': 'https://gensokyo.jp/v2',
550560
},
561+
'gensokyo.jp': {
562+
'Username': 'sakuya',
563+
'Password': 'izayoi',
564+
'ServerAddress': 'https://gensokyo.jp/v2',
565+
},
551566
'https://default.com/v2': {
552567
'Username': 'user',
553568
'Password': 'hunter2',
554569
'ServerAddress': 'https://default.com/v2',
555570
},
571+
'default.com': {
572+
'Username': 'user',
573+
'Password': 'hunter2',
574+
'ServerAddress': 'https://default.com/v2',
575+
},
556576
'registry1.io': None,
557577
}
558578

@@ -571,11 +591,21 @@ def test_get_all_credentials_with_credhelpers_only(self):
571591
'Password': 'izayoi',
572592
'ServerAddress': 'https://gensokyo.jp/v2',
573593
},
594+
'gensokyo.jp': {
595+
'Username': 'sakuya',
596+
'Password': 'izayoi',
597+
'ServerAddress': 'https://gensokyo.jp/v2',
598+
},
574599
'https://default.com/v2': {
575600
'Username': 'user',
576601
'Password': 'hunter2',
577602
'ServerAddress': 'https://default.com/v2',
578603
},
604+
'default.com': {
605+
'Username': 'user',
606+
'Password': 'hunter2',
607+
'ServerAddress': 'https://default.com/v2',
608+
},
579609
}
580610

581611
def test_get_all_credentials_with_auths_entries(self):
@@ -591,18 +621,84 @@ def test_get_all_credentials_with_auths_entries(self):
591621
'Password': 'izayoi',
592622
'ServerAddress': 'https://gensokyo.jp/v2',
593623
},
624+
'gensokyo.jp': {
625+
'Username': 'sakuya',
626+
'Password': 'izayoi',
627+
'ServerAddress': 'https://gensokyo.jp/v2',
628+
},
594629
'https://default.com/v2': {
595630
'Username': 'user',
596631
'Password': 'hunter2',
597632
'ServerAddress': 'https://default.com/v2',
598633
},
634+
'default.com': {
635+
'Username': 'user',
636+
'Password': 'hunter2',
637+
'ServerAddress': 'https://default.com/v2',
638+
},
599639
'registry1.io': {
600640
'ServerAddress': 'registry1.io',
601641
'Username': 'reimu',
602642
'Password': 'hakurei',
603643
},
604644
}
605645

646+
def test_get_all_credentials_with_empty_auths_entry(self):
647+
self.authconfig.add_auth('default.com', {})
648+
649+
assert self.authconfig.get_all_credentials() == {
650+
'https://gensokyo.jp/v2': {
651+
'Username': 'sakuya',
652+
'Password': 'izayoi',
653+
'ServerAddress': 'https://gensokyo.jp/v2',
654+
},
655+
'gensokyo.jp': {
656+
'Username': 'sakuya',
657+
'Password': 'izayoi',
658+
'ServerAddress': 'https://gensokyo.jp/v2',
659+
},
660+
'https://default.com/v2': {
661+
'Username': 'user',
662+
'Password': 'hunter2',
663+
'ServerAddress': 'https://default.com/v2',
664+
},
665+
'default.com': {
666+
'Username': 'user',
667+
'Password': 'hunter2',
668+
'ServerAddress': 'https://default.com/v2',
669+
},
670+
}
671+
672+
def test_get_all_credentials_credstore_overrides_auth_entry(self):
673+
self.authconfig.add_auth('default.com', {
674+
'Username': 'shouldnotsee',
675+
'Password': 'thisentry',
676+
'ServerAddress': 'https://default.com/v2',
677+
})
678+
679+
assert self.authconfig.get_all_credentials() == {
680+
'https://gensokyo.jp/v2': {
681+
'Username': 'sakuya',
682+
'Password': 'izayoi',
683+
'ServerAddress': 'https://gensokyo.jp/v2',
684+
},
685+
'gensokyo.jp': {
686+
'Username': 'sakuya',
687+
'Password': 'izayoi',
688+
'ServerAddress': 'https://gensokyo.jp/v2',
689+
},
690+
'https://default.com/v2': {
691+
'Username': 'user',
692+
'Password': 'hunter2',
693+
'ServerAddress': 'https://default.com/v2',
694+
},
695+
'default.com': {
696+
'Username': 'user',
697+
'Password': 'hunter2',
698+
'ServerAddress': 'https://default.com/v2',
699+
},
700+
}
701+
606702
def test_get_all_credentials_helpers_override_default(self):
607703
self.authconfig['credHelpers'] = {
608704
'https://default.com/v2': 'truesecret',
@@ -616,11 +712,21 @@ def test_get_all_credentials_helpers_override_default(self):
616712
'Password': 'izayoi',
617713
'ServerAddress': 'https://gensokyo.jp/v2',
618714
},
715+
'gensokyo.jp': {
716+
'Username': 'sakuya',
717+
'Password': 'izayoi',
718+
'ServerAddress': 'https://gensokyo.jp/v2',
719+
},
619720
'https://default.com/v2': {
620721
'Username': 'reimu',
621722
'Password': 'hakurei',
622723
'ServerAddress': 'https://default.com/v2',
623724
},
725+
'default.com': {
726+
'Username': 'reimu',
727+
'Password': 'hakurei',
728+
'ServerAddress': 'https://default.com/v2',
729+
},
624730
}
625731

626732
def test_get_all_credentials_3_sources(self):
@@ -642,11 +748,21 @@ def test_get_all_credentials_3_sources(self):
642748
'Password': 'izayoi',
643749
'ServerAddress': 'https://gensokyo.jp/v2',
644750
},
751+
'gensokyo.jp': {
752+
'Username': 'sakuya',
753+
'Password': 'izayoi',
754+
'ServerAddress': 'https://gensokyo.jp/v2',
755+
},
645756
'https://default.com/v2': {
646757
'Username': 'user',
647758
'Password': 'hunter2',
648759
'ServerAddress': 'https://default.com/v2',
649760
},
761+
'default.com': {
762+
'Username': 'user',
763+
'Password': 'hunter2',
764+
'ServerAddress': 'https://default.com/v2',
765+
},
650766
'registry1.io': {
651767
'ServerAddress': 'registry1.io',
652768
'Username': 'reimu',

0 commit comments

Comments
 (0)