Search in sources :

Example 6 with GoogleAuthenticatorMultifactorProperties

use of org.apereo.cas.configuration.model.support.mfa.gauth.GoogleAuthenticatorMultifactorProperties 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 7 with GoogleAuthenticatorMultifactorProperties

use of org.apereo.cas.configuration.model.support.mfa.gauth.GoogleAuthenticatorMultifactorProperties 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 8 with GoogleAuthenticatorMultifactorProperties

use of org.apereo.cas.configuration.model.support.mfa.gauth.GoogleAuthenticatorMultifactorProperties in project cas by apereo.

the class RestGoogleAuthenticatorTokenCredentialRepositoryTests method verifySave.

@Test
public void verifySave() throws Exception {
    val props = new GoogleAuthenticatorMultifactorProperties();
    props.getRest().setUrl("http://localhost:8553");
    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(8553, new ByteArrayResource(entity.getBytes(UTF_8), "Output"), OK)) {
        webServer.start();
        assertDoesNotThrow(new Executable() {

            @Override
            public void execute() {
                val toSave = OneTimeTokenAccount.builder().username(account.getUsername()).secretKey(account.getSecretKey()).validationCode(0).scratchCodes(List.of()).name(UUID.randomUUID().toString()).build();
                repo.save(toSave);
            }
        });
    }
}
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) Executable(org.junit.jupiter.api.function.Executable) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 9 with GoogleAuthenticatorMultifactorProperties

use of org.apereo.cas.configuration.model.support.mfa.gauth.GoogleAuthenticatorMultifactorProperties in project cas by apereo.

the class RestGoogleAuthenticatorTokenCredentialRepositoryTests method verifySaveFail.

@Test
public void verifySaveFail() {
    val props = new GoogleAuthenticatorMultifactorProperties();
    props.getRest().setUrl("http://localhost:8554");
    val repo = new RestGoogleAuthenticatorTokenCredentialRepository(googleAuthenticatorInstance, props, CipherExecutor.noOpOfStringToString());
    val account = repo.create(UUID.randomUUID().toString());
    try (val webServer = new MockWebServer(8554, new ByteArrayResource(StringUtils.EMPTY.getBytes(UTF_8), "Output"), HttpStatus.BAD_REQUEST)) {
        webServer.start();
        assertNull(repo.update(account));
    }
}
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 10 with GoogleAuthenticatorMultifactorProperties

use of org.apereo.cas.configuration.model.support.mfa.gauth.GoogleAuthenticatorMultifactorProperties in project cas by apereo.

the class RestGoogleAuthenticatorTokenCredentialRepositoryTests method verifyDelete.

@Test
public void verifyDelete() {
    val props = new GoogleAuthenticatorMultifactorProperties();
    props.getRest().setUrl("http://localhost:8550");
    val repo = new RestGoogleAuthenticatorTokenCredentialRepository(googleAuthenticatorInstance, props, CipherExecutor.noOpOfStringToString());
    try (val webServer = new MockWebServer(8550, new ByteArrayResource("1".getBytes(UTF_8), "Output"), OK)) {
        webServer.start();
        assertDoesNotThrow(new Executable() {

            @Override
            public void execute() {
                repo.delete("casuser");
                repo.delete(12345);
                repo.deleteAll();
            }
        });
    }
}
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) Executable(org.junit.jupiter.api.function.Executable) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

lombok.val (lombok.val)10 GoogleAuthenticatorMultifactorProperties (org.apereo.cas.configuration.model.support.mfa.gauth.GoogleAuthenticatorMultifactorProperties)10 MockWebServer (org.apereo.cas.util.MockWebServer)10 Test (org.junit.jupiter.api.Test)10 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)10 ByteArrayResource (org.springframework.core.io.ByteArrayResource)10 Executable (org.junit.jupiter.api.function.Executable)2