Search in sources :

Example 36 with Order

use of org.junit.jupiter.api.Order in project cas by apereo.

the class MultifactorAuthenticationVerifyTrustActionTests method verifyDeviceNotTrusted.

@Test
@Order(1)
public void verifyDeviceNotTrusted() throws Exception {
    val r = getMultifactorAuthenticationTrustRecord();
    r.setRecordDate(ZonedDateTime.now(ZoneOffset.UTC).minusSeconds(5));
    getMfaTrustEngine().save(r);
    val context = new MockRequestContext();
    WebUtils.putServiceIntoFlowScope(context, RegisteredServiceTestUtils.getService());
    WebUtils.putRegisteredService(context, RegisteredServiceTestUtils.getRegisteredService("sample-service", Collections.EMPTY_MAP));
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), new MockHttpServletRequest(), new MockHttpServletResponse()));
    WebUtils.putAuthentication(CoreAuthenticationTestUtils.getAuthentication(r.getPrincipal()), context);
    assertEquals(CasWebflowConstants.TRANSITION_ID_NO, mfaVerifyTrustAction.execute(context).getId());
}
Also used : lombok.val(lombok.val) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockRequestContext(org.springframework.webflow.test.MockRequestContext) MockServletContext(org.springframework.mock.web.MockServletContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Order(org.junit.jupiter.api.Order) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 37 with Order

use of org.junit.jupiter.api.Order in project cas by apereo.

the class MultifactorAuthenticationVerifyTrustActionTests method verifyDeviceTrusted.

@Test
@Order(2)
public void verifyDeviceTrusted() throws Exception {
    val context = new MockRequestContext();
    WebUtils.putServiceIntoFlowScope(context, RegisteredServiceTestUtils.getService());
    WebUtils.putRegisteredService(context, RegisteredServiceTestUtils.getRegisteredService("sample-service", Collections.EMPTY_MAP));
    val request = new MockHttpServletRequest();
    request.setRemoteAddr("123.456.789.000");
    request.setLocalAddr("123.456.789.000");
    request.addHeader(HttpRequestUtils.USER_AGENT_HEADER, "test");
    ClientInfoHolder.setClientInfo(new ClientInfo(request));
    val response = new MockHttpServletResponse();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
    val record = getMultifactorAuthenticationTrustRecord();
    record.setRecordDate(ZonedDateTime.now(ZoneOffset.UTC).minusSeconds(5));
    val deviceFingerprint = deviceFingerprintStrategy.determineFingerprintComponent(record.getPrincipal(), request, response);
    record.setDeviceFingerprint(deviceFingerprint);
    mfaTrustEngine.save(record);
    assertNotNull(response.getCookies());
    assertEquals(response.getCookies().length, 1);
    request.setCookies(response.getCookies());
    val authn = RegisteredServiceTestUtils.getAuthentication(record.getPrincipal());
    WebUtils.putAuthentication(authn, context);
    assertEquals("yes", mfaVerifyTrustAction.execute(context).getId());
    assertTrue(MultifactorAuthenticationTrustUtils.isMultifactorAuthenticationTrustedInScope(context));
    assertTrue(authn.getAttributes().containsKey(casProperties.getAuthn().getMfa().getTrusted().getCore().getAuthenticationContextAttribute()));
}
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) ClientInfo(org.apereo.inspektr.common.web.ClientInfo) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) MockServletContext(org.springframework.mock.web.MockServletContext) Order(org.junit.jupiter.api.Order) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 38 with Order

use of org.junit.jupiter.api.Order in project cas by apereo.

the class MultifactorAuthenticationVerifyTrustActionTests method verifySkipVerify.

@Test
@Order(3)
public void verifySkipVerify() throws Exception {
    val r = getMultifactorAuthenticationTrustRecord();
    r.setRecordDate(ZonedDateTime.now(ZoneOffset.UTC).minusSeconds(5));
    val context = new MockRequestContext();
    WebUtils.putServiceIntoFlowScope(context, RegisteredServiceTestUtils.getService());
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), new MockHttpServletRequest(), new MockHttpServletResponse()));
    assertEquals(CasWebflowConstants.TRANSITION_ID_NO, mfaVerifyTrustAction.execute(context).getId());
    WebUtils.putAuthentication(CoreAuthenticationTestUtils.getAuthentication("bad-principal"), context);
    val registeredService = RegisteredServiceTestUtils.getRegisteredService("sample-service", Collections.EMPTY_MAP);
    registeredService.setMultifactorPolicy(new DefaultRegisteredServiceMultifactorPolicy().setBypassTrustedDeviceEnabled(true));
    WebUtils.putRegisteredService(context, registeredService);
    assertEquals(CasWebflowConstants.TRANSITION_ID_SKIP, mfaVerifyTrustAction.execute(context).getId());
    registeredService.setMultifactorPolicy(new DefaultRegisteredServiceMultifactorPolicy());
    assertEquals(CasWebflowConstants.TRANSITION_ID_NO, mfaVerifyTrustAction.execute(context).getId());
}
Also used : lombok.val(lombok.val) DefaultRegisteredServiceMultifactorPolicy(org.apereo.cas.services.DefaultRegisteredServiceMultifactorPolicy) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockRequestContext(org.springframework.webflow.test.MockRequestContext) MockServletContext(org.springframework.mock.web.MockServletContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Order(org.junit.jupiter.api.Order) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 39 with Order

use of org.junit.jupiter.api.Order in project cas by apereo.

the class SSOSamlIdPPostProfileHandlerControllerTests method verifyPostRequest.

@Test
@Order(4)
public void verifyPostRequest() throws Exception {
    val request = new MockHttpServletRequest();
    request.setMethod("POST");
    val response = new MockHttpServletResponse();
    val authnRequest = getAuthnRequest();
    val xml = SamlUtils.transformSamlObject(openSamlConfigBean, authnRequest).toString();
    request.addParameter(SamlProtocolConstants.PARAMETER_SAML_REQUEST, EncodingUtils.encodeBase64(xml));
    val mv = controller.handleSaml2ProfileSsoPostRequest(response, request);
    assertEquals(HttpStatus.FOUND, mv.getStatus());
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Order(org.junit.jupiter.api.Order) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Test(org.junit.jupiter.api.Test)

Example 40 with Order

use of org.junit.jupiter.api.Order in project cas by apereo.

the class SSOSamlIdPPostProfileHandlerControllerTests method verifyPostRequestWithUnknownCookie.

@Test
@Order(7)
public void verifyPostRequestWithUnknownCookie() throws Exception {
    val response = new MockHttpServletResponse();
    val tgt = new MockTicketGrantingTicket("casuser");
    ticketGrantingTicketCookieGenerator.addCookie(response, tgt.getId());
    val request = new MockHttpServletRequest();
    request.setCookies(response.getCookies());
    request.setMethod("POST");
    val authnRequest = getAuthnRequest();
    val xml = SamlUtils.transformSamlObject(openSamlConfigBean, authnRequest).toString();
    request.addParameter(SamlProtocolConstants.PARAMETER_SAML_REQUEST, EncodingUtils.encodeBase64(xml));
    samlIdPDistributedSessionStore.set(new JEEContext(request, response), SamlProtocolConstants.PARAMETER_SAML_RELAY_STATE, "relay-state");
    val mv = controller.handleSaml2ProfileSsoPostRequest(response, request);
    assertEquals(HttpStatus.FOUND, mv.getStatus());
}
Also used : lombok.val(lombok.val) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) JEEContext(org.pac4j.core.context.JEEContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Order(org.junit.jupiter.api.Order) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Test(org.junit.jupiter.api.Test)

Aggregations

Order (org.junit.jupiter.api.Order)76 TestMethodOrder (org.junit.jupiter.api.TestMethodOrder)76 Test (org.junit.jupiter.api.Test)74 lombok.val (lombok.val)67 CasConfigurationProperties (org.apereo.cas.configuration.CasConfigurationProperties)30 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)24 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)24 Service (org.apereo.cas.authentication.principal.Service)23 MockTicketGrantingTicket (org.apereo.cas.mock.MockTicketGrantingTicket)9 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)9 DefaultMultifactorAuthenticationProviderResolver (org.apereo.cas.authentication.DefaultMultifactorAuthenticationProviderResolver)7 Tag (org.junit.jupiter.api.Tag)6 CountDownLatch (java.util.concurrent.CountDownLatch)5 RepeatedTest (org.junit.jupiter.api.RepeatedTest)5 TicketGrantingTicket (org.apereo.cas.ticket.TicketGrantingTicket)4 TicketGrantingTicketFactory (org.apereo.cas.ticket.TicketGrantingTicketFactory)4 MessageContext (org.opensaml.messaging.context.MessageContext)4 JEEContext (org.pac4j.core.context.JEEContext)4 ClassPathResource (org.springframework.core.io.ClassPathResource)4 URLBuilder (net.shibboleth.utilities.java.support.net.URLBuilder)3