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

Method loginDoPost

src/test/java/servlets/LoginTest.java:429–496  ·  view source on GitHub ↗
(String userName, String password, String theClass)

Source from the content-addressed store, hash-verified

427 }
428
429 public void loginDoPost(String userName, String password, String theClass) throws Exception
430 {
431 try
432 {
433 int expectedResponseCode = 302;
434
435 log.debug("Creating Login Servlet Instance");
436 Login servlet = new Login();
437 servlet.init(new MockServletConfig("Login"));
438
439 //Setup Servlet Parameters and Attributes
440 log.debug("Setting Up Params and Atrributes");
441 request.addParameter("login", userName);
442 request.addParameter("pwd", password);
443 request.getSession().setAttribute("lang", lang);
444
445
446 log.debug("Running doPost");
447 servlet.doPost(request, response);
448
449 if(response.getStatus() != expectedResponseCode)
450 fail("Login Servlet Returned " + response.getStatus() + " Code. 302 Expected");
451 else
452 {
453 log.debug("302 OK Detected");
454 String location = response.getHeader("Location");
455 log.debug("302 pointing at: " + location);
456 if(!location.endsWith("index.jsp"))
457 {
458 throw new Exception("Login not Redirecting to index.jsp. Login Proceedure Failed");
459 }
460 else
461 {
462 log.debug("Making sure all Session Attributes have been set");
463 HttpSession ses = request.getSession();
464 try
465 {
466 String userStamp = ses.getAttribute("userStamp").toString();
467 log.debug("userStamp = " + userStamp);
468 String sessionUserName = ses.getAttribute("userName").toString();
469 log.debug("userName = " + sessionUserName);
470 String userRole = ses.getAttribute("userRole").toString();
471 log.debug("userRole = " + userRole);
472 String userLang = ses.getAttribute("lang").toString();
473 log.debug("lang = " + userLang);
474 if(theClass != null) //Null Class wasn't Submitted, So Check ses has a class id in it
475 {
476 String userClass = ses.getAttribute("userClass").toString();
477 log.debug("userClass = " + userClass);
478 }
479 else if(ses.getAttribute("userClass") != null)//Null was Submitted. Make sure the class is null
480 {
481 fail("Player is in a class, but should have class id of null");
482 }
483 }
484 catch(Exception e)
485 {
486 log.fatal("Could not Retrieve All Session Attibutes: " + e.toString());

Callers 8

testUserLoginMethod · 0.95
testAdminLoginMethod · 0.95
testUserLoginWithSqliMethod · 0.95

Calls 3

doPostMethod · 0.95
initMethod · 0.80
getSessionMethod · 0.80

Tested by

no test coverage detected