From 9811cc030fd62c41eee990c32b6d88d458c996f9 Mon Sep 17 00:00:00 2001 From: Scott Frederick Date: Wed, 27 Sep 2023 10:09:44 -0500 Subject: [PATCH] Fix LifecycleTests for security options on Windows Fixes gh-37598 --- .../boot/buildpack/platform/build/LifecycleTests.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/LifecycleTests.java b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/LifecycleTests.java index f55e0ed5cd..6f898d1a98 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/LifecycleTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/LifecycleTests.java @@ -262,7 +262,7 @@ class LifecycleTests { given(this.docker.container().wait(any())).willReturn(ContainerStatus.of(0, null)); BuildRequest request = getTestRequest().withSecurityOptions(List.of("label=user:USER", "label=role:ROLE")); createLifecycle(request).execute(); - assertPhaseWasRun("creator", withExpectedConfig("lifecycle-creator-security-opts.json")); + assertPhaseWasRun("creator", withExpectedConfig("lifecycle-creator-security-opts.json", true)); assertThat(this.out.toString()).contains("Successfully built image 'docker.io/library/my-application:latest'"); } @@ -370,12 +370,16 @@ class LifecycleTests { } private IOConsumer withExpectedConfig(String name) { + return withExpectedConfig(name, false); + } + + private IOConsumer withExpectedConfig(String name, boolean expectSecurityOptAlways) { return (config) -> { try { InputStream in = getClass().getResourceAsStream(name); String jsonString = FileCopyUtils.copyToString(new InputStreamReader(in, StandardCharsets.UTF_8)); JSONObject json = new JSONObject(jsonString); - if (Platform.isWindows()) { + if (!expectSecurityOptAlways && Platform.isWindows()) { JSONObject hostConfig = json.getJSONObject("HostConfig"); hostConfig.remove("SecurityOpt"); }