use of net.sourceforge.stripes.mock.MockHttpServletRequest 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);
}
use of net.sourceforge.stripes.mock.MockHttpServletRequest in project jspwiki by apache.
the class CookieAssertionLoginModuleTest method testLogout.
public final void testLogout() {
MockHttpServletRequest request = m_engine.newHttpRequest();
Cookie cookie = new Cookie(CookieAssertionLoginModule.PREFS_COOKIE_NAME, "Bullwinkle");
request.setCookies(new Cookie[] { cookie });
try {
CallbackHandler handler = new WebContainerCallbackHandler(m_engine, request);
LoginModule module = new CookieAssertionLoginModule();
module.initialize(m_subject, handler, new HashMap<String, Object>(), new HashMap<String, Object>());
module.login();
module.commit();
Set<Principal> principals = m_subject.getPrincipals();
Assert.assertEquals(1, principals.size());
Assert.assertTrue(principals.contains(new WikiPrincipal("Bullwinkle")));
Assert.assertFalse(principals.contains(Role.ANONYMOUS));
Assert.assertFalse(principals.contains(Role.ALL));
module.logout();
Assert.assertEquals(0, principals.size());
} catch (LoginException e) {
System.err.println(e.getMessage());
Assert.assertTrue(false);
}
}
use of net.sourceforge.stripes.mock.MockHttpServletRequest in project jspwiki by apache.
the class CommandResolverTest method testFindWikiActionWithParams.
@Test
public void testFindWikiActionWithParams() throws Exception {
Command a;
WikiPage page = m_engine.getPage("SinglePage");
// Passing an EDIT request with page param yields a wrapped action
MockHttpServletRequest request = m_engine.newHttpRequest("/Edit.jsp?page=SinglePage");
request.getParameterMap().put("page", new String[] { "SinglePage" });
a = resolver.findCommand(request, WikiContext.EDIT);
Assert.assertNotSame(PageCommand.EDIT, a);
Assert.assertEquals("EditContent.jsp", a.getContentTemplate());
Assert.assertEquals("Edit.jsp", a.getJSP());
Assert.assertEquals("%uEdit.jsp?page=%n", a.getURLPattern());
Assert.assertEquals(page, a.getTarget());
// Passing an EDIT request with page=Search yields FIND action, *not* edit
request.setContextPath("/Edit.jsp?page=Search");
request.getParameterMap().put("page", new String[] { "Search" });
a = resolver.findCommand(request, WikiContext.EDIT);
Assert.assertEquals(WikiCommand.FIND, a);
Assert.assertEquals("FindContent.jsp", a.getContentTemplate());
Assert.assertEquals("Search.jsp", a.getJSP());
Assert.assertEquals("%uSearch.jsp", a.getURLPattern());
Assert.assertNull(a.getTarget());
// Passing an EDIT request with group="Foo" yields wrapped VIEW_GROUP
request = m_engine.newHttpRequest("/Group.jsp?group=Foo");
request.getParameterMap().put("group", new String[] { "Foo" });
a = resolver.findCommand(request, WikiContext.EDIT);
Assert.assertNotSame(GroupCommand.VIEW_GROUP, a);
Assert.assertEquals("GroupContent.jsp", a.getContentTemplate());
Assert.assertEquals("Group.jsp", a.getJSP());
Assert.assertEquals("%uGroup.jsp?group=%n", a.getURLPattern());
Assert.assertEquals(new GroupPrincipal("Foo"), a.getTarget());
}
use of net.sourceforge.stripes.mock.MockHttpServletRequest in project jspwiki by apache.
the class SearchManagerTest method testSimpleSearch4.
@Test
public void testSimpleSearch4() throws Exception {
String txt = "It was the dawn of the third age of mankind, ten years after the Earth-Minbari War.";
MockHttpServletRequest request = m_engine.newHttpRequest();
request.getParameterMap().put("page", new String[] { "TestPage" });
WikiContext ctx = m_engine.createContext(request, WikiContext.EDIT);
m_engine.saveText(ctx, txt);
Thread.yield();
Collection res = waitForIndex("mankind", "testSimpleSearch4");
Assert.assertNotNull("found results", res);
Assert.assertEquals("result not found", 1, res.size());
m_engine.saveText(ctx, "[{ALLOW view Authenticated}] It was the dawn of the third age of mankind... page is blocked");
res = m_mgr.findPages("mankind", ctx);
Assert.assertNotNull("null result", res);
Assert.assertEquals("result found, should be blocked", 0, res.size());
m_engine.deleteTestPage("TestPage");
}
use of net.sourceforge.stripes.mock.MockHttpServletRequest in project jspwiki by apache.
the class SearchManagerTest method waitForIndex.
/**
* Should cover for both index and initial delay
*/
Collection waitForIndex(String text, String testName) throws Exception {
Collection res = null;
for (long l = 0; l < SLEEP_COUNT; l++) {
if (res == null || res.isEmpty()) {
Thread.sleep(SLEEP_TIME);
} else {
break;
}
MockHttpServletRequest request = m_engine.newHttpRequest();
WikiContext ctx = m_engine.createContext(request, WikiContext.EDIT);
res = m_mgr.findPages(text, ctx);
// debugSearchResults( res );
}
return res;
}
Aggregations