Skip to content
This repository has been archived by the owner on Mar 21, 2022. It is now read-only.

Commit

Permalink
Merge pull request #783 from spotify/mattbrown/fix-npe-multiauth
Browse files Browse the repository at this point in the history
fix NPE in MultiRegistryAuthSupplier
  • Loading branch information
mattnworb authored Jun 5, 2017
2 parents 4d3a4a6 + aa8a023 commit e9e3bdc
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## 8.7.1

### Bugfixes

Fix NPE in MultiRegistryAuthSupplier ([783][])

[783]: https://github.com/spotify/docker-client/pull/783

## 8.7.0

Released June 5, 2017
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ public RegistryConfigs authForBuild() throws DockerException {
// have precedence
for (RegistryAuthSupplier supplier : Lists.reverse(suppliers)) {
final RegistryConfigs configs = supplier.authForBuild();
allConfigs.putAll(configs.configs());
if (configs != null && configs.configs() != null) {
allConfigs.putAll(configs.configs());
}
}
return RegistryConfigs.create(allConfigs);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public interface RegistryAuthSupplier {
* Returns a RegistryAuth object that is valid for a Docker Swarm context [i.e. not tied
* to specific image]. It's unnecessary if it's not planned to use this AuthSupplier to pull
* images for Swarm.
*
* @return the RegistryAuth to use in Swarn, or else {@code null} for no authentication info
*/
RegistryAuth authForSwarm() throws DockerException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ public void testAuthForBuild() throws Exception {
"b", auth2
)));

//
when(supplier2.authForBuild()).thenReturn(RegistryConfigs.create(ImmutableMap.of(
"b", auth3,
"c", auth4
Expand All @@ -124,4 +123,29 @@ public void testAuthForBuild() throws Exception {
hasEntry("c", auth4)
));
}

/**
* Test what happens if one of the Suppliers returns null for authForBuild().
*/
@Test
public void testAuthForBuild_ReturnsNull() throws Exception {

when(supplier1.authForBuild()).thenReturn(null);

final RegistryConfigs registryConfigs = RegistryConfigs.create(ImmutableMap.of(
"a",
RegistryAuth.builder()
.username("1")
.serverAddress("a")
.build(),
"b",
RegistryAuth.builder()
.username("2")
.serverAddress("b")
.build()
));
when(supplier2.authForBuild()).thenReturn(registryConfigs);

assertThat(multiSupplier.authForBuild(), is(registryConfigs));
}
}

0 comments on commit e9e3bdc

Please sign in to comment.