成功登录后,我的应用程序将 cookie 'XYZ' 添加到响应中。此 cookie 确定应用程序登录后的特定行为。
我使用 shiro FormAuthenticationFilter 这就是添加 cookie 的方式。
@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);
}
使用 HTMLUnit 断言此行为的功能测试失败,因为此 cookie 设置不正确。当我在 Chrome 中使用该应用程序时,它工作得非常好。调试HTMLUnit测试证明登录成功后如下方法,
driver.manage.getCookies()
仅返回 JESSIONID cookie 而不是应用程序设置的附加 cookie 'XYZ'。
注意:如果我在登录后以外的任何页面上设置此 cookie,htmlunit 会选择它。
请问有什么想法吗?