Repository navigation
Expand file tree
/
Copy pathSLSTest.java
More file actions
104 lines (81 loc) · 3.42 KB
/
Copy pathSLSTest.java
File metadata and controls
104 lines (81 loc) · 3.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package servlets;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.mock.web.MockHttpSession;
import utils.SamlTestSupport;
public class SLSTest {
private static SamlTestSupport saml;
@BeforeAll
public static void installClient() throws Exception {
saml = new SamlTestSupport();
saml.installClient();
}
@AfterAll
public static void uninstallClient() {
SamlTestSupport.uninstallClient();
}
private static MockHttpSession loggedInSession() {
MockHttpSession session = new MockHttpSession();
session.setAttribute("userName", "jdoe");
session.setAttribute("userRole", "player");
return session;
}
private static MockHttpServletRequest logoutResponse() throws Exception {
return SamlTestSupport.slsGet(
SamlTestSupport.redirectQuery(
"SAMLResponse", SamlTestSupport.toXml(saml.logoutResponse(), null, null), null));
}
/** The SLS used to only define handleRequest, so the IdP's redirect got a 405 */
@Test
public void doGet_WithoutSamlMessage_IsBadRequest() throws Exception {
MockHttpServletResponse response = new MockHttpServletResponse();
new SLS().doGet(new MockHttpServletRequest("GET", "/saml/sls"), response);
assertEquals(400, response.getStatus());
assertNull(response.getRedirectedUrl());
}
@Test
public void doPost_WithoutSamlMessage_IsBadRequest() throws Exception {
MockHttpServletResponse response = new MockHttpServletResponse();
new SLS().doPost(new MockHttpServletRequest("POST", "/saml/sls"), response);
assertEquals(400, response.getStatus());
assertNull(response.getRedirectedUrl());
}
/**
* A bogus message must not end the session, directly or by redirecting to login.jsp, which
* invalidates the session it is loaded in
*/
@Test
public void invalidLogoutMessage_KeepsSessionAndDoesNotRedirect() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/saml/sls");
MockHttpSession session = loggedInSession();
request.setSession(session);
MockHttpServletResponse response = new MockHttpServletResponse();
new SLS().doGet(request, response);
assertFalse(session.isInvalid());
assertEquals(400, response.getStatus());
assertNull(response.getRedirectedUrl());
}
@Test
public void logoutResponse_WithoutSession_GoesToLogin() throws Exception {
MockHttpServletResponse response = new MockHttpServletResponse();
new SLS().doGet(logoutResponse(), response);
assertEquals("../login.jsp", response.getRedirectedUrl());
}
/** A LogoutResponse delivered to a still-logged-in browser must not end that session */
@Test
public void logoutResponse_InLoggedInBrowser_KeepsSession() throws Exception {
MockHttpServletRequest request = logoutResponse();
MockHttpSession session = loggedInSession();
request.setSession(session);
MockHttpServletResponse response = new MockHttpServletResponse();
new SLS().doGet(request, response);
assertFalse(session.isInvalid());
assertEquals("../index.jsp", response.getRedirectedUrl());
}
}