Skip to content

Commit

Permalink
delete: another unused test
Browse files Browse the repository at this point in the history
* We considered making this work by mocking the IdP, but we'd have to remove most of it because it's testing IdP features, plus the discovery endpoint. It doesn't seem to be a good test for the discovery endpoint.

[#187065237]

Co-authored-by: Hongchol Sinn <hongchol.sinn@broadcom.com>
  • Loading branch information
swalchemist and hsinn0 committed Feb 22, 2024
1 parent 7dd538f commit 6194843
Showing 1 changed file with 0 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import org.cloudfoundry.identity.uaa.provider.IdentityProvider;
import org.cloudfoundry.identity.uaa.provider.JdbcIdentityProviderProvisioning;
import org.cloudfoundry.identity.uaa.provider.SamlIdentityProviderDefinition;
import org.cloudfoundry.identity.uaa.provider.saml.idp.SamlServiceProvider;
import org.cloudfoundry.identity.uaa.scim.ScimUser;
import org.cloudfoundry.identity.uaa.scim.jdbc.JdbcScimUserProvisioning;
import org.cloudfoundry.identity.uaa.zone.IdentityZone;
Expand All @@ -28,11 +27,9 @@
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.mock.web.MockHttpSession;
import org.springframework.security.oauth2.common.util.RandomValueStringGenerator;
import org.springframework.security.oauth2.provider.client.BaseClientDetails;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.ResultActions;
import org.springframework.web.context.WebApplicationContext;

Expand All @@ -48,9 +45,6 @@
import static org.springframework.http.HttpHeaders.HOST;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.redirectedUrl;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

@DefaultTestContext
class SamlAuthenticationMockMvcTests {
Expand Down Expand Up @@ -113,49 +107,6 @@ void putBackOriginalLogger() {
loggingAuditService.setLogger(originalAuditServiceLogger);
}

@Disabled("The test depends on IDP endpoints, which was removed.")
@Test
void sendAuthnRequestToIdp() throws Exception {
createIdp();

String idpEntityId = idpZone.getSubdomain() + ".cloudfoundry-saml-login";
MvcResult mvcResult = mockMvc.perform(
get("/uaa/saml/discovery")
.contextPath("/uaa")
.header(HOST, spZone.getSubdomain() + ".localhost:8080")
.param("returnIDParam", "idp")
.param("entityID", spZoneEntityId)
.param("idp", idp.getOriginKey())
.param("isPassive", "true")
)
.andExpect(status().isFound())
.andReturn();

mvcResult = mockMvc.perform(
get(mvcResult.getResponse().getRedirectedUrl())
.contextPath("/uaa")
.header(HOST, spZone.getSubdomain() + ".localhost:8080")
.session((MockHttpSession) mvcResult.getRequest().getSession())

)
.andDo(print())
.andExpect(status().isOk())
.andReturn();

String body = mvcResult.getResponse().getContentAsString();
String relayState = extractRelayState(body);
String samlRequest = extractSamlRequest(body);
mockMvc.perform(
post("/uaa/saml/idp/SSO/alias/" + idpEntityId)
.contextPath("/uaa")
.header(HOST, idpZone.getSubdomain() + ".localhost:8080")
.param("RelayState", relayState)
.param("SAMLRequest", samlRequest)
)
.andExpect(status().isFound())
.andExpect(redirectedUrl("http://" + idpZone.getSubdomain() + ".localhost:8080/uaa/login"));
}

private ResultActions postSamlResponse(
final String xml,
final String queryString,
Expand Down Expand Up @@ -321,27 +272,4 @@ private IdentityZone createZone(String zoneIdPrefix, BaseClientDetails adminClie
adminClient, IdentityZoneHolder.getCurrentZoneId()
).getIdentityZone();
}

private static String extractSamlRequest(String response) {
String searchFor = "name=\"SAMLRequest\" value=\"";
return extractFormParameter(searchFor, response, false);
}

private static String extractRelayState(String response) {
String searchFor = "name=\"RelayState\" value=\"";
return extractFormParameter(searchFor, response, false);
}

private static String extractFormParameter(String searchFor, String response, boolean decode) {
int start = response.indexOf(searchFor) + searchFor.length();
assertThat("Must find the SAML response in output\n" + response, start, greaterThan(searchFor.length()));
int end = response.indexOf("\"/>", start);
assertThat("Must find the SAML response in output\n" + response, end, greaterThan(start));
String encoded = response.substring(start, end);
if (decode) {
return new String(Base64.getDecoder().decode(encoded));
} else {
return encoded;
}
}
}

0 comments on commit 6194843

Please sign in to comment.