Skip to content

Commit

Permalink
CredsStore validation for RegistryAuthLocator (#1303)
Browse files Browse the repository at this point in the history
 ## Fixes
`RegistryAuthLocator` : Add additional validation for existing key `credsStore` but empty value

## Purpose
Define behaviour for RegistryAuthLocator on empty values in config

Offer: 
 - fail on empty value
 - ignore field with empty value & log -> return null;

## Background Context
Currently experienced problems using testcontainers, I found existing issue for my problem and decided to help. 
Potentially, put checks for all existing `keys` with empty strings

## References
ref: #921
  • Loading branch information
zhenik authored and rnorth committed Mar 18, 2019
1 parent 43e971f commit c03a22b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ private AuthConfig authConfigUsingStore(final JsonNode config, final String repo
final JsonNode credsStoreNode = config.get("credsStore");
if (credsStoreNode != null && !credsStoreNode.isMissingNode() && credsStoreNode.isTextual()) {
final String credsStore = credsStoreNode.asText();
if (isBlank(credsStore)) {
log.warn("Docker auth config credsStore field will be ignored, because value is blank");
return null;
}
return runCredentialProvider(reposName, credsStore);
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,16 @@ public void lookupAuthConfigWithCredentialsNotFound() throws URISyntaxException
discoveredMessage);
}

@Test
public void lookupAuthConfigWithCredStoreEmpty() throws URISyntaxException {
final RegistryAuthLocator authLocator = createTestAuthLocator("config-with-store-empty.json");

DockerImageName dockerImageName = new DockerImageName("registry2.example.com/org/repo");
final AuthConfig authConfig = authLocator.lookupAuthConfig(dockerImageName, new AuthConfig());

assertNull("CredStore field will be ignored, because value is blank", authConfig.getAuth());
}

@NotNull
private RegistryAuthLocator createTestAuthLocator(String configName) throws URISyntaxException {
return createTestAuthLocator(configName, new HashMap<>());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"auths": {
"registry.example.com": {}
},
"HttpHeaders": {
"User-Agent": "Docker-Client/18.03.0-ce (darwin)"
},
"credsStore": ""
}

0 comments on commit c03a22b

Please sign in to comment.