Skip to content

Commit 1facaf0

Browse files
authored
Remove extra call to docker credentials (#9545)
In #9544, proper process execution handling was introduced in order to manage error messages correctly.
1 parent c68f791 commit 1facaf0

File tree

4 files changed

+7
-47
lines changed

4 files changed

+7
-47
lines changed

core/src/main/java/org/testcontainers/utility/RegistryAuthLocator.java

Lines changed: 6 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,10 @@ private AuthConfig runCredentialProvider(String hostName, String helperOrStoreNa
289289
final String responseErrorMsg = data.getStdout();
290290

291291
if (!StringUtils.isBlank(responseErrorMsg)) {
292-
String credentialsNotFoundMsg = getGenericCredentialsNotFoundMsg(credentialProgramName);
292+
String credentialsNotFoundMsg = getGenericCredentialsNotFoundMsg(
293+
responseErrorMsg,
294+
credentialProgramName
295+
);
293296
if (credentialsNotFoundMsg != null && credentialsNotFoundMsg.equals(responseErrorMsg)) {
294297
log.info(
295298
"Credential helper/store ({}) does not have credentials for {}",
@@ -346,48 +349,13 @@ private String effectiveRegistryName(DockerImageName dockerImageName) {
346349
);
347350
}
348351

349-
private String getGenericCredentialsNotFoundMsg(String credentialHelperName) {
352+
private String getGenericCredentialsNotFoundMsg(String credentialsNotFoundMsg, String credentialHelperName) {
350353
if (!CREDENTIALS_HELPERS_NOT_FOUND_MESSAGE_CACHE.containsKey(credentialHelperName)) {
351-
String credentialsNotFoundMsg = discoverCredentialsHelperNotFoundMessage(credentialHelperName);
352-
if (!StringUtils.isBlank(credentialsNotFoundMsg)) {
353-
CREDENTIALS_HELPERS_NOT_FOUND_MESSAGE_CACHE.put(credentialHelperName, credentialsNotFoundMsg);
354-
}
354+
CREDENTIALS_HELPERS_NOT_FOUND_MESSAGE_CACHE.put(credentialHelperName, credentialsNotFoundMsg);
355355
}
356-
357356
return CREDENTIALS_HELPERS_NOT_FOUND_MESSAGE_CACHE.get(credentialHelperName);
358357
}
359358

360-
private String discoverCredentialsHelperNotFoundMessage(String credentialHelperName) {
361-
// will do fake call to given credential helper to find out with which message
362-
// it response when there are no credentials for given hostName
363-
364-
// hostName should be valid, but most probably not existing
365-
// IF its not enough, then should probably run 'list' command first to be sure...
366-
final String notExistentFakeHostName = "https://not.a.real.registry/url";
367-
368-
String credentialsNotFoundMsg = null;
369-
try {
370-
CredentialOutput data = runCredentialProgram(notExistentFakeHostName, credentialHelperName);
371-
372-
if (data.getStdout() != null && !data.getStdout().isEmpty()) {
373-
credentialsNotFoundMsg = data.getStdout();
374-
375-
log.debug(
376-
"Got credentials not found error message from docker credential helper - {}",
377-
credentialsNotFoundMsg
378-
);
379-
}
380-
} catch (Exception e) {
381-
log.warn(
382-
"Failure running docker credential helper ({}) with fake call, expected 'credentials not found' response. Exception message: {}",
383-
credentialHelperName,
384-
e.getMessage()
385-
);
386-
}
387-
388-
return credentialsNotFoundMsg;
389-
}
390-
391359
private CredentialOutput runCredentialProgram(String hostName, String credentialHelperName)
392360
throws InterruptedException, TimeoutException, IOException {
393361
String[] command = SystemUtils.IS_OS_WINDOWS

core/src/test/java/org/testcontainers/utility/RegistryAuthLocatorTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ public void lookupAuthConfigWithCredentialsNotFound() throws URISyntaxException,
241241

242242
assertThat(discoveredMessage)
243243
.as("Not correct message discovered")
244-
.isEqualTo("Fake credentials not found on credentials store 'https://not.a.real.registry/url'");
244+
.isEqualTo("Fake credentials not found on credentials store 'registry2.example.com'");
245245
}
246246

247247
@Test

core/src/test/resources/auth-config/docker-credential-fake

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@ if [ "$inputLine" = "registry2.example.com" ]; then
1010
echo Fake credentials not found on credentials store \'$inputLine\' 0>&2
1111
exit 1
1212
fi
13-
if [ "$inputLine" = "https://not.a.real.registry/url" ]; then
14-
echo Fake credentials not found on credentials store \'$inputLine\' 0>&2
15-
exit 1
16-
fi
1713

1814
if [ "$inputLine" = "registry.example.com" ]; then
1915
echo '{' \

core/src/test/resources/auth-config/win/docker-credential-fake.bat

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ if "%inputLine%" == "registry2.example.com" (
99
echo Fake credentials not found on credentials store '%inputLine%' 0>&2
1010
exit 1
1111
)
12-
if "%inputLine%" == "https://not.a.real.registry/url" (
13-
echo Fake credentials not found on credentials store '%inputLine%' 0>&2
14-
exit 1
15-
)
1612

1713
if "%inputLine%" == "registry.example.com" (
1814
echo {

0 commit comments

Comments
 (0)