Search in sources :

Example 91 with MockRequestContext

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);
}
Also used : lombok.val(lombok.val) MockRequestContext(org.springframework.webflow.test.MockRequestContext) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 92 with MockRequestContext

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());
}
Also used : lombok.val(lombok.val) OAuthRegisteredService(org.apereo.cas.support.oauth.services.OAuthRegisteredService) MockRequestContext(org.springframework.webflow.test.MockRequestContext) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 93 with MockRequestContext

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;
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) MockRequestContext(org.springframework.webflow.test.MockRequestContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) MockServletContext(org.springframework.mock.web.MockServletContext)

Example 94 with MockRequestContext

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());
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) MockRequestContext(org.springframework.webflow.test.MockRequestContext) EventFactorySupport(org.springframework.webflow.action.EventFactorySupport) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) MockServletContext(org.apereo.cas.util.MockServletContext) Test(org.junit.jupiter.api.Test)

Example 95 with MockRequestContext

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());
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) MockRequestContext(org.springframework.webflow.test.MockRequestContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) MockServletContext(org.apereo.cas.util.MockServletContext) Test(org.junit.jupiter.api.Test)

Aggregations

MockRequestContext (org.springframework.webflow.test.MockRequestContext)517 lombok.val (lombok.val)483 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)466 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)458 ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)454 Test (org.junit.jupiter.api.Test)450 MockServletContext (org.springframework.mock.web.MockServletContext)404 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)132 MockServletContext (org.apereo.cas.util.MockServletContext)46 MockTicketGrantingTicket (org.apereo.cas.mock.MockTicketGrantingTicket)43 MockWebServer (org.apereo.cas.util.MockWebServer)36 ByteArrayResource (org.springframework.core.io.ByteArrayResource)36 ClientInfo (org.apereo.inspektr.common.web.ClientInfo)35 Test (org.junit.Test)29 Event (org.springframework.webflow.execution.Event)26 Transition (org.springframework.webflow.engine.Transition)25 LiteralExpression (org.springframework.binding.expression.support.LiteralExpression)23 EventFactorySupport (org.springframework.webflow.action.EventFactorySupport)23 DefaultTargetStateResolver (org.springframework.webflow.engine.support.DefaultTargetStateResolver)23 DefaultTransitionCriteria (org.springframework.webflow.engine.support.DefaultTransitionCriteria)23