|
1 | 1 | /*
|
2 |
| - * Copyright 2012-2020 the original author or authors. |
| 2 | + * Copyright 2012-2021 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
@@ -308,6 +308,42 @@ void buildWhenBuilderReturnsErrorThrowsException() throws Exception {
|
308 | 308 | .withMessage("Builder lifecycle 'creator' failed with status code 9");
|
309 | 309 | }
|
310 | 310 |
|
| 311 | + @Test |
| 312 | + void buildWhenDetectedRunImageInDifferentAuthenticatedRegistryThrowsException() throws Exception { |
| 313 | + TestPrintStream out = new TestPrintStream(); |
| 314 | + DockerApi docker = mockDockerApi(); |
| 315 | + Image builderImage = loadImage("image-with-run-image-different-registry.json"); |
| 316 | + DockerConfiguration dockerConfiguration = new DockerConfiguration() |
| 317 | + .withBuilderRegistryTokenAuthentication("builder token"); |
| 318 | + given(docker.image().pull(eq(ImageReference.of(BuildRequest.DEFAULT_BUILDER_IMAGE_NAME)), any(), |
| 319 | + eq(dockerConfiguration.getBuilderRegistryAuthentication().getAuthHeader()))) |
| 320 | + .willAnswer(withPulledImage(builderImage)); |
| 321 | + Builder builder = new Builder(BuildLog.to(out), docker, dockerConfiguration); |
| 322 | + BuildRequest request = getTestRequest(); |
| 323 | + assertThatIllegalStateException().isThrownBy(() -> builder.build(request)) |
| 324 | + .withMessageContaining(BuildRequest.DEFAULT_BUILDER_IMAGE_NAME) |
| 325 | + .withMessageContaining("example.com/custom/run:latest") |
| 326 | + .withMessageContaining("must be pulled from the same authenticated registry"); |
| 327 | + } |
| 328 | + |
| 329 | + @Test |
| 330 | + void buildWhenRequestedRunImageInDifferentAuthenticatedRegistryThrowsException() throws Exception { |
| 331 | + TestPrintStream out = new TestPrintStream(); |
| 332 | + DockerApi docker = mockDockerApi(); |
| 333 | + Image builderImage = loadImage("image.json"); |
| 334 | + DockerConfiguration dockerConfiguration = new DockerConfiguration() |
| 335 | + .withBuilderRegistryTokenAuthentication("builder token"); |
| 336 | + given(docker.image().pull(eq(ImageReference.of(BuildRequest.DEFAULT_BUILDER_IMAGE_NAME)), any(), |
| 337 | + eq(dockerConfiguration.getBuilderRegistryAuthentication().getAuthHeader()))) |
| 338 | + .willAnswer(withPulledImage(builderImage)); |
| 339 | + Builder builder = new Builder(BuildLog.to(out), docker, dockerConfiguration); |
| 340 | + BuildRequest request = getTestRequest().withRunImage(ImageReference.of("example.com/custom/run:latest")); |
| 341 | + assertThatIllegalStateException().isThrownBy(() -> builder.build(request)) |
| 342 | + .withMessageContaining(BuildRequest.DEFAULT_BUILDER_IMAGE_NAME) |
| 343 | + .withMessageContaining("example.com/custom/run:latest") |
| 344 | + .withMessageContaining("must be pulled from the same authenticated registry"); |
| 345 | + } |
| 346 | + |
311 | 347 | private DockerApi mockDockerApi() throws IOException {
|
312 | 348 | ContainerApi containerApi = mock(ContainerApi.class);
|
313 | 349 | ContainerReference reference = ContainerReference.of("container-ref");
|
|
0 commit comments