Skip to content

Commit fccc4ec

Browse files
Merge branch '3.2.x'
Closes gh-40871
2 parents 3858a33 + 4e5cd2c commit fccc4ec

File tree

3 files changed

+36
-6
lines changed
  • spring-boot-project/spring-boot-tools

3 files changed

+36
-6
lines changed

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootBuildImage.java

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -99,6 +99,7 @@ public BootBuildImage() {
9999
this.launchCache = getProject().getObjects().newInstance(CacheSpec.class);
100100
this.docker = getProject().getObjects().newInstance(DockerSpec.class);
101101
this.pullPolicy = getProject().getObjects().property(PullPolicy.class);
102+
getSecurityOptions().convention((Iterable<? extends String>) null);
102103
}
103104

104105
/**
@@ -464,9 +465,11 @@ private BuildRequest customizeApplicationDirectory(BuildRequest request) {
464465
}
465466

466467
private BuildRequest customizeSecurityOptions(BuildRequest request) {
467-
List<String> securityOptions = getSecurityOptions().getOrNull();
468-
if (securityOptions != null) {
469-
return request.withSecurityOptions(securityOptions);
468+
if (getSecurityOptions().isPresent()) {
469+
List<String> securityOptions = getSecurityOptions().getOrNull();
470+
if (securityOptions != null) {
471+
return request.withSecurityOptions(securityOptions);
472+
}
470473
}
471474
return request;
472475
}

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/BootBuildImageTests.java

+21-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@
1818

1919
import java.io.File;
2020
import java.util.Arrays;
21+
import java.util.Collections;
2122
import java.util.HashMap;
2223
import java.util.Map;
2324

@@ -294,4 +295,23 @@ void whenIndividualEntriesAreAddedToTagsThenRequestHasTags() {
294295
ImageReference.of("example.com/my-app:0.0.1-SNAPSHOT"), ImageReference.of("example.com/my-app:latest"));
295296
}
296297

298+
@Test
299+
void whenSecurityOptionsAreNotConfiguredThenRequestHasNoSecurityOptions() {
300+
assertThat(this.buildImage.createRequest().getSecurityOptions()).isNull();
301+
}
302+
303+
@Test
304+
void whenSecurityOptionsAreEmptyThenRequestHasEmptySecurityOptions() {
305+
this.buildImage.getSecurityOptions().set(Collections.emptyList());
306+
assertThat(this.buildImage.createRequest().getSecurityOptions()).isEmpty();
307+
}
308+
309+
@Test
310+
void whenSecurityOptionsAreConfiguredThenRequestHasSecurityOptions() {
311+
this.buildImage.getSecurityOptions().add("label=user:USER");
312+
this.buildImage.getSecurityOptions().add("label=role:ROLE");
313+
assertThat(this.buildImage.createRequest().getSecurityOptions()).containsExactly("label=user:USER",
314+
"label=role:ROLE");
315+
}
316+
297317
}

spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/ImageTests.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -235,6 +235,13 @@ void getBuildRequestWhenHasApplicationDirectoryUsesApplicationDirectory() {
235235
assertThat(request.getApplicationDirectory()).isEqualTo("/application");
236236
}
237237

238+
@Test
239+
void getBuildRequestWhenHasNoSecurityOptionsUsesNoSecurityOptions() {
240+
Image image = new Image();
241+
BuildRequest request = image.getBuildRequest(createArtifact(), mockApplicationContent());
242+
assertThat(request.getSecurityOptions()).isNull();
243+
}
244+
238245
@Test
239246
void getBuildRequestWhenHasSecurityOptionsUsesSecurityOptions() {
240247
Image image = new Image();

0 commit comments

Comments
 (0)