diff --git a/core/src/main/java/org/testcontainers/utility/RegistryAuthLocator.java b/core/src/main/java/org/testcontainers/utility/RegistryAuthLocator.java index ff29206cc30..3caabb6f0d4 100644 --- a/core/src/main/java/org/testcontainers/utility/RegistryAuthLocator.java +++ b/core/src/main/java/org/testcontainers/utility/RegistryAuthLocator.java @@ -289,7 +289,10 @@ private AuthConfig runCredentialProvider(String hostName, String helperOrStoreNa final String responseErrorMsg = data.getStdout(); if (!StringUtils.isBlank(responseErrorMsg)) { - String credentialsNotFoundMsg = getGenericCredentialsNotFoundMsg(credentialProgramName); + String credentialsNotFoundMsg = getGenericCredentialsNotFoundMsg( + responseErrorMsg, + credentialProgramName + ); if (credentialsNotFoundMsg != null && credentialsNotFoundMsg.equals(responseErrorMsg)) { log.info( "Credential helper/store ({}) does not have credentials for {}", @@ -346,48 +349,13 @@ private String effectiveRegistryName(DockerImageName dockerImageName) { ); } - private String getGenericCredentialsNotFoundMsg(String credentialHelperName) { + private String getGenericCredentialsNotFoundMsg(String credentialsNotFoundMsg, String credentialHelperName) { if (!CREDENTIALS_HELPERS_NOT_FOUND_MESSAGE_CACHE.containsKey(credentialHelperName)) { - String credentialsNotFoundMsg = discoverCredentialsHelperNotFoundMessage(credentialHelperName); - if (!StringUtils.isBlank(credentialsNotFoundMsg)) { - CREDENTIALS_HELPERS_NOT_FOUND_MESSAGE_CACHE.put(credentialHelperName, credentialsNotFoundMsg); - } + CREDENTIALS_HELPERS_NOT_FOUND_MESSAGE_CACHE.put(credentialHelperName, credentialsNotFoundMsg); } - return CREDENTIALS_HELPERS_NOT_FOUND_MESSAGE_CACHE.get(credentialHelperName); } - private String discoverCredentialsHelperNotFoundMessage(String credentialHelperName) { - // will do fake call to given credential helper to find out with which message - // it response when there are no credentials for given hostName - - // hostName should be valid, but most probably not existing - // IF its not enough, then should probably run 'list' command first to be sure... - final String notExistentFakeHostName = "https://not.a.real.registry/url"; - - String credentialsNotFoundMsg = null; - try { - CredentialOutput data = runCredentialProgram(notExistentFakeHostName, credentialHelperName); - - if (data.getStdout() != null && !data.getStdout().isEmpty()) { - credentialsNotFoundMsg = data.getStdout(); - - log.debug( - "Got credentials not found error message from docker credential helper - {}", - credentialsNotFoundMsg - ); - } - } catch (Exception e) { - log.warn( - "Failure running docker credential helper ({}) with fake call, expected 'credentials not found' response. Exception message: {}", - credentialHelperName, - e.getMessage() - ); - } - - return credentialsNotFoundMsg; - } - private CredentialOutput runCredentialProgram(String hostName, String credentialHelperName) throws InterruptedException, TimeoutException, IOException { String[] command = SystemUtils.IS_OS_WINDOWS diff --git a/core/src/test/java/org/testcontainers/utility/RegistryAuthLocatorTest.java b/core/src/test/java/org/testcontainers/utility/RegistryAuthLocatorTest.java index 2e6f87d08b7..ed986b05015 100644 --- a/core/src/test/java/org/testcontainers/utility/RegistryAuthLocatorTest.java +++ b/core/src/test/java/org/testcontainers/utility/RegistryAuthLocatorTest.java @@ -241,7 +241,7 @@ public void lookupAuthConfigWithCredentialsNotFound() throws URISyntaxException, assertThat(discoveredMessage) .as("Not correct message discovered") - .isEqualTo("Fake credentials not found on credentials store 'https://not.a.real.registry/url'"); + .isEqualTo("Fake credentials not found on credentials store 'registry2.example.com'"); } @Test diff --git a/core/src/test/resources/auth-config/docker-credential-fake b/core/src/test/resources/auth-config/docker-credential-fake index b1d5ffb50d4..3eb54b35a7e 100755 --- a/core/src/test/resources/auth-config/docker-credential-fake +++ b/core/src/test/resources/auth-config/docker-credential-fake @@ -10,10 +10,6 @@ if [ "$inputLine" = "registry2.example.com" ]; then echo Fake credentials not found on credentials store \'$inputLine\' 0>&2 exit 1 fi -if [ "$inputLine" = "https://not.a.real.registry/url" ]; then - echo Fake credentials not found on credentials store \'$inputLine\' 0>&2 - exit 1 -fi if [ "$inputLine" = "registry.example.com" ]; then echo '{' \ diff --git a/core/src/test/resources/auth-config/win/docker-credential-fake.bat b/core/src/test/resources/auth-config/win/docker-credential-fake.bat index 989332cce65..afb4c66f1c6 100644 --- a/core/src/test/resources/auth-config/win/docker-credential-fake.bat +++ b/core/src/test/resources/auth-config/win/docker-credential-fake.bat @@ -9,10 +9,6 @@ if "%inputLine%" == "registry2.example.com" ( echo Fake credentials not found on credentials store '%inputLine%' 0>&2 exit 1 ) -if "%inputLine%" == "https://not.a.real.registry/url" ( - echo Fake credentials not found on credentials store '%inputLine%' 0>&2 - exit 1 -) if "%inputLine%" == "registry.example.com" ( echo {