List of usage examples for org.springframework.mock.web MockHttpServletResponse getRedirectedUrl
@Nullable
public String getRedirectedUrl()
From source file:fi.okm.mpass.shibboleth.authn.impl.ShibbolethSpAuthnServletTest.java
@Test public void testWithHeaders() throws Exception { final MockHttpServletRequest servletRequest = initServletRequest(); final String headerName = "mockHeader"; final String headerValue = "mockValue"; servletRequest.addHeader(headerName, headerValue); servletRequest.addHeader(headerName + "2", ""); final MockHttpServletResponse servletResponse = new MockHttpServletResponse(); servlet.doGet(servletRequest, servletResponse); Assert.assertEquals(servletResponse.getRedirectedUrl(), flowExecutionUrl); assertExternalContext(headerName, headerValue, null); }
From source file:org.craftercms.security.authentication.impl.LoginFailureHandlerImplTest.java
@Test public void testRedirectToTargetUrl() throws Exception { handler.setTargetUrl(TARGET_URL); MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); RequestContext context = new RequestContext(request, response); handler.handle(context, new AuthenticationException()); assertEquals(TARGET_URL, response.getRedirectedUrl()); assertEquals(HttpServletResponse.SC_MOVED_TEMPORARILY, response.getStatus()); assertTrue(response.isCommitted());/*ww w . java 2 s .co m*/ }
From source file:org.craftercms.security.authentication.impl.LoginSuccessHandleImplTest.java
@Test public void testRedirectToDefaultTargetUrl() throws Exception { MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); RequestContext context = new RequestContext(request, response); handler.handle(context, mock(Authentication.class)); assertEquals(DEFAULT_TARGET_URL, response.getRedirectedUrl()); assertEquals(HttpServletResponse.SC_MOVED_TEMPORARILY, response.getStatus()); assertTrue(response.isCommitted());//from w w w. j ava 2s .c om }
From source file:fi.okm.mpass.idp.authn.impl.SocialUserOpenIdConnectEndServletTest.java
/** * Run servlet successfully through.//from w w w. j av a 2 s.com * * @throws Exception */ @Test public void testSuccess() throws Exception { final MockHttpServletRequest httpRequest = new MockHttpServletRequest(); httpRequest.getSession().setAttribute(SocialUserOpenIdConnectStartServlet.SESSION_ATTR_FLOWKEY, conversationKey); httpRequest.getSession().setAttribute(SocialUserOpenIdConnectStartServlet.SESSION_ATTR_SUCTX, new SocialUserOpenIdConnectContext()); final ProfileRequestContext<?, ?> ctx = new ProfileRequestContext<>(); httpRequest.getSession().setAttribute(ExternalAuthentication.CONVERSATION_KEY + conversationKey, new ExternalAuthenticationImpl(ctx)); final AuthenticationContext authnCtx = ctx.getSubcontext(AuthenticationContext.class, true); final ExternalAuthenticationContext externalCtx = authnCtx .getSubcontext(ExternalAuthenticationContext.class, true); final String url = "https://mock.example.org/"; externalCtx.setFlowExecutionUrl(url); final AuthenticationFlowDescriptor flow = new AuthenticationFlowDescriptor(); flow.setId("mock"); authnCtx.setAttemptedFlow(flow); final MockHttpServletResponse httpResponse = new MockHttpServletResponse(); Assert.assertFalse(SocialUserOpenIdConnectStartServletTest.runService(servlet, httpRequest, httpResponse)); Assert.assertEquals(httpResponse.getRedirectedUrl(), url); }
From source file:org.ambraproject.doi.ResolverServletTest.java
@Test(dataProvider = "dois") public void testDoGet(HttpServletRequest request, String expectedRedirect, String expectedReferral) { MockHttpServletResponse response = new MockHttpServletResponse(); resolverServlet.doGet(request, response); assertEquals(response.getHeader(HTTP_HEADER_REFERRER), expectedReferral, "referral did not match"); assertEquals(response.getRedirectedUrl(), expectedRedirect, "servlet didn't redirect correctly"); }
From source file:org.openmrs.web.servlet.LoginServletTest.java
/** * If a user logs in correctly, they should never be redirected back to the login screen because * this would cause confusion//from ww w . j a v a 2s. com * * @throws Exception */ @Test public void shouldNotRedirectBackToLoginScreenWithCorrectUsernameAndPassword() throws Exception { // this test depends on being able to log in as "admin:test". Context.logout(); Context.authenticate("admin", "test"); Assert.assertTrue(Context.isAuthenticated()); // do the test now LoginServlet loginServlet = new LoginServlet(); MockHttpServletRequest request = new MockHttpServletRequest("POST", "/loginServlet"); request.setContextPath("/somecontextpath"); MockHttpServletResponse response = new MockHttpServletResponse(); request.setParameter("uname", "admin"); request.setParameter("pw", "test"); loginServlet.service(request, response); Assert.assertNotSame("/somecontextpath/login.htm", response.getRedirectedUrl()); }
From source file:fi.okm.mpass.idp.authn.impl.SocialUserOpenIdConnectStartServletTest.java
/** * Run servlet with prerequisities met.//from w ww . j av a2s . c o m * @throws Exception */ @Test public void testSuccess() throws Exception { MockHttpServletRequest httpRequest = new MockHttpServletRequest(); httpRequest.setParameter(ExternalAuthentication.CONVERSATION_KEY, conversationKey); final ProfileRequestContext<?, ?> ctx = new ProfileRequestContext<>(); final AuthenticationContext authnCtx = ctx.getSubcontext(AuthenticationContext.class, true); final AuthenticationFlowDescriptor flow = new AuthenticationFlowDescriptor(); flow.setId("mock"); authnCtx.setAttemptedFlow(flow); final SocialUserOpenIdConnectContext suOidcCtx = authnCtx .getSubcontext(SocialUserOpenIdConnectContext.class, true); final String redirectUri = "https://mock.example.org"; suOidcCtx.setAuthenticationRequestURI(new URI(redirectUri)); httpRequest.getSession().setAttribute(ExternalAuthentication.CONVERSATION_KEY + conversationKey, new ExternalAuthenticationImpl(ctx)); final MockHttpServletResponse httpResponse = new MockHttpServletResponse(); Assert.assertFalse(runService(servlet, httpRequest, httpResponse)); Assert.assertEquals(httpResponse.getRedirectedUrl(), redirectUri); Assert.assertNotNull( httpRequest.getSession().getAttribute(SocialUserOpenIdConnectStartServlet.SESSION_ATTR_SUCTX)); Assert.assertTrue(httpRequest.getSession().getAttribute( SocialUserOpenIdConnectStartServlet.SESSION_ATTR_SUCTX) instanceof SocialUserOpenIdConnectContext); }
From source file:org.craftercms.security.authentication.impl.AuthenticationRequiredHandlerImplTest.java
@Test public void testRedirectToLoginFormUrl() throws Exception { handler.setLoginFormUrl(LOGIN_FORM_URL); MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); RequestContext context = new RequestContext(request, response); handler.handle(context, new AuthenticationRequiredException("")); verify(requestCache).saveRequest(request, response); assertEquals(LOGIN_FORM_URL, response.getRedirectedUrl()); assertEquals(HttpServletResponse.SC_MOVED_TEMPORARILY, response.getStatus()); assertTrue(response.isCommitted());//from w w w . j av a 2s. c o m }
From source file:org.openmrs.web.servlet.LoginServletTest.java
/** * The servlet should send the user back to the login box if the user enters the wrong username * or password./*from w w w.jav a 2 s . c om*/ * * @throws Exception */ @Test public void shouldRedirectBackToLoginScreenOnBadUsernameAndPassword() throws Exception { LoginServlet loginServlet = new LoginServlet(); MockHttpServletRequest request = new MockHttpServletRequest("POST", "/loginServlet"); request.setContextPath("/somecontextpath"); MockHttpServletResponse response = new MockHttpServletResponse(); request.setParameter("uname", "some wrong username"); request.setParameter("pw", "some wrong password"); loginServlet.service(request, response); Assert.assertEquals("/somecontextpath/login.htm", response.getRedirectedUrl()); }
From source file:fi.okm.mpass.idp.authn.impl.SocialUserAuthServletTest.java
@Test public void testAuthnStart() throws Exception { MockHttpServletRequest httpRequest = initHttpRequest(); MockHttpServletResponse httpResponse = new MockHttpServletResponse(); httpRequest.setRequestURI(nullAuthenticator); servlet.service(httpRequest, httpResponse); Assert.assertNull(httpRequest.getAttribute(ExternalAuthentication.AUTHENTICATION_ERROR_KEY)); Assert.assertEquals(httpResponse.getRedirectedUrl(), authnRedirectUrl); }