Skip to content

Commit

Permalink
Test redirect servicedesk flow #587
Browse files Browse the repository at this point in the history
  • Loading branch information
oharsta committed Jan 14, 2025
1 parent 656ed4f commit 7c2089c
Showing 1 changed file with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
package myconext.api;

import io.restassured.http.Cookie;
import io.restassured.response.Response;
import myconext.AbstractIntegrationTest;
import myconext.model.MagicLinkRequest;
import myconext.model.User;
import org.junit.Test;
import org.springframework.http.HttpMethod;
import org.springframework.test.context.ActiveProfiles;

import java.io.IOException;
import java.util.UUID;

import static io.restassured.RestAssured.given;
import static myconext.security.GuestIdpAuthenticationRequestFilter.GUEST_IDP_REMEMBER_ME_COOKIE_NAME;
import static org.hamcrest.Matchers.startsWith;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;

@ActiveProfiles(value = "dev", inheritProfiles = false)
Expand Down Expand Up @@ -134,4 +142,31 @@ public void testCreateFromInstitutionLoginNewUser() {
"http://localhost:3001/security?new=true");
}

@Test
public void redirectToSPServiceDeskHook() throws IOException {
String authenticationRequestId = samlAuthnRequest();
User user = user("[email protected]", "Steve", "Doe", "en");
MagicLinkResponse magicLinkResponse = magicLinkRequest(new MagicLinkRequest(authenticationRequestId, user, false), HttpMethod.POST);
Response response = magicResponse(magicLinkResponse);

String cookie = response.cookie(GUEST_IDP_REMEMBER_ME_COOKIE_NAME);
String authnContext = readFile("request_authn_context.xml");
samlAuthnRequestResponseWithLoa(
new Cookie.Builder(GUEST_IDP_REMEMBER_ME_COOKIE_NAME, cookie).build(), null, authnContext);
String location = given().redirects().follow(false)
.when()
.get("/servicedesk/" + authenticationRequestId)
.header("Location");
assertEquals("http://localhost:3001/personal?servicedesk=start", location);
}

@Test
public void redirectToSPServiceDeskHookNoAuthenticationRequest() throws IOException {
String location = given().redirects().follow(false)
.when()
.get("/servicedesk/" + UUID.randomUUID().toString())
.header("Location");
assertEquals("http://localhost:3000/expired", location);
}

}

0 comments on commit 7c2089c

Please sign in to comment.