Search in sources :

Example 11 with PasswordChangeRequest

use of org.apereo.cas.pm.PasswordChangeRequest in project cas by apereo.

the class PasswordChangeActionTests method verifyFailsValidation.

@Test
public void verifyFailsValidation() throws Exception {
    val context = new MockRequestContext();
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
    RequestContextHolder.setRequestContext(context);
    ExternalContextHolder.setExternalContext(context.getExternalContext());
    WebUtils.putCredential(context, RegisteredServiceTestUtils.getCredentialsWithSameUsernameAndPassword("casuser"));
    val changeReq = new PasswordChangeRequest();
    changeReq.setUsername("casuser");
    changeReq.setPassword("123456");
    context.getFlowScope().put(PasswordManagementWebflowConfigurer.FLOW_VAR_ID_PASSWORD, changeReq);
    assertEquals(CasWebflowConstants.TRANSITION_ID_ERROR, passwordChangeAction.execute(context).getId());
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) PasswordChangeRequest(org.apereo.cas.pm.PasswordChangeRequest) MockRequestContext(org.springframework.webflow.test.MockRequestContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) MockServletContext(org.springframework.mock.web.MockServletContext) Test(org.junit.jupiter.api.Test)

Example 12 with PasswordChangeRequest

use of org.apereo.cas.pm.PasswordChangeRequest in project cas by apereo.

the class GroovyPasswordHistoryServiceTests method verifyValidity.

@Test
public void verifyValidity() {
    val request = new PasswordChangeRequest("casuser", "password", "password");
    assertFalse(passwordHistoryService.exists(request));
    assertTrue(passwordHistoryService.store(request));
    assertTrue(passwordHistoryService.fetchAll().isEmpty());
    assertTrue(passwordHistoryService.fetch("casuser").isEmpty());
    assertDoesNotThrow(new Executable() {

        @Override
        public void execute() throws Throwable {
            passwordHistoryService.remove("casuser");
            passwordHistoryService.removeAll();
        }
    });
}
Also used : lombok.val(lombok.val) PasswordChangeRequest(org.apereo.cas.pm.PasswordChangeRequest) Executable(org.junit.jupiter.api.function.Executable) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 13 with PasswordChangeRequest

use of org.apereo.cas.pm.PasswordChangeRequest in project cas by apereo.

the class JdbcPasswordHistoryServiceTests method verifyOperation.

@Test
public void verifyOperation() {
    val request = new PasswordChangeRequest("casuser", "password", "password");
    assertFalse(passwordHistoryService.exists(request));
    assertTrue(passwordHistoryService.store(request));
    assertTrue(passwordHistoryService.exists(request));
    assertFalse(passwordHistoryService.fetchAll().isEmpty());
    assertFalse(passwordHistoryService.fetch("casuser").isEmpty());
    passwordHistoryService.remove("casuser");
    assertFalse(passwordHistoryService.exists(request));
}
Also used : lombok.val(lombok.val) PasswordChangeRequest(org.apereo.cas.pm.PasswordChangeRequest) Test(org.junit.jupiter.api.Test)

Aggregations

lombok.val (lombok.val)13 PasswordChangeRequest (org.apereo.cas.pm.PasswordChangeRequest)13 Test (org.junit.jupiter.api.Test)13 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)5 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)5 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)5 MockServletContext (org.springframework.mock.web.MockServletContext)5 ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)5 MockRequestContext (org.springframework.webflow.test.MockRequestContext)5 UsernamePasswordCredential (org.apereo.cas.authentication.credential.UsernamePasswordCredential)4 PasswordManagementProperties (org.apereo.cas.configuration.model.support.pm.PasswordManagementProperties)1 Executable (org.junit.jupiter.api.function.Executable)1