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

Method testLogout

src/test/java/servlets/LogoutTest.java:137–178  ·  view source on GitHub ↗

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

()

Source from the content-addressed store, hash-verified

135 * This test logs the user in and then calls the logout function
136 */
137 @Test
138 public void testLogout()
139 {
140 String userName = "logoutUser1";
141 try
142 {
143 //Verify User Exists in DB
144 GetterTest.verifyTestUser(applicationRoot, userName, userName);
145 //Sign in as Normal User
146 log.debug("Signing in as User Through LoginServlet");
147 loginDoPost(userName, userName, null);
148 log.debug("Login Servlet Complete, Getting CSRF Token");
149 if(response.getCookie("token") == null)
150 fail("No CSRF Token Was Returned from Login Servlet");
151 String csrfToken = response.getCookie("token").getValue();
152 if(csrfToken.isEmpty())
153 {
154 String message = new String("No CSRF token returned from Login Servlet");
155 log.fatal(message);
156 fail(message);
157 }
158 else
159 {
160 //Add Cookies from Response to outgoing request
161 request.setCookies(response.getCookies());
162 logoutDoPost(csrfToken);
163 log.debug("Checking Session");
164 HttpSession ses = request.getSession();
165 if(ses.getAttribute("userStamp") != null)
166 fail("User's Session is not Cleared After Logout");
167 else
168 {
169 log.debug("User Logged Out! Pass!");
170 }
171 }
172 }
173 catch(Exception e)
174 {
175 log.fatal("Could not Complete testLogout: " + e.toString());
176 fail("Could not Complete testLogout");
177 }
178 }
179
180 /**
181 * This test logs the user in and then calls the logout function

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