Search in sources :

Example 6 with PasswordChangeRequest

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

the class PasswordChangeActionTests method verifyChange.

@Test
public void verifyChange() 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.getCredentialsWithDifferentUsernameAndPassword("casuser", "Th!$isT3$t"));
    val changeReq = new PasswordChangeRequest();
    changeReq.setUsername("casuser");
    changeReq.setPassword("P@ssword");
    changeReq.setConfirmedPassword("P@ssword");
    context.getFlowScope().put(PasswordManagementWebflowConfigurer.FLOW_VAR_ID_PASSWORD, changeReq);
    assertEquals(CasWebflowConstants.TRANSITION_ID_PASSWORD_UPDATE_SUCCESS, 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 7 with PasswordChangeRequest

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

the class PasswordChangeActionTests method verifyChangeFails.

@Test
public void verifyChangeFails() 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.getCredentialsWithDifferentUsernameAndPassword("bad-credential", "P@ssword"));
    val changeReq = new PasswordChangeRequest();
    changeReq.setUsername("bad-credential");
    changeReq.setPassword("P@ssword");
    changeReq.setConfirmedPassword("P@ssword");
    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 8 with PasswordChangeRequest

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

the class NoOpPasswordManagementServiceTests method verifyChange.

@Test
public void verifyChange() {
    val properties = new PasswordManagementProperties();
    val service = new NoOpPasswordManagementService(CipherExecutor.noOpOfSerializableToString(), "CAS", properties);
    assertFalse(service.changeInternal(RegisteredServiceTestUtils.getCredentialsWithSameUsernameAndPassword("casuser"), new PasswordChangeRequest()));
}
Also used : lombok.val(lombok.val) PasswordManagementProperties(org.apereo.cas.configuration.model.support.pm.PasswordManagementProperties) PasswordChangeRequest(org.apereo.cas.pm.PasswordChangeRequest) Test(org.junit.jupiter.api.Test)

Example 9 with PasswordChangeRequest

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

the class PasswordChangeActionTests method verifyPasswordRejected.

@Test
public void verifyPasswordRejected() 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.getCredentialsWithDifferentUsernameAndPassword("error-credential", "P@ssword"));
    val changeReq = new PasswordChangeRequest();
    changeReq.setUsername("error-credential");
    changeReq.setPassword("P@ssword");
    changeReq.setConfirmedPassword("P@ssword");
    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 10 with PasswordChangeRequest

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

the class PasswordChangeActionTests method verifyFailNoCreds.

@Test
public void verifyFailNoCreds() 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());
    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)

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