From 969d1774ed2b2c1e28df2272212adeece492b971 Mon Sep 17 00:00:00 2001 From: Moritz Halbritter Date: Wed, 15 Oct 2025 12:30:13 +0200 Subject: [PATCH] Add nullability annotations to tests in module/spring-boot-security-saml2 See gh-47263 --- .../spring-boot-security-saml2/build.gradle | 4 ++ ...ml2RelyingPartyAutoConfigurationTests.java | 4 +- .../Saml2RelyingPartyPropertiesTests.java | 45 +++++++++---------- 3 files changed, 29 insertions(+), 24 deletions(-) diff --git a/module/spring-boot-security-saml2/build.gradle b/module/spring-boot-security-saml2/build.gradle index 52a9fda8c30..49d724af0a4 100644 --- a/module/spring-boot-security-saml2/build.gradle +++ b/module/spring-boot-security-saml2/build.gradle @@ -45,3 +45,7 @@ dependencies { testRuntimeOnly("ch.qos.logback:logback-classic") } + +tasks.named("compileTestJava") { + options.nullability.checking = "tests" +} diff --git a/module/spring-boot-security-saml2/src/test/java/org/springframework/boot/security/saml2/autoconfigure/Saml2RelyingPartyAutoConfigurationTests.java b/module/spring-boot-security-saml2/src/test/java/org/springframework/boot/security/saml2/autoconfigure/Saml2RelyingPartyAutoConfigurationTests.java index ed24408901f..5b80db576d4 100644 --- a/module/spring-boot-security-saml2/src/test/java/org/springframework/boot/security/saml2/autoconfigure/Saml2RelyingPartyAutoConfigurationTests.java +++ b/module/spring-boot-security-saml2/src/test/java/org/springframework/boot/security/saml2/autoconfigure/Saml2RelyingPartyAutoConfigurationTests.java @@ -23,6 +23,7 @@ import jakarta.servlet.Filter; import okhttp3.mockwebserver.MockResponse; import okhttp3.mockwebserver.MockWebServer; import okio.Buffer; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.springframework.boot.autoconfigure.AutoConfigurations; @@ -344,7 +345,7 @@ class Saml2RelyingPartyAutoConfigurationTests { .doesNotHaveBean(MANAGEMENT_SECURITY_FILTER_CHAIN_BEAN)); } - private void testMultipleProviders(String specifiedEntityId, String expected) throws Exception { + private void testMultipleProviders(@Nullable String specifiedEntityId, String expected) throws Exception { try (MockWebServer server = new MockWebServer()) { server.start(); String metadataUrl = server.url("").toString(); @@ -413,6 +414,7 @@ class Saml2RelyingPartyAutoConfigurationTests { } if (filter instanceof CompositeFilter) { List filters = (List) ReflectionTestUtils.getField(filter, "filters"); + assertThat(filters).isNotNull(); return (FilterChainProxy) filters.stream() .filter(FilterChainProxy.class::isInstance) .findFirst() diff --git a/module/spring-boot-security-saml2/src/test/java/org/springframework/boot/security/saml2/autoconfigure/Saml2RelyingPartyPropertiesTests.java b/module/spring-boot-security-saml2/src/test/java/org/springframework/boot/security/saml2/autoconfigure/Saml2RelyingPartyPropertiesTests.java index 8c5d184a33c..8ed759deb25 100644 --- a/module/spring-boot-security-saml2/src/test/java/org/springframework/boot/security/saml2/autoconfigure/Saml2RelyingPartyPropertiesTests.java +++ b/module/spring-boot-security-saml2/src/test/java/org/springframework/boot/security/saml2/autoconfigure/Saml2RelyingPartyPropertiesTests.java @@ -25,6 +25,7 @@ import org.springframework.boot.context.properties.bind.Bindable; import org.springframework.boot.context.properties.bind.Binder; import org.springframework.boot.context.properties.source.ConfigurationPropertySource; import org.springframework.boot.context.properties.source.MapConfigurationPropertySource; +import org.springframework.boot.security.saml2.autoconfigure.Saml2RelyingPartyProperties.Registration; import org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistration; import org.springframework.security.saml2.provider.service.registration.Saml2MessageBinding; @@ -44,8 +45,9 @@ class Saml2RelyingPartyPropertiesTests { void customizeSsoUrl() { bind("spring.security.saml2.relyingparty.registration.simplesamlphp.assertingparty.single-sign-on.url", "https://simplesaml-for-spring-saml/SSOService.php"); - assertThat( - this.properties.getRegistration().get("simplesamlphp").getAssertingparty().getSinglesignon().getUrl()) + Registration registration = this.properties.getRegistration().get("simplesamlphp"); + assertThat(registration).isNotNull(); + assertThat(registration.getAssertingparty().getSinglesignon().getUrl()) .isEqualTo("https://simplesaml-for-spring-saml/SSOService.php"); } @@ -53,30 +55,27 @@ class Saml2RelyingPartyPropertiesTests { void customizeSsoBinding() { bind("spring.security.saml2.relyingparty.registration.simplesamlphp.assertingparty.single-sign-on.binding", "post"); - assertThat(this.properties.getRegistration() - .get("simplesamlphp") - .getAssertingparty() - .getSinglesignon() - .getBinding()).isEqualTo(Saml2MessageBinding.POST); + Registration registration = this.properties.getRegistration().get("simplesamlphp"); + assertThat(registration).isNotNull(); + assertThat(registration.getAssertingparty().getSinglesignon().getBinding()).isEqualTo(Saml2MessageBinding.POST); } @Test void customizeSsoSignRequests() { bind("spring.security.saml2.relyingparty.registration.simplesamlphp.assertingparty.single-sign-on.sign-request", "false"); - assertThat(this.properties.getRegistration() - .get("simplesamlphp") - .getAssertingparty() - .getSinglesignon() - .getSignRequest()).isFalse(); + Registration registration = this.properties.getRegistration().get("simplesamlphp"); + assertThat(registration).isNotNull(); + assertThat(registration.getAssertingparty().getSinglesignon().getSignRequest()).isFalse(); } @Test void customizeRelyingPartyEntityId() { bind("spring.security.saml2.relyingparty.registration.simplesamlphp.entity-id", "{baseUrl}/saml2/custom-entity-id"); - assertThat(this.properties.getRegistration().get("simplesamlphp").getEntityId()) - .isEqualTo("{baseUrl}/saml2/custom-entity-id"); + Registration registration = this.properties.getRegistration().get("simplesamlphp"); + assertThat(registration).isNotNull(); + assertThat(registration.getEntityId()).isEqualTo("{baseUrl}/saml2/custom-entity-id"); } @Test @@ -89,25 +88,25 @@ class Saml2RelyingPartyPropertiesTests { void customizeAssertingPartyMetadataUri() { bind("spring.security.saml2.relyingparty.registration.simplesamlphp.assertingparty.metadata-uri", "https://idp.example.org/metadata"); - assertThat(this.properties.getRegistration().get("simplesamlphp").getAssertingparty().getMetadataUri()) - .isEqualTo("https://idp.example.org/metadata"); + Registration registration = this.properties.getRegistration().get("simplesamlphp"); + assertThat(registration).isNotNull(); + assertThat(registration.getAssertingparty().getMetadataUri()).isEqualTo("https://idp.example.org/metadata"); } @Test void customizeSsoSignRequestsIsNullByDefault() { this.properties.getRegistration().put("simplesamlphp", new Saml2RelyingPartyProperties.Registration()); - assertThat(this.properties.getRegistration() - .get("simplesamlphp") - .getAssertingparty() - .getSinglesignon() - .getSignRequest()).isNull(); + Registration registration = this.properties.getRegistration().get("simplesamlphp"); + assertThat(registration).isNotNull(); + assertThat(registration.getAssertingparty().getSinglesignon().getSignRequest()).isNull(); } @Test void customizeNameIdFormat() { bind("spring.security.saml2.relyingparty.registration.simplesamlphp.name-id-format", "sampleNameIdFormat"); - assertThat(this.properties.getRegistration().get("simplesamlphp").getNameIdFormat()) - .isEqualTo("sampleNameIdFormat"); + Registration registration = this.properties.getRegistration().get("simplesamlphp"); + assertThat(registration).isNotNull(); + assertThat(registration.getNameIdFormat()).isEqualTo("sampleNameIdFormat"); } private void bind(String name, String value) {