-
Notifications
You must be signed in to change notification settings - Fork 831
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
70019ee
commit 290f89c
Showing
6 changed files
with
144 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
...r/src/test/java/org/cloudfoundry/identity/uaa/provider/saml/SamlMetadataEndpointTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package org.cloudfoundry.identity.uaa.provider.saml; | ||
|
||
import org.cloudfoundry.identity.uaa.zone.IdentityZone; | ||
import org.cloudfoundry.identity.uaa.zone.IdentityZoneConfiguration; | ||
import org.cloudfoundry.identity.uaa.zone.SamlConfig; | ||
import org.cloudfoundry.identity.uaa.zone.beans.IdentityZoneManager; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.mock.web.MockHttpServletRequest; | ||
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.Saml2MessageBinding; | ||
|
||
import java.util.List; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.cloudfoundry.identity.uaa.provider.saml.TestSaml2X509Credentials.relyingPartySigningCredential; | ||
import static org.cloudfoundry.identity.uaa.provider.saml.TestSaml2X509Credentials.relyingPartyVerifyingCredential; | ||
import static org.mockito.Mockito.spy; | ||
import static org.mockito.Mockito.when; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class SamlMetadataEndpointTest { | ||
SamlMetadataEndpoint endpoint; | ||
|
||
MockHttpServletRequest request; | ||
|
||
@Mock | ||
RelyingPartyRegistrationRepository repository; | ||
@Mock | ||
IdentityZoneManager identityZoneManager; | ||
@Mock | ||
RelyingPartyRegistration registration; | ||
@Mock | ||
IdentityZone identityZone; | ||
@Mock | ||
IdentityZoneConfiguration identityZoneConfiguration; | ||
@Mock | ||
SamlConfig samlConfig; | ||
@Mock | ||
RelyingPartyRegistration.AssertingPartyDetails assertingPartyDetails; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
endpoint = spy(new SamlMetadataEndpoint(repository, identityZoneManager)); | ||
when(repository.findByRegistrationId("regId")).thenReturn(registration); | ||
when(registration.getEntityId()).thenReturn("entityId"); | ||
when(registration.getSigningX509Credentials()).thenReturn(List.of(relyingPartySigningCredential())); | ||
when(registration.getDecryptionX509Credentials()).thenReturn(List.of(relyingPartyVerifyingCredential())); | ||
when(registration.getAssertionConsumerServiceBinding()).thenReturn(Saml2MessageBinding.REDIRECT); | ||
when(registration.getAssertionConsumerServiceLocation()).thenReturn("acsl"); | ||
when(identityZoneManager.getCurrentIdentityZone()).thenReturn(identityZone); | ||
when(identityZone.getConfig()).thenReturn(identityZoneConfiguration); | ||
when(identityZoneConfiguration.getSamlConfig()).thenReturn(samlConfig); | ||
when(registration.getAssertingPartyDetails()).thenReturn(assertingPartyDetails); | ||
} | ||
|
||
@Test | ||
void testDefaultFileName() { | ||
ResponseEntity<String> response = endpoint.metadataEndpoint("regId", request); | ||
assertThat(response.getHeaders().getFirst(HttpHeaders.CONTENT_DISPOSITION)) | ||
.isEqualTo("attachment; filename=\"saml-sp.xml\"; filename*=UTF-8''saml-sp.xml"); | ||
} | ||
|
||
@Test | ||
void testZonedFileName() { | ||
when(identityZone.isUaa()).thenReturn(false); | ||
when(identityZone.getSubdomain()).thenReturn("testzone1"); | ||
when(endpoint.retrieveZone()).thenReturn(identityZone); | ||
ResponseEntity<String> response = endpoint.metadataEndpoint("regId", request); | ||
assertThat(response.getHeaders().getFirst(HttpHeaders.CONTENT_DISPOSITION)) | ||
.isEqualTo("attachment; filename=\"saml-testzone1-sp.xml\"; filename*=UTF-8''saml-testzone1-sp.xml"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters