use of net.sourceforge.stripes.mock.MockHttpServletResponse in project jspwiki by apache.
the class WikiSessionTest method testAuthenticationCookieDefaults.
@Test
public void testAuthenticationCookieDefaults() throws ServletException, IOException {
MockHttpServletRequest request;
WikiSession wikiSession;
// Set the authentication cookie first
MockHttpServletResponse response = new MockHttpServletResponse();
CookieAuthenticationLoginModule.setLoginCookie(m_engine, response, "Fred Flintstone");
Cookie[] cookies = response.getCookies();
Assert.assertEquals(1, cookies.length);
String uid = cookies[0].getValue();
// Adding the magic "authentication cookie" should NOT count as authenticated in the default case
// (because cookie authentication is OFF).
request = m_engine.newHttpRequest();
request.setUserPrincipal(null);
request.setCookies(new Cookie[] { new Cookie("JSPWikiUID", uid) });
runSecurityFilter(m_engine, request);
wikiSession = WikiSession.getWikiSession(m_engine, request);
Assert.assertTrue(wikiSession.isAnonymous());
Assert.assertFalse(wikiSession.isAuthenticated());
Assert.assertEquals("127.0.0.1", wikiSession.getUserPrincipal().getName());
// Clear the authentication cookie
response = new MockHttpServletResponse();
CookieAuthenticationLoginModule.clearLoginCookie(m_engine, request, response);
}
use of net.sourceforge.stripes.mock.MockHttpServletResponse in project jspwiki by apache.
the class WikiSessionTest method testAuthenticationCookieWhenOn.
@Test
public void testAuthenticationCookieWhenOn() throws WikiException, ServletException, IOException {
Properties props = TestEngine.getTestProperties();
props.setProperty(AuthenticationManager.PROP_ALLOW_COOKIE_AUTH, "true");
m_engine = new TestEngine(props);
MockHttpServletRequest request;
WikiSession wikiSession;
// Set the authentication cookie first
MockHttpServletResponse response = new MockHttpServletResponse();
CookieAuthenticationLoginModule.setLoginCookie(m_engine, response, "Fred Flintstone");
Cookie[] cookies = response.getCookies();
Assert.assertEquals(1, cookies.length);
String uid = cookies[0].getValue();
// Adding the magic "authentication cookie" should count as authenticated
request = m_engine.newHttpRequest();
request.setUserPrincipal(null);
request.setCookies(new Cookie[] { new Cookie("JSPWikiUID", uid) });
runSecurityFilter(m_engine, request);
wikiSession = WikiSession.getWikiSession(m_engine, request);
Assert.assertFalse(wikiSession.isAnonymous());
Assert.assertTrue(wikiSession.isAuthenticated());
Assert.assertEquals("Fred Flintstone", wikiSession.getUserPrincipal().getName());
// Clear the authentication cookie
response = new MockHttpServletResponse();
CookieAuthenticationLoginModule.clearLoginCookie(m_engine, request, response);
}
Aggregations