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());
}
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()));
}
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());
}
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());
}
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());
}
Aggregations