|
16 | 16 |
|
17 | 17 | package org.springframework.security.saml2.provider.service.web;
|
18 | 18 |
|
| 19 | +import java.io.IOException; |
| 20 | +import java.nio.charset.StandardCharsets; |
19 | 21 | import javax.servlet.http.HttpServletRequest;
|
20 | 22 |
|
21 | 23 | import org.junit.Test;
|
|
24 | 26 | import org.mockito.junit.MockitoJUnitRunner;
|
25 | 27 |
|
26 | 28 | import org.springframework.core.convert.converter.Converter;
|
| 29 | +import org.springframework.core.io.ClassPathResource; |
27 | 30 | import org.springframework.mock.web.MockHttpServletRequest;
|
28 | 31 | import org.springframework.security.saml2.core.Saml2Utils;
|
29 | 32 | import org.springframework.security.saml2.provider.service.authentication.Saml2AuthenticationToken;
|
30 | 33 | import org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistration;
|
| 34 | +import org.springframework.util.StreamUtils; |
| 35 | +import org.springframework.web.util.UriUtils; |
31 | 36 |
|
32 | 37 | import static java.nio.charset.StandardCharsets.UTF_8;
|
33 | 38 | import static org.assertj.core.api.Assertions.assertThat;
|
@@ -99,4 +104,29 @@ public void constructorWhenResolverIsNullThenIllegalArgument() {
|
99 | 104 | assertThatCode(() -> new Saml2AuthenticationTokenConverter(null))
|
100 | 105 | .isInstanceOf(IllegalArgumentException.class);
|
101 | 106 | }
|
| 107 | + |
| 108 | + @Test |
| 109 | + public void convertWhenUsingSamlUtilsBase64ThenXmlIsValid() throws Exception { |
| 110 | + Saml2AuthenticationTokenConverter converter = new Saml2AuthenticationTokenConverter |
| 111 | + (this.relyingPartyRegistrationResolver); |
| 112 | + when(this.relyingPartyRegistrationResolver.convert(any(HttpServletRequest.class))) |
| 113 | + .thenReturn(this.relyingPartyRegistration); |
| 114 | + MockHttpServletRequest request = new MockHttpServletRequest(); |
| 115 | + request.setParameter("SAMLResponse", getSsoCircleEncodedXml()); |
| 116 | + Saml2AuthenticationToken token = converter.convert(request); |
| 117 | + validateSsoCircleXml(token.getSaml2Response()); |
| 118 | + } |
| 119 | + |
| 120 | + private void validateSsoCircleXml(String xml) { |
| 121 | + assertThat(xml) |
| 122 | + .contains("InResponseTo=\"ARQ9a73ead-7dcf-45a8-89eb-26f3c9900c36\"") |
| 123 | + .contains(" ID=\"s246d157446618e90e43fb79bdd4d9e9e19cf2c7c4\"") |
| 124 | + .contains("<saml:Issuer>https://idp.ssocircle.com</saml:Issuer>"); |
| 125 | + } |
| 126 | + |
| 127 | + private String getSsoCircleEncodedXml() throws IOException { |
| 128 | + ClassPathResource resource = new ClassPathResource("saml2-response-sso-circle.encoded"); |
| 129 | + String response = StreamUtils.copyToString(resource.getInputStream(), StandardCharsets.UTF_8); |
| 130 | + return UriUtils.decode(response, UTF_8); |
| 131 | + } |
102 | 132 | }
|
0 commit comments