Skip to content

Commit

Permalink
Fixes regression #1179
Browse files Browse the repository at this point in the history
  • Loading branch information
tkrah committed Sep 28, 2023
1 parent 1ee4778 commit 03a632d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ public AuthConfigurations lookupAllAuthConfigs(DockerRegistryCredentials registr
*/
public AuthConfigurations lookupAllAuthConfigs(AuthConfig additionalAuthConfig) {
AuthConfigurations allAuthConfigs = lookupAllAuthConfigs();
if (allAuthConfigs.getConfigs().isEmpty()) {
if (additionalAuthConfig.getUsername() != null && additionalAuthConfig.getPassword() != null) {
allAuthConfigs.addConfig(additionalAuthConfig);
}
return allAuthConfigs;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class RegistryAuthLocatorTest extends Specification {
}

@Issue('https://github.com/bmuschko/gradle-docker-plugin/issues/985')
def "AuthLocator returns auth from file over default"() {
def "AuthLocator returns empty auth from file over default"() {
given:
RegistryAuthLocator locator =
createAuthLocatorForExistingConfigFile('config-docker-hub-user-pass.json', false)
Expand All @@ -154,6 +154,33 @@ class RegistryAuthLocatorTest extends Specification {
0 * logger.error(*_)
}

@Issue('https://github.com/bmuschko/gradle-docker-plugin/issues/1179')
def "AuthLocator returns valid auth from file and default"() {
given:
RegistryAuthLocator locator =
createAuthLocatorForExistingConfigFile('config-docker-hub-user-pass.json', false)

when:
AuthConfigurations allConfigs = locator.lookupAllAuthConfigs(new AuthConfig()
.withRegistryAddress("https://index.docker.io/v2/")
.withUsername("username2")
.withPassword("secret2"))

then:
AuthConfig config = new AuthConfig()
.withUsername('username')
.withPassword('secret')
AuthConfig configAddon = new AuthConfig()
.withRegistryAddress("https://index.docker.io/v2/")
.withUsername('username2')
.withPassword('secret2')
allConfigs.configs.size() == 2
allConfigs.configs.get(config.registryAddress) == config
allConfigs.configs.get(configAddon.registryAddress) == configAddon

0 * logger.error(*_)
}

def "AuthLocator returns correct default registry"() {
given:
String image = 'ubuntu'
Expand Down

0 comments on commit 03a632d

Please sign in to comment.