Search in sources :

Example 16 with MockWebServer

use of org.apereo.cas.util.MockWebServer in project cas by apereo.

the class RestGoogleAuthenticatorTokenCredentialRepositoryTests method verifyCount.

@Test
public void verifyCount() {
    val props = new GoogleAuthenticatorMultifactorProperties();
    props.getRest().setUrl("http://localhost:8552");
    val repo = new RestGoogleAuthenticatorTokenCredentialRepository(googleAuthenticatorInstance, props, CipherExecutor.noOpOfStringToString());
    try (val webServer = new MockWebServer(8552, new ByteArrayResource("1".getBytes(UTF_8), "Output"), OK)) {
        webServer.start();
        assertEquals(1, repo.count());
    }
}
Also used : lombok.val(lombok.val) GoogleAuthenticatorMultifactorProperties(org.apereo.cas.configuration.model.support.mfa.gauth.GoogleAuthenticatorMultifactorProperties) MockWebServer(org.apereo.cas.util.MockWebServer) ByteArrayResource(org.springframework.core.io.ByteArrayResource) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 17 with MockWebServer

use of org.apereo.cas.util.MockWebServer in project cas by apereo.

the class RestGoogleAuthenticatorTokenCredentialRepositoryTests method verifyCountByUser.

@Test
public void verifyCountByUser() {
    val props = new GoogleAuthenticatorMultifactorProperties();
    props.getRest().setUrl("http://localhost:8596");
    val repo = new RestGoogleAuthenticatorTokenCredentialRepository(googleAuthenticatorInstance, props, CipherExecutor.noOpOfStringToString());
    try (val webServer = new MockWebServer(8596, new ByteArrayResource("1".getBytes(UTF_8), "Output"), OK)) {
        webServer.start();
        assertEquals(1, repo.count("casuser"));
    }
}
Also used : lombok.val(lombok.val) GoogleAuthenticatorMultifactorProperties(org.apereo.cas.configuration.model.support.mfa.gauth.GoogleAuthenticatorMultifactorProperties) MockWebServer(org.apereo.cas.util.MockWebServer) ByteArrayResource(org.springframework.core.io.ByteArrayResource) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 18 with MockWebServer

use of org.apereo.cas.util.MockWebServer in project cas by apereo.

the class RestGoogleAuthenticatorTokenCredentialRepositoryTests method verifyGetByIdAndUser.

@Test
public void verifyGetByIdAndUser() throws Exception {
    val props = new GoogleAuthenticatorMultifactorProperties();
    props.getRest().setUrl("http://localhost:8552");
    val repo = new RestGoogleAuthenticatorTokenCredentialRepository(googleAuthenticatorInstance, props, CipherExecutor.noOpOfStringToString());
    val account = repo.create(UUID.randomUUID().toString());
    val entity = MAPPER.writeValueAsString(account);
    try (val webServer = new MockWebServer(8552, new ByteArrayResource(entity.getBytes(UTF_8), "Results"), OK)) {
        webServer.start();
        assertNotNull(repo.get(account.getUsername(), account.getId()));
    }
}
Also used : lombok.val(lombok.val) GoogleAuthenticatorMultifactorProperties(org.apereo.cas.configuration.model.support.mfa.gauth.GoogleAuthenticatorMultifactorProperties) MockWebServer(org.apereo.cas.util.MockWebServer) ByteArrayResource(org.springframework.core.io.ByteArrayResource) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 19 with MockWebServer

use of org.apereo.cas.util.MockWebServer in project cas by apereo.

the class RestfulPasswordlessUserAccountStoreTests method verifyFailsAction.

@Test
public void verifyFailsAction() {
    try (val webServer = new MockWebServer(9291, new ByteArrayResource("###".getBytes(StandardCharsets.UTF_8), "REST Output"), MediaType.APPLICATION_JSON_VALUE)) {
        webServer.start();
        val user = passwordlessUserAccountStore.findUser("casuser");
        assertTrue(user.isEmpty());
    }
}
Also used : lombok.val(lombok.val) MockWebServer(org.apereo.cas.util.MockWebServer) ByteArrayResource(org.springframework.core.io.ByteArrayResource) Test(org.junit.jupiter.api.Test)

Example 20 with MockWebServer

use of org.apereo.cas.util.MockWebServer in project cas by apereo.

the class RestAuthenticationHandlerTests method verifyUnauthorized.

@Test
public void verifyUnauthorized() {
    try (val webServer = new MockWebServer(8081, HttpStatus.UNAUTHORIZED)) {
        webServer.start();
        assertThrows(FailedLoginException.class, () -> authenticationHandler.authenticate(CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword()));
    }
}
Also used : lombok.val(lombok.val) MockWebServer(org.apereo.cas.util.MockWebServer) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

MockWebServer (org.apereo.cas.util.MockWebServer)175 lombok.val (lombok.val)173 Test (org.junit.jupiter.api.Test)157 ByteArrayResource (org.springframework.core.io.ByteArrayResource)151 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)82 MockRequestContext (org.springframework.webflow.test.MockRequestContext)36 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)32 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)31 ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)26 MockServletContext (org.springframework.mock.web.MockServletContext)25 CasConfigurationProperties (org.apereo.cas.configuration.CasConfigurationProperties)15 ClassPathResource (org.springframework.core.io.ClassPathResource)15 ClientInfo (org.apereo.inspektr.common.web.ClientInfo)13 GoogleAuthenticatorMultifactorProperties (org.apereo.cas.configuration.model.support.mfa.gauth.GoogleAuthenticatorMultifactorProperties)10 AdaptiveAuthenticationProperties (org.apereo.cas.configuration.model.core.authentication.AdaptiveAuthenticationProperties)9 Executable (org.junit.jupiter.api.function.Executable)8 RestEndpointProperties (org.apereo.cas.configuration.model.RestEndpointProperties)7 SamlRegisteredService (org.apereo.cas.support.saml.services.SamlRegisteredService)7 Service (org.apereo.cas.authentication.principal.Service)4 GoogleRecaptchaProperties (org.apereo.cas.configuration.model.support.captcha.GoogleRecaptchaProperties)4