Polish Test

Issue gh-9281
This commit is contained in:
Josh Cummings 2021-03-02 08:24:00 -07:00
parent c0fa3f906d
commit 3e8ad4bc2b
No known key found for this signature in database
GPG Key ID: 49EF60DD7FF83443
1 changed files with 16 additions and 26 deletions

View File

@ -120,6 +120,22 @@ public class Saml2MetadataFilterTests {
verify(this.repository).findByRegistrationId("path"); verify(this.repository).findByRegistrationId("path");
} }
@Test
public void doFilterWhenSetMetadataFilenameThenUses() throws Exception {
RelyingPartyRegistration validRegistration = TestRelyingPartyRegistrations.full().build();
String testMetadataFilename = "test-{registrationId}-metadata.xml";
String fileName = testMetadataFilename.replace("{registrationId}", validRegistration.getRegistrationId());
String encodedFileName = URLEncoder.encode(fileName, StandardCharsets.UTF_8.name());
String generatedMetadata = "<xml>test</xml>";
this.request.setPathInfo("/saml2/service-provider-metadata/validRegistration");
given(this.resolver.resolve(validRegistration)).willReturn(generatedMetadata);
this.filter = new Saml2MetadataFilter((request) -> validRegistration, this.resolver);
this.filter.setMetadataFilename(testMetadataFilename);
this.filter.doFilter(this.request, this.response, this.chain);
assertThat(this.response.getHeaderValue(HttpHeaders.CONTENT_DISPOSITION)).asString()
.isEqualTo("attachment; filename=\"%s\"; filename*=UTF-8''%s", fileName, encodedFileName);
}
@Test @Test
public void setRequestMatcherWhenNullThenIllegalArgument() { public void setRequestMatcherWhenNullThenIllegalArgument() {
assertThatIllegalArgumentException().isThrownBy(() -> this.filter.setRequestMatcher(null)); assertThatIllegalArgumentException().isThrownBy(() -> this.filter.setRequestMatcher(null));
@ -138,30 +154,4 @@ public class Saml2MetadataFilterTests {
.withMessage("metadataFilename must contain a {registrationId} match variable"); .withMessage("metadataFilename must contain a {registrationId} match variable");
} }
@Test
public void doFilterWhenSetMetadataFilenameThenUses() throws Exception {
String testMetadataFilename = "test-{registrationId}-metadata.xml";
this.request.setPathInfo("/saml2/service-provider-metadata/validRegistration");
RelyingPartyRegistration validRegistration = TestRelyingPartyRegistrations.noCredentials()
.assertingPartyDetails((party) -> party.verificationX509Credentials(
(c) -> c.add(TestSaml2X509Credentials.relyingPartyVerifyingCredential())))
.build();
String generatedMetadata = "<xml>test</xml>";
given(this.resolver.resolve(validRegistration)).willReturn(generatedMetadata);
this.filter = new Saml2MetadataFilter((request) -> validRegistration, this.resolver);
this.filter.setMetadataFilename(testMetadataFilename);
this.filter.doFilter(this.request, this.response, this.chain);
verifyNoInteractions(this.chain);
assertThat(this.response.getStatus()).isEqualTo(200);
assertThat(this.response.getContentAsString()).isEqualTo(generatedMetadata);
String fileName = testMetadataFilename.replace("{registrationId}", validRegistration.getRegistrationId());
String encodedFileName = URLEncoder.encode(fileName, StandardCharsets.UTF_8.name());
assertThat(this.response.getHeaderValue(HttpHeaders.CONTENT_DISPOSITION)).asString()
.isEqualTo("attachment; filename=\"%s\"; filename*=UTF-8''%s", fileName, encodedFileName);
verify(this.resolver).resolve(validRegistration);
}
} }