MCPcopy Create free account
hub / github.com/OWASP/SecurityShepherd / testLogoutBadCsrf

Method testLogoutBadCsrf

src/test/java/servlets/LogoutTest.java:183–223  ·  view source on GitHub ↗

This test logs the user in and then calls the logout function

()

Source from the content-addressed store, hash-verified

181 * This test logs the user in and then calls the logout function
182 */
183 @Test
184 public void testLogoutBadCsrf()
185 {
186 String userName = "logoutUser2";
187 try
188 {
189 //Verify User Exists in DB
190 GetterTest.verifyTestUser(applicationRoot, userName, userName);
191 //Sign in as Normal User
192 log.debug("Signing in as User Through LoginServlet");
193 loginDoPost(userName, userName, null);
194 log.debug("Login Servlet Complete, Getting CSRF Token");
195 if(response.getCookie("token") == null)
196 fail("No CSRF Token Was Returned from Login Servlet");
197 String csrfToken = response.getCookie("token").getValue();
198 if(csrfToken.isEmpty())
199 {
200 String message = new String("No CSRF token returned from Login Servlet");
201 log.fatal(message);
202 fail(message);
203 }
204 else
205 {
206 //Add Cookies from Response to outgoing request
207 request.setCookies(response.getCookies());
208 logoutDoPost("wrongCsrfToken");
209 HttpSession ses = request.getSession();
210 if(ses.getAttribute("userStamp") == null)
211 fail("User's Session is Cleared After CSRF'd Logout");
212 else
213 {
214 log.debug("User Not Logged Out! Pass!");
215 }
216 }
217 }
218 catch(Exception e)
219 {
220 log.fatal("Could not Complete testLogoutBadCsrf: " + e.toString());
221 fail("Could not Complete testLogoutBadCsrf");
222 }
223 }
224}

Callers

nothing calls this directly

Calls 4

verifyTestUserMethod · 0.95
loginDoPostMethod · 0.95
logoutDoPostMethod · 0.95
getSessionMethod · 0.80

Tested by

no test coverage detected