use of org.springframework.mock.web.MockHttpSession in project cas by apereo.
the class OAuth20AuthorizeControllerTests method verifyRedirectToApproval.
@Test
public void verifyRedirectToApproval() throws Exception {
clearAllServices();
final MockHttpServletRequest mockRequest = new MockHttpServletRequest(GET, CONTEXT + OAuthConstants.AUTHORIZE_URL);
mockRequest.setParameter(OAuthConstants.CLIENT_ID, CLIENT_ID);
mockRequest.setParameter(OAuthConstants.REDIRECT_URI, REDIRECT_URI);
mockRequest.setParameter(OAuthConstants.RESPONSE_TYPE, OAuth20ResponseTypes.CODE.name().toLowerCase());
mockRequest.setServerName(CAS_SERVER);
mockRequest.setServerPort(CAS_PORT);
mockRequest.setScheme(CAS_SCHEME);
final MockHttpServletResponse mockResponse = new MockHttpServletResponse();
final OAuthRegisteredService service = getRegisteredService(REDIRECT_URI, SERVICE_NAME);
service.setBypassApprovalPrompt(false);
oAuth20AuthorizeEndpointController.getServicesManager().save(service);
final CasProfile profile = new CasProfile();
profile.setId(ID);
final Map<String, Object> attributes = new HashMap<>();
attributes.put(FIRST_NAME_ATTRIBUTE, FIRST_NAME);
attributes.put(LAST_NAME_ATTRIBUTE, LAST_NAME);
profile.addAttributes(attributes);
final MockHttpSession session = new MockHttpSession();
mockRequest.setSession(session);
session.putValue(Pac4jConstants.USER_PROFILES, profile);
final ModelAndView modelAndView = oAuth20AuthorizeEndpointController.handleRequestInternal(mockRequest, mockResponse);
assertEquals(OAuthConstants.CONFIRM_VIEW, modelAndView.getViewName());
final Map<String, Object> model = modelAndView.getModel();
assertEquals(CommonHelper.addParameter(AUTHORIZE_URL, OAuthConstants.BYPASS_APPROVAL_PROMPT, "true"), model.get("callbackUrl"));
assertEquals(SERVICE_NAME, model.get("serviceName"));
}
use of org.springframework.mock.web.MockHttpSession in project gocd by gocd.
the class FlashLoadingFilterIntegrationTest method shouldLoadExistingFlashFromSession.
@Test
public void shouldLoadExistingFlashFromSession() throws IOException, ServletException {
MockHttpServletRequest req = new MockHttpServletRequest();
MockHttpSession session = new MockHttpSession();
FlashMessageService.Flash oldFlash = new FlashMessageService.Flash();
oldFlash.put("my_key", new FlashMessageModel("my other message", "warning"));
session.putValue(FlashLoadingFilter.FLASH_SESSION_KEY, oldFlash);
req.setSession(session);
MockHttpServletResponse res = new MockHttpServletResponse();
FilterChain filterChain = new MockFilterChain() {
@Override
public void doFilter(ServletRequest request, ServletResponse response) {
flash = service.get("my_key");
}
};
filter.doFilter(req, res, filterChain);
assertThat(flash.toString(), is("my other message"));
assertThat(flash.getFlashClass(), is("warning"));
}
use of org.springframework.mock.web.MockHttpSession in project gocd by gocd.
the class TokenInterceptorTest method shouldCreateSessionTokenForNonPOSTRequest.
@Test
public void shouldCreateSessionTokenForNonPOSTRequest() throws Exception {
when(request.getMethod()).thenReturn("GET");
MockHttpSession session = new MockHttpSession();
when(request.getSession()).thenReturn(session);
TokenInterceptor interceptor = new TokenInterceptor(manager);
assertThat(interceptor.preHandle(request, response, mock(Object.class)), is(true));
verify(request).getMethod();
verify(manager).create(session);
verify(request).getSession();
}
use of org.springframework.mock.web.MockHttpSession in project ORCID-Source by ORCID.
the class FundingsControllerTest method testGetFundingsJson.
@Test
public void testGetFundingsJson() {
when(localeManager.getLocale()).thenReturn(new Locale("us", "EN"));
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpSession session = new MockHttpSession();
request.setSession(session);
request.addPreferredLocale(new Locale("us", "EN"));
List<FundingForm> fundings = fundingController.getFundingsJson(request, "1");
assertNotNull(fundings);
assertEquals(1, fundings.size());
FundingForm funding = fundings.get(0);
List<Contributor> contributors = funding.getContributors();
Contributor contributor = contributors.get(0);
assertNull(contributor.getEmail());
assertEquals("Jaylen Kessler", contributor.getCreditName().getValue());
contributor = contributors.get(1);
assertNull(contributor.getEmail());
assertEquals("John Smith", contributor.getCreditName().getValue());
contributor = contributors.get(2);
assertNull(contributor.getEmail());
assertEquals("Credit Name", contributor.getCreditName().getValue());
// contributor is an ORCID user with private name
contributor = contributors.get(3);
assertNull(contributor.getEmail());
assertNull(contributor.getCreditName().getValue());
}
use of org.springframework.mock.web.MockHttpSession in project cloudstack by apache.
the class HttpUtilsTest method validateSessionKeyTest.
@Test
public void validateSessionKeyTest() {
HttpSession session = null;
Map<String, Object[]> params = null;
String sessionKeyString = null;
Cookie[] cookies = null;
final String sessionKeyValue = "randomUniqueSessionID";
// session and sessionKeyString null test
assertFalse(HttpUtils.validateSessionKey(session, params, cookies, sessionKeyString));
sessionKeyString = "sessionkey";
assertFalse(HttpUtils.validateSessionKey(session, params, cookies, sessionKeyString));
// param and cookie null test
session = new MockHttpSession();
session.setAttribute(sessionKeyString, sessionKeyValue);
assertFalse(HttpUtils.validateSessionKey(session, params, cookies, sessionKeyString));
// param null, cookies not null test
params = null;
cookies = new Cookie[] { new Cookie(sessionKeyString, sessionKeyValue) };
assertFalse(HttpUtils.validateSessionKey(session, params, cookies, "randomString"));
assertTrue(HttpUtils.validateSessionKey(session, params, cookies, sessionKeyString));
// param not null, cookies null test
params = new HashMap<String, Object[]>();
params.put(sessionKeyString, new String[] { "randomString" });
cookies = null;
assertFalse(HttpUtils.validateSessionKey(session, params, cookies, sessionKeyString));
params.put(sessionKeyString, new String[] { sessionKeyValue });
assertTrue(HttpUtils.validateSessionKey(session, params, cookies, sessionKeyString));
// both param and cookies not null test
params = new HashMap<String, Object[]>();
cookies = new Cookie[] { new Cookie(sessionKeyString, sessionKeyValue) };
params.put(sessionKeyString, new String[] { "incorrectValue" });
assertFalse(HttpUtils.validateSessionKey(session, params, cookies, sessionKeyString));
params.put(sessionKeyString, new String[] { sessionKeyValue });
assertTrue(HttpUtils.validateSessionKey(session, params, cookies, sessionKeyString));
}
Aggregations