HTMLUnit does not read any cookie other than JESSIONID after login

185 Views Asked by At

My application adds a cookie 'XYZ' to the response after a successful login. This cookie determines a certain behaviour of the app post login.

I use shiro FormAuthenticationFilter and this is how the cookie is added.

@Override
public boolean onLoginSuccess(AuthenticationToken token, Subject subject, ServletRequest     
   request, ServletResponse response) throws Exception {
       Cookie cookie = new Cookie('XYZ', '123');
       cookie.setPath("/");
       cookie.setMaxAge(-1);
       response.addCookie(cookie);
}

Functional tests to assert this behaviour using HTMLUnit fail because this cookie is not set properly. It works perfectly fine when I use the app in Chrome. Debugging the HTMLUnit test proved that after successful login the following method,

driver.manage.getCookies() 

returns only the JESSIONID cookie and not the additional cookie 'XYZ' set by the application.

Note: If I set this cookie on any page other than post login, htmlunit picks it up.

Thoughts please?

1

There are 1 best solutions below

1
On

It is very hard to guess why something works in on any page other than post login but not in the login itself, which is just another page. Particularly if you haven't provided any code.

The obvious non-code answer is: the login is doing something different than the rest of the page. Find what it is and fix it.

Applying my imagination, and just mentioning one of the hundred things that might be happening here, I bet the issue is that you're setting that cookie based on an AJAX call that is not being performed or received properly.