Skip to content

Commit

Permalink
Add Metadata Content Type Test
Browse files Browse the repository at this point in the history
Issue gh-15147
  • Loading branch information
jzheaux committed Jun 21, 2024
1 parent a529607 commit 672902a
Showing 1 changed file with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-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.
Expand Down Expand Up @@ -29,6 +29,8 @@
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.security.saml2.core.TestSaml2X509Credentials;
import org.springframework.security.saml2.provider.service.metadata.Saml2MetadataResolver;
import org.springframework.security.saml2.provider.service.metadata.Saml2MetadataResponse;
import org.springframework.security.saml2.provider.service.metadata.Saml2MetadataResponseResolver;
import org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistration;
import org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistrationRepository;
import org.springframework.security.saml2.provider.service.registration.TestRelyingPartyRegistrations;
Expand Down Expand Up @@ -111,6 +113,19 @@ public void doFilterWhenRelyingPartyRegistrationFoundThenInvokesMetadataResolver
verify(this.resolver).resolve(validRegistration);
}

@Test
public void doFilterWhenMatchesThenRespondsWithMetadata() throws Exception {
Saml2MetadataResponse metadata = new Saml2MetadataResponse("<xml/>", "metadata.xml");
Saml2MetadataResponseResolver resolver = mock(Saml2MetadataResponseResolver.class);
given(resolver.resolve(this.request)).willReturn(metadata);
Saml2MetadataFilter filter = new Saml2MetadataFilter(resolver);
filter.doFilter(this.request, this.response, this.chain);
assertThat(this.response.getContentType()).isEqualTo("application/samlmetadata+xml;charset=UTF-8");
assertThat(this.response.getContentAsString()).isEqualTo("<xml/>");
assertThat(this.response.getHeaderValue(HttpHeaders.CONTENT_DISPOSITION)).asString()
.isEqualTo("attachment; filename=\"metadata.xml\"; filename*=UTF-8''metadata.xml");
}

@Test
public void doFilterWhenCustomRequestMatcherThenUses() throws Exception {
this.request.setPathInfo("/path");
Expand Down

0 comments on commit 672902a

Please sign in to comment.