Skip to content

Commit

Permalink
Fix NPE when reading "auths" section in ~/.docker/config.json (#2536)
Browse files Browse the repository at this point in the history
  • Loading branch information
chanseokoh authored Jun 22, 2020
1 parent cb78087 commit 38ea51b
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 2 deletions.
2 changes: 2 additions & 0 deletions jib-core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ All notable changes to this project will be documented in this file.

### Fixed

- Fixed `NullPointerException` when the `"auths":` section in `~/.docker/config.json` has an entry with no `"auth":` field. ([#2535](https://github.com/GoogleContainerTools/jib/issues/2535))

## 0.15.0

### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ Optional<Credential> retrieve(DockerConfig dockerConfig, Consumer<LogEvent> logg

// Lastly, find defined auth.
AuthTemplate auth = dockerConfig.getAuthFor(registryAlias);
if (auth != null) {
if (auth != null && auth.getAuth() != null) {
// 'auth' is a basic authentication token that should be parsed back into credentials
String usernameColonPassword =
new String(Base64.decodeBase64(auth.getAuth()), StandardCharsets.UTF_8);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,4 +194,15 @@ public void testRetrieve_azureIdentityToken() throws IOException, URISyntaxExcep
Assert.assertEquals("<token>", credentials.get().getUsername());
Assert.assertEquals("cool identity token", credentials.get().getPassword());
}

@Test
public void testRetrieve_noErrorWhenMissingAuthField() throws IOException, URISyntaxException {
Path dockerConfigFile = Paths.get(Resources.getResource("core/json/dockerconfig.json").toURI());

DockerConfigCredentialRetriever dockerConfigCredentialRetriever =
DockerConfigCredentialRetriever.create("no auth field", dockerConfigFile);

Optional<Credential> credentials = dockerConfigCredentialRetriever.retrieve(mockLogger);
Assert.assertFalse(credentials.isPresent());
}
}
3 changes: 2 additions & 1 deletion jib-core/src/test/resources/core/json/dockerconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"some registry":{"auth":"c29tZTphdXRo","password":"ignored"},
"https://registry":{"auth":"dG9rZW4="},

"example.com":{"auth":"should not match example"}
"example.com":{"auth":"should not match example"},
"no auth field":{}
},
"credsStore":"some credential store",
"credHelpers":{
Expand Down
1 change: 1 addition & 0 deletions jib-gradle-plugin/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ All notable changes to this project will be documented in this file.
### Fixed

- Fixed reporting a wrong credential helper name when the helper does not exist on Windows. ([#2527](https://github.com/GoogleContainerTools/jib/issues/2527))
- Fixed `NullPointerException` when the `"auths":` section in `~/.docker/config.json` has an entry with no `"auth":` field. ([#2535](https://github.com/GoogleContainerTools/jib/issues/2535))

## 2.4.0

Expand Down
1 change: 1 addition & 0 deletions jib-maven-plugin/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ All notable changes to this project will be documented in this file.
### Fixed

- Fixed reporting a wrong credential helper name when the helper does not exist on Windows. ([#2527](https://github.com/GoogleContainerTools/jib/issues/2527))
- Fixed `NullPointerException` when the `"auths":` section in `~/.docker/config.json` has an entry with no `"auth":` field. ([#2535](https://github.com/GoogleContainerTools/jib/issues/2535))

## 2.4.0

Expand Down

0 comments on commit 38ea51b

Please sign in to comment.