Search in sources :

Example 11 with Order

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

the class GroovyScriptMultifactorAuthenticationTriggerTests method verifyScriptDoesNotExist.

@Test
@Order(2)
public void verifyScriptDoesNotExist() {
    val props = new CasConfigurationProperties();
    var trigger = new GroovyScriptMultifactorAuthenticationTrigger(props, applicationContext);
    var result = trigger.isActivated(authentication, registeredService, this.httpRequest, this.httpResponse, mock(Service.class));
    assertFalse(result.isPresent());
    props.getAuthn().getMfa().getGroovyScript().setLocation(new ClassPathResource("DoesNotExist.groovy"));
    trigger = new GroovyScriptMultifactorAuthenticationTrigger(props, applicationContext);
    result = trigger.isActivated(authentication, registeredService, this.httpRequest, this.httpResponse, mock(Service.class));
    assertFalse(result.isPresent());
}
Also used : lombok.val(lombok.val) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) Service(org.apereo.cas.authentication.principal.Service) ClassPathResource(org.springframework.core.io.ClassPathResource) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Order(org.junit.jupiter.api.Order) Test(org.junit.jupiter.api.Test)

Example 12 with Order

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

the class GroovyScriptMultifactorAuthenticationTriggerTests method verifyNoProvider.

@Test
@Order(0)
@Tag("DisableProviderRegistration")
public void verifyNoProvider() {
    val props = new CasConfigurationProperties();
    props.getAuthn().getMfa().getGroovyScript().setLocation(new ClassPathResource("GroovyMfaTrigger.groovy"));
    val trigger = new GroovyScriptMultifactorAuthenticationTrigger(props, applicationContext);
    assertThrows(AuthenticationException.class, () -> trigger.isActivated(authentication, registeredService, this.httpRequest, this.httpResponse, mock(Service.class)));
}
Also used : lombok.val(lombok.val) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) ClassPathResource(org.springframework.core.io.ClassPathResource) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Order(org.junit.jupiter.api.Order) Test(org.junit.jupiter.api.Test) Tag(org.junit.jupiter.api.Tag)

Example 13 with Order

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

the class GroovyScriptMultifactorAuthenticationTriggerTests method verifyOperationByProvider.

@Test
@Order(1)
public void verifyOperationByProvider() {
    val props = new CasConfigurationProperties();
    props.getAuthn().getMfa().getGroovyScript().setLocation(new ClassPathResource("GroovyMfaTrigger.groovy"));
    val trigger = new GroovyScriptMultifactorAuthenticationTrigger(props, applicationContext);
    var result = trigger.isActivated(authentication, registeredService, this.httpRequest, this.httpResponse, mock(Service.class));
    assertTrue(result.isPresent());
    val service = MultifactorAuthenticationTestUtils.getService("nomfa");
    result = trigger.isActivated(authentication, registeredService, this.httpRequest, this.httpResponse, service);
    assertFalse(result.isPresent());
}
Also used : lombok.val(lombok.val) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) Service(org.apereo.cas.authentication.principal.Service) ClassPathResource(org.springframework.core.io.ClassPathResource) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Order(org.junit.jupiter.api.Order) Test(org.junit.jupiter.api.Test)

Example 14 with Order

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

the class GlobalMultifactorAuthenticationTriggerTests method verifyOperationByUnresolvedProvider.

@Test
@Order(4)
public void verifyOperationByUnresolvedProvider() {
    val props = new CasConfigurationProperties();
    props.getAuthn().getMfa().getTriggers().getGlobal().setGlobalProviderId("does-not-exist");
    val trigger = new GlobalMultifactorAuthenticationTrigger(props, applicationContext, (providers, service, principal) -> providers.iterator().next());
    assertThrows(AuthenticationException.class, () -> trigger.isActivated(authentication, registeredService, this.httpRequest, this.httpResponse, mock(Service.class)));
}
Also used : lombok.val(lombok.val) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Order(org.junit.jupiter.api.Order) Test(org.junit.jupiter.api.Test)

Example 15 with Order

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

the class GlobalMultifactorAuthenticationTriggerTests method verifyOperationByProvider.

@Test
@Order(1)
public void verifyOperationByProvider() {
    val props = new CasConfigurationProperties();
    props.getAuthn().getMfa().getTriggers().getGlobal().setGlobalProviderId(TestMultifactorAuthenticationProvider.ID);
    val trigger = new GlobalMultifactorAuthenticationTrigger(props, applicationContext, (providers, service, principal) -> providers.iterator().next());
    val result = trigger.isActivated(authentication, registeredService, this.httpRequest, this.httpResponse, mock(Service.class));
    assertTrue(result.isPresent());
}
Also used : lombok.val(lombok.val) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) Service(org.apereo.cas.authentication.principal.Service) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Order(org.junit.jupiter.api.Order) 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