Search in sources :

Example 31 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 {
    final OAuthRegisteredService 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);
    final MockRequestContext ctx = new MockRequestContext();
    WebUtils.putService(ctx, RegisteredServiceTestUtils.getService("https://www.example.org?client_id=id&client_secret=secret&redirect_uri=https://oauth.example.org"));
    final Event event = oauth20RegisteredServiceUIAction.execute(ctx);
    assertEquals("success", event.getId());
    final DefaultRegisteredServiceUserInterfaceInfo 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 : OAuthRegisteredService(org.apereo.cas.support.oauth.services.OAuthRegisteredService) Event(org.springframework.webflow.execution.Event) DefaultRegisteredServiceUserInterfaceInfo(org.apereo.cas.web.flow.services.DefaultRegisteredServiceUserInterfaceInfo) MockRequestContext(org.springframework.webflow.test.MockRequestContext) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 32 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 {
    final MockRequestContext ctx = new MockRequestContext();
    WebUtils.putService(ctx, RegisteredServiceTestUtils.getService());
    final Event event = oauth20RegisteredServiceUIAction.execute(ctx);
    assertEquals("success", event.getId());
    final Serializable mdui = WebUtils.getServiceUserInterfaceMetadata(ctx, Serializable.class);
    assertNull(mdui);
}
Also used : Serializable(java.io.Serializable) Event(org.springframework.webflow.execution.Event) MockRequestContext(org.springframework.webflow.test.MockRequestContext) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 33 with MockRequestContext

use of org.springframework.webflow.test.MockRequestContext in project cas by apereo.

the class BaseLdapSpnegoKnownClientSystemsFilterActionTests method ensureLdapAttributeShouldDoSpnego.

@Test
public void ensureLdapAttributeShouldDoSpnego() throws Exception {
    final MockRequestContext ctx = new MockRequestContext();
    final MockHttpServletRequest req = new MockHttpServletRequest();
    req.setRemoteAddr("localhost");
    final ServletExternalContext extCtx = new ServletExternalContext(new MockServletContext(), req, new MockHttpServletResponse());
    ctx.setExternalContext(extCtx);
    final Event ev = action.execute(ctx);
    assertEquals(ev.getId(), new EventFactorySupport().yes(this).getId());
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) Event(org.springframework.webflow.execution.Event) MockRequestContext(org.springframework.webflow.test.MockRequestContext) MockServletContext(org.springframework.mock.web.MockServletContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) EventFactorySupport(org.springframework.webflow.action.EventFactorySupport) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 34 with MockRequestContext

use of org.springframework.webflow.test.MockRequestContext in project cas by apereo.

the class SpnegoKnownClientSystemsFilterActionTests method ensureHostnameAndIpShouldDoSpnego.

@Test
public void ensureHostnameAndIpShouldDoSpnego() {
    final HostNameSpnegoKnownClientSystemsFilterAction action = new HostNameSpnegoKnownClientSystemsFilterAction(RegexUtils.createPattern("74\\..+"), "", 0, "\\w+\\.\\w+\\.\\w+");
    final MockRequestContext ctx = new MockRequestContext();
    final MockHttpServletRequest req = new MockHttpServletRequest();
    req.setRemoteAddr(ALTERNATE_REMOTE_IP);
    final ServletExternalContext extCtx = new ServletExternalContext(new MockServletContext(), req, new MockHttpServletResponse());
    ctx.setExternalContext(extCtx);
    final Event ev = action.doExecute(ctx);
    assertEquals(ev.getId(), new EventFactorySupport().yes(this).getId());
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) Event(org.springframework.webflow.execution.Event) MockRequestContext(org.springframework.webflow.test.MockRequestContext) MockServletContext(org.springframework.mock.web.MockServletContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) EventFactorySupport(org.springframework.webflow.action.EventFactorySupport) Test(org.junit.Test)

Example 35 with MockRequestContext

use of org.springframework.webflow.test.MockRequestContext in project cas by apereo.

the class SpnegoKnownClientSystemsFilterActionTests method ensureRemoteIpShouldNotBeChecked.

@Test
public void ensureRemoteIpShouldNotBeChecked() {
    final BaseSpnegoKnownClientSystemsFilterAction action = new BaseSpnegoKnownClientSystemsFilterAction(RegexUtils.createPattern("^192\\.158\\..+"), "", 0);
    final MockRequestContext ctx = new MockRequestContext();
    final MockHttpServletRequest req = new MockHttpServletRequest();
    req.setRemoteAddr("193.158.5.781");
    final ServletExternalContext extCtx = new ServletExternalContext(new MockServletContext(), req, new MockHttpServletResponse());
    ctx.setExternalContext(extCtx);
    final Event ev = action.doExecute(ctx);
    assertNotEquals(ev.getId(), new EventFactorySupport().yes(this).getId());
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) Event(org.springframework.webflow.execution.Event) MockRequestContext(org.springframework.webflow.test.MockRequestContext) MockServletContext(org.springframework.mock.web.MockServletContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) EventFactorySupport(org.springframework.webflow.action.EventFactorySupport) Test(org.junit.Test)

Aggregations

MockRequestContext (org.springframework.webflow.test.MockRequestContext)73 Test (org.junit.Test)68 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)53 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)53 ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)50 MockServletContext (org.springframework.mock.web.MockServletContext)46 Event (org.springframework.webflow.execution.Event)34 EventFactorySupport (org.springframework.webflow.action.EventFactorySupport)14 TicketGrantingTicket (org.apereo.cas.ticket.TicketGrantingTicket)10 DeliveryOptions (org.opennms.reporting.core.DeliveryOptions)8 Credential (org.apereo.cas.authentication.Credential)7 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)7 AuthenticationResult (org.apereo.cas.authentication.AuthenticationResult)5 Service (org.apereo.cas.authentication.principal.Service)5 CentralAuthenticationService (org.apereo.cas.CentralAuthenticationService)4 Clients (org.pac4j.core.client.Clients)4 FacebookClient (org.pac4j.oauth.client.FacebookClient)4 MutableAttributeMap (org.springframework.webflow.core.collection.MutableAttributeMap)4 Authentication (org.apereo.cas.authentication.Authentication)3 SamlMetadataUIInfo (org.apereo.cas.support.saml.mdui.SamlMetadataUIInfo)3