use of org.springframework.mock.web.MockHttpSession in project cas by apereo.
the class DelegatedClientAuthenticationActionTests method verifyFinishAuthentication.
@Test
public void verifyFinishAuthentication() throws Exception {
final MockHttpServletRequest mockRequest = new MockHttpServletRequest();
mockRequest.setParameter(Clients.DEFAULT_CLIENT_NAME_PARAMETER, "FacebookClient");
final MockHttpSession mockSession = new MockHttpSession();
mockSession.setAttribute(ThemeChangeInterceptor.DEFAULT_PARAM_NAME, MY_THEME);
mockSession.setAttribute(LocaleChangeInterceptor.DEFAULT_PARAM_NAME, MY_LOCALE);
mockSession.setAttribute(CasProtocolConstants.PARAMETER_METHOD, MY_METHOD);
final Service service = CoreAuthenticationTestUtils.getService(MY_SERVICE);
mockSession.setAttribute(CasProtocolConstants.PARAMETER_SERVICE, service);
mockRequest.setSession(mockSession);
final ServletExternalContext servletExternalContext = mock(ServletExternalContext.class);
when(servletExternalContext.getNativeRequest()).thenReturn(mockRequest);
when(servletExternalContext.getNativeResponse()).thenReturn(new MockHttpServletResponse());
final MockRequestContext mockRequestContext = new MockRequestContext();
mockRequestContext.setExternalContext(servletExternalContext);
final FacebookClient facebookClient = new FacebookClient() {
@Override
protected OAuth20Credentials retrieveCredentials(final WebContext context) throws HttpAction {
return new OAuth20Credentials("fakeVerifier", FacebookClient.class.getSimpleName());
}
};
facebookClient.setName(FacebookClient.class.getSimpleName());
final Clients clients = new Clients(MY_LOGIN_URL, facebookClient);
final TicketGrantingTicket tgt = new TicketGrantingTicketImpl(TGT_ID, mock(Authentication.class), mock(ExpirationPolicy.class));
final CentralAuthenticationService casImpl = mock(CentralAuthenticationService.class);
when(casImpl.createTicketGrantingTicket(any(AuthenticationResult.class))).thenReturn(tgt);
final AuthenticationTransactionManager transManager = mock(AuthenticationTransactionManager.class);
final AuthenticationManager authNManager = mock(AuthenticationManager.class);
when(authNManager.authenticate(any(AuthenticationTransaction.class))).thenReturn(CoreAuthenticationTestUtils.getAuthentication());
when(transManager.getAuthenticationManager()).thenReturn(authNManager);
when(transManager.handle(any(AuthenticationTransaction.class), any(AuthenticationResultBuilder.class))).thenReturn(transManager);
final AuthenticationSystemSupport support = mock(AuthenticationSystemSupport.class);
when(support.getAuthenticationTransactionManager()).thenReturn(transManager);
final DelegatedClientAuthenticationAction action = new DelegatedClientAuthenticationAction(clients, support, casImpl, "theme", "locale", false);
final Event event = action.execute(mockRequestContext);
assertEquals("success", event.getId());
assertEquals(MY_THEME, mockRequest.getAttribute(ThemeChangeInterceptor.DEFAULT_PARAM_NAME));
assertEquals(MY_LOCALE, mockRequest.getAttribute(LocaleChangeInterceptor.DEFAULT_PARAM_NAME));
assertEquals(MY_METHOD, mockRequest.getAttribute(CasProtocolConstants.PARAMETER_METHOD));
assertEquals(MY_SERVICE, mockRequest.getAttribute(CasProtocolConstants.PARAMETER_SERVICE));
final MutableAttributeMap flowScope = mockRequestContext.getFlowScope();
final MutableAttributeMap requestScope = mockRequestContext.getRequestScope();
assertEquals(service, flowScope.get(CasProtocolConstants.PARAMETER_SERVICE));
assertEquals(TGT_ID, flowScope.get(TGT_NAME));
assertEquals(TGT_ID, requestScope.get(TGT_NAME));
}
use of org.springframework.mock.web.MockHttpSession in project cobar by alibaba.
the class PermissionInterceptorTest method testPermissionInter.
public void testPermissionInter() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest();
request.setServletPath("/cobarDetail.htm");
MockHttpSession session = new MockHttpSession();
UserDO user = new UserDO();
user.setStatus(ConstantDefine.NORMAL);
user.setUser_role(ConstantDefine.SYSTEM_ADMIN);
session.setAttribute("user", user);
request.setSession(session);
boolean rst = permissionInterceptor.preHandle(request, new MockHttpServletResponse(), null);
Assert.assertTrue(rst);
}
use of org.springframework.mock.web.MockHttpSession in project cobar by alibaba.
the class TestAddCobar method testAddCobar.
public void testAddCobar() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest();
request.setMethod("POST");
MockHttpSession session = new MockHttpSession();
UserDO user = new UserDO();
user.setStatus(ConstantDefine.NORMAL);
user.setUser_role(ConstantDefine.CLUSTER_ADMIN);
session.setAttribute("user", user);
request.setSession(session);
request.addParameter("clusterId", "1");
request.addParameter("host", "1.2.4.3");
request.addParameter("cobarName", "test");
request.addParameter("port", "8066");
request.addParameter("userName", "test");
request.addParameter("password", "TTT");
request.addParameter("status", "ACTIVE");
ModelAndView mav = addcobar.handleRequest(request, new MockHttpServletResponse());
Assert.assertEquals("add cobar success", String.valueOf(mav.getModel().get("info")));
}
use of org.springframework.mock.web.MockHttpSession in project spring-framework by spring-projects.
the class MockHttpServletRequestBuilderTests method session.
@Test
public void session() {
MockHttpSession session = new MockHttpSession(this.servletContext);
session.setAttribute("foo", "bar");
this.builder.session(session);
this.builder.sessionAttr("baz", "qux");
MockHttpServletRequest request = this.builder.buildRequest(this.servletContext);
assertEquals(session, request.getSession());
assertEquals("bar", request.getSession().getAttribute("foo"));
assertEquals("qux", request.getSession().getAttribute("baz"));
}
use of org.springframework.mock.web.MockHttpSession in project spring-framework by spring-projects.
the class HtmlUnitRequestBuilder method httpSession.
private MockHttpSession httpSession(MockHttpServletRequest request, final String sessionid) {
MockHttpSession session;
synchronized (this.sessions) {
session = this.sessions.get(sessionid);
if (session == null) {
session = new HtmlUnitMockHttpSession(request, sessionid);
session.setNew(true);
synchronized (this.sessions) {
this.sessions.put(sessionid, session);
}
addSessionCookie(request, sessionid);
} else {
session.setNew(false);
}
}
return session;
}
Aggregations