Browse Source

Add nullability annotations to tests in module/spring-boot-security-saml2

See gh-47263
pull/47637/head
Moritz Halbritter 2 months ago
parent
commit
969d1774ed
  1. 4
      module/spring-boot-security-saml2/build.gradle
  2. 4
      module/spring-boot-security-saml2/src/test/java/org/springframework/boot/security/saml2/autoconfigure/Saml2RelyingPartyAutoConfigurationTests.java
  3. 45
      module/spring-boot-security-saml2/src/test/java/org/springframework/boot/security/saml2/autoconfigure/Saml2RelyingPartyPropertiesTests.java

4
module/spring-boot-security-saml2/build.gradle

@ -45,3 +45,7 @@ dependencies { @@ -45,3 +45,7 @@ dependencies {
testRuntimeOnly("ch.qos.logback:logback-classic")
}
tasks.named("compileTestJava") {
options.nullability.checking = "tests"
}

4
module/spring-boot-security-saml2/src/test/java/org/springframework/boot/security/saml2/autoconfigure/Saml2RelyingPartyAutoConfigurationTests.java

@ -23,6 +23,7 @@ import jakarta.servlet.Filter; @@ -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 { @@ -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 { @@ -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()

45
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; @@ -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 { @@ -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 { @@ -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 { @@ -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) {

Loading…
Cancel
Save