diff --git a/src/main/java/com/bmuschko/gradle/docker/internal/RegistryAuthLocator.java b/src/main/java/com/bmuschko/gradle/docker/internal/RegistryAuthLocator.java index afa8b53c6..10e8c7f79 100644 --- a/src/main/java/com/bmuschko/gradle/docker/internal/RegistryAuthLocator.java +++ b/src/main/java/com/bmuschko/gradle/docker/internal/RegistryAuthLocator.java @@ -245,7 +245,7 @@ public AuthConfigurations lookupAllAuthConfigs(DockerRegistryCredentials registr */ public AuthConfigurations lookupAllAuthConfigs(AuthConfig additionalAuthConfig) { AuthConfigurations allAuthConfigs = lookupAllAuthConfigs(); - if (allAuthConfigs.getConfigs().isEmpty()) { + if (isProvidedByBuild(additionalAuthConfig)) { allAuthConfigs.addConfig(additionalAuthConfig); } return allAuthConfigs; diff --git a/src/test/groovy/com/bmuschko/gradle/docker/internal/RegistryAuthLocatorTest.groovy b/src/test/groovy/com/bmuschko/gradle/docker/internal/RegistryAuthLocatorTest.groovy index 63af3cd58..956b918f9 100644 --- a/src/test/groovy/com/bmuschko/gradle/docker/internal/RegistryAuthLocatorTest.groovy +++ b/src/test/groovy/com/bmuschko/gradle/docker/internal/RegistryAuthLocatorTest.groovy @@ -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) @@ -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'