use of org.springframework.webflow.test.MockRequestContext in project cas by apereo.
the class OAuth20RegisteredServiceUIActionTests method verifyOAuthActionWithoutMDUI.
@Test
public void verifyOAuthActionWithoutMDUI() throws Exception {
val ctx = new MockRequestContext();
val service = RegisteredServiceTestUtils.getService();
WebUtils.putServiceIntoFlowScope(ctx, service);
val svc = RegisteredServiceTestUtils.getRegisteredService(service.getId());
servicesManager.save(svc);
val event = oauth20RegisteredServiceUIAction.execute(ctx);
assertEquals(CasWebflowConstants.TRANSITION_ID_SUCCESS, event.getId());
val mdui = WebUtils.getServiceUserInterfaceMetadata(ctx, Serializable.class);
assertNull(mdui);
}
use of org.springframework.webflow.test.MockRequestContext in project cas by apereo.
the class OAuth20RegisteredServiceUIActionTests method verifyOAuthActionWithMDUI.
@Test
public void verifyOAuthActionWithMDUI() throws Exception {
val svc = new OAuthRegisteredService();
svc.setClientId("id");
svc.setName("oauth");
svc.setDescription("description");
svc.setClientSecret("secret");
svc.setInformationUrl("info");
svc.setPrivacyUrl("privacy");
svc.setServiceId("https://oauth\\.example\\.org.*");
svc.setLogo("logo");
servicesManager.save(svc);
val ctx = new MockRequestContext();
val service = RegisteredServiceTestUtils.getService("https://www.example.org?client_id=id&client_secret=secret&redirect_uri=https://oauth.example.org");
service.getAttributes().put(OAuth20Constants.CLIENT_ID, List.of("id"));
WebUtils.putServiceIntoFlowScope(ctx, service);
val event = oauth20RegisteredServiceUIAction.execute(ctx);
assertEquals(CasWebflowConstants.TRANSITION_ID_SUCCESS, event.getId());
val mdui = WebUtils.getServiceUserInterfaceMetadata(ctx, DefaultRegisteredServiceUserInterfaceInfo.class);
assertNotNull(mdui);
assertEquals(mdui.getDisplayName(), svc.getName());
assertEquals(mdui.getInformationURL(), svc.getInformationUrl());
assertEquals(mdui.getDescription(), svc.getDescription());
assertEquals(mdui.getPrivacyStatementURL(), svc.getPrivacyUrl());
assertEquals(mdui.getLogoUrl(), svc.getLogo());
}
use of org.springframework.webflow.test.MockRequestContext in project cas by apereo.
the class DefaultDelegatedClientIdentityProviderRedirectionStrategyTests method getMockRequestContext.
private static MockRequestContext getMockRequestContext() {
val context = new MockRequestContext();
val request = new MockHttpServletRequest();
val response = new MockHttpServletResponse();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
RequestContextHolder.setRequestContext(context);
ExternalContextHolder.setExternalContext(context.getExternalContext());
return context;
}
use of org.springframework.webflow.test.MockRequestContext in project cas by apereo.
the class OneTimeTokenAuthenticationWebflowActionTests method verifyAction.
@Test
public void verifyAction() {
val resolver = mock(CasWebflowEventResolver.class);
when(resolver.resolveSingle(any())).thenReturn(new EventFactorySupport().event(this, CasWebflowConstants.TRANSITION_ID_SUCCESS));
val action = new OneTimeTokenAuthenticationWebflowAction(resolver);
val context = new MockRequestContext();
val request = new MockHttpServletRequest();
val response = new MockHttpServletResponse();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
RequestContextHolder.setRequestContext(context);
ExternalContextHolder.setExternalContext(context.getExternalContext());
assertEquals(CasWebflowConstants.TRANSITION_ID_SUCCESS, action.doExecute(context).getId());
}
use of org.springframework.webflow.test.MockRequestContext in project cas by apereo.
the class OneTimeTokenAccountSaveRegistrationActionTests method verifyCreateAccount.
@Test
public void verifyCreateAccount() {
val props = new CasConfigurationProperties();
val account = OneTimeTokenAccount.builder().username("casuser").secretKey(UUID.randomUUID().toString()).validationCode(123456).scratchCodes(List.of()).name(UUID.randomUUID().toString()).build();
val repository = mock(OneTimeTokenCredentialRepository.class);
val action = new OneTimeTokenAccountSaveRegistrationAction(repository, props);
val context = new MockRequestContext();
val request = new MockHttpServletRequest();
request.addParameter(OneTimeTokenAccountSaveRegistrationAction.REQUEST_PARAMETER_ACCOUNT_NAME, "ExampleAccount");
val response = new MockHttpServletResponse();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
RequestContextHolder.setRequestContext(context);
ExternalContextHolder.setExternalContext(context.getExternalContext());
WebUtils.putAuthentication(RegisteredServiceTestUtils.getAuthentication("casuser"), context);
context.getFlowScope().put(OneTimeTokenAccountCreateRegistrationAction.FLOW_SCOPE_ATTR_ACCOUNT, account);
assertEquals(CasWebflowConstants.TRANSITION_ID_SUCCESS, action.doExecute(context).getId());
}
Aggregations