@Test
    void verifyOperations() throws Throwable {
        val port = URI.create(casProperties.getAuthn().getRest().getFirst().getUri()).getPort();
        val instant = Instant.now(Clock.systemUTC()).plus(10, ChronoUnit.DAYS);
        val formatted = DateTimeFormatter.RFC_1123_DATE_TIME
            .withZone(ZoneOffset.UTC)
            .format(instant);


        try (val webServer = new MockWebServer(port)) {
            webServer.start();
            webServer.responseBodyJson(PrincipalFactoryUtils.newPrincipalFactory().createPrincipal("casuser"));

            val headers = new HashMap<String, String>();
            headers.put(RestAuthenticationHandler.HEADER_NAME_CAS_PASSWORD_EXPIRATION_DATE, formatted);
            headers.put(RestAuthenticationHandler.HEADER_NAME_CAS_WARNING, "warning1");

            webServer.headers(headers);
            webServer.responseStatus(HttpStatus.OK);

            val res = getFirstHandler().authenticate(CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword(), mock(Service.class));
            assertEquals("casuser", res.getPrincipal().getId());
            assertEquals(1, webServer.getRequestCount());

            webServer.responseBody("{}");
            assertThrows(FailedLoginException.class,
                () -> getFirstHandler().authenticate(CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword(), mock(Service.class)));
            assertEquals(2, webServer.getRequestCount());

            webServer.responseStatus(HttpStatus.FORBIDDEN);
            assertThrows(AccountDisabledException.class,
                () -> getFirstHandler().authenticate(CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword(), mock(Service.class)));
            assertEquals(3, webServer.getRequestCount());


            webServer.responseStatus(HttpStatus.UNAUTHORIZED);
            assertThrows(FailedLoginException.class,
                () -> getFirstHandler().authenticate(CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword(), mock(Service.class)));

            webServer.responseStatus(HttpStatus.REQUEST_TIMEOUT);
            assertThrows(FailedLoginException.class,
                () -> getFirstHandler().authenticate(CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword(), mock(Service.class)));

            webServer.responseStatus(HttpStatus.LOCKED);
            assertThrows(AccountLockedException.class,
                () -> getFirstHandler().authenticate(CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword(), mock(Service.class)));

            webServer.responseStatus(HttpStatus.PRECONDITION_REQUIRED);
            assertThrows(AccountPasswordMustChangeException.class,
                () -> getFirstHandler().authenticate(CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword(), mock(Service.class)));

            webServer.responseStatus(HttpStatus.PRECONDITION_FAILED);
            assertThrows(AccountExpiredException.class,
                () -> getFirstHandler().authenticate(CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword(), mock(Service.class)));

            webServer.responseStatus(HttpStatus.NOT_FOUND);
            assertThrows(AccountNotFoundException.class,
                () -> getFirstHandler().authenticate(CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword(), mock(Service.class)));
        }
    }
This is {@link RestAuthenticationHandlerTests}.

@author Misagh Moayyed
@since 5.0.0
support/cas-server-support-rest-authentication/src/test/java/org/apereo/cas/adaptors/rest/RestAuthenticationHandlerTests.java