From 4f7de1c8899c64cb3e0798e6bf36d3d844a2d07e Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Fri, 8 Nov 2024 23:58:48 -0800 Subject: [PATCH] Fix `SslOptions.isSpecified()` logic Prior to this commit `SslOptions.isSpecified()` only returned `true` if both ciphers and enabled protocols were set. If should have returned `true` if either were set. Fixes gh-43082 --- .../springframework/boot/ssl/SslOptions.java | 2 +- .../boot/ssl/SslOptionsTests.java | 20 ++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/ssl/SslOptions.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/ssl/SslOptions.java index d45e9163a34..5ae5d952ff0 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/ssl/SslOptions.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/ssl/SslOptions.java @@ -45,7 +45,7 @@ public interface SslOptions { * @return {@code true} if SSL options have been specified */ default boolean isSpecified() { - return (getCiphers() != null) && (getEnabledProtocols() != null); + return (getCiphers() != null) || (getEnabledProtocols() != null); } /** diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/ssl/SslOptionsTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/ssl/SslOptionsTests.java index 513fa2b7fd3..2e374fb4774 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/ssl/SslOptionsTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/ssl/SslOptionsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -72,4 +72,22 @@ class SslOptionsTests { assertThat(options.getEnabledProtocols()).isNull(); } + @Test + void isSpecifiedWhenHasCiphers() { + SslOptions options = SslOptions.of(Set.of("a", "b", "c"), null); + assertThat(options.isSpecified()).isTrue(); + } + + @Test + void isSpecifiedWhenHasEnabledProtocols() { + SslOptions options = SslOptions.of(null, Set.of("d", "e", "f")); + assertThat(options.isSpecified()).isTrue(); + } + + @Test + void isSpecifiedWhenHasNoCiphersOrEnabledProtocols() { + SslOptions options = SslOptions.NONE; + assertThat(options.isSpecified()).isFalse(); + } + }