Search in sources :

Example 1 with PasswordChangeDTO

use of io.github.jhipster.sample.service.dto.PasswordChangeDTO in project jhipster-sample-app-dto by jhipster.

the class AccountResourceIntTest method testChangePasswordTooSmall.

@Test
@Transactional
@WithMockUser("change-password-too-small")
public void testChangePasswordTooSmall() throws Exception {
    User user = new User();
    String currentPassword = RandomStringUtils.random(60);
    user.setPassword(passwordEncoder.encode(currentPassword));
    user.setLogin("change-password-too-small");
    user.setEmail("change-password-too-small@example.com");
    userRepository.saveAndFlush(user);
    restMvc.perform(post("/api/account/change-password").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(new PasswordChangeDTO(currentPassword, "new")))).andExpect(status().isBadRequest());
    User updatedUser = userRepository.findOneByLogin("change-password-too-small").orElse(null);
    assertThat(updatedUser.getPassword()).isEqualTo(user.getPassword());
}
Also used : User(io.github.jhipster.sample.domain.User) WithMockUser(org.springframework.security.test.context.support.WithMockUser) PasswordChangeDTO(io.github.jhipster.sample.service.dto.PasswordChangeDTO) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with PasswordChangeDTO

use of io.github.jhipster.sample.service.dto.PasswordChangeDTO in project jhipster-sample-app-websocket by jhipster.

the class AccountResourceIntTest method testChangePasswordWrongExistingPassword.

@Test
@Transactional
@WithMockUser("change-password-wrong-existing-password")
public void testChangePasswordWrongExistingPassword() throws Exception {
    User user = new User();
    String currentPassword = RandomStringUtils.random(60);
    user.setPassword(passwordEncoder.encode(currentPassword));
    user.setLogin("change-password-wrong-existing-password");
    user.setEmail("change-password-wrong-existing-password@example.com");
    userRepository.saveAndFlush(user);
    restMvc.perform(post("/api/account/change-password").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(new PasswordChangeDTO("1" + currentPassword, "new password")))).andExpect(status().isBadRequest());
    User updatedUser = userRepository.findOneByLogin("change-password-wrong-existing-password").orElse(null);
    assertThat(passwordEncoder.matches("new password", updatedUser.getPassword())).isFalse();
    assertThat(passwordEncoder.matches(currentPassword, updatedUser.getPassword())).isTrue();
}
Also used : User(io.github.jhipster.sample.domain.User) WithMockUser(org.springframework.security.test.context.support.WithMockUser) PasswordChangeDTO(io.github.jhipster.sample.service.dto.PasswordChangeDTO) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with PasswordChangeDTO

use of io.github.jhipster.sample.service.dto.PasswordChangeDTO in project jhipster-sample-app-websocket by jhipster.

the class AccountResourceIntTest method testChangePasswordTooSmall.

@Test
@Transactional
@WithMockUser("change-password-too-small")
public void testChangePasswordTooSmall() throws Exception {
    User user = new User();
    String currentPassword = RandomStringUtils.random(60);
    user.setPassword(passwordEncoder.encode(currentPassword));
    user.setLogin("change-password-too-small");
    user.setEmail("change-password-too-small@example.com");
    userRepository.saveAndFlush(user);
    restMvc.perform(post("/api/account/change-password").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(new PasswordChangeDTO(currentPassword, "new")))).andExpect(status().isBadRequest());
    User updatedUser = userRepository.findOneByLogin("change-password-too-small").orElse(null);
    assertThat(updatedUser.getPassword()).isEqualTo(user.getPassword());
}
Also used : User(io.github.jhipster.sample.domain.User) WithMockUser(org.springframework.security.test.context.support.WithMockUser) PasswordChangeDTO(io.github.jhipster.sample.service.dto.PasswordChangeDTO) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with PasswordChangeDTO

use of io.github.jhipster.sample.service.dto.PasswordChangeDTO in project jhipster-sample-app-cassandra by jhipster.

the class AccountResourceIntTest method testChangePasswordWrongExistingPassword.

@Test
@WithMockUser("change-password-wrong-existing-password")
public void testChangePasswordWrongExistingPassword() throws Exception {
    User user = new User();
    user.setId(UUID.randomUUID().toString());
    String currentPassword = RandomStringUtils.random(60);
    user.setPassword(passwordEncoder.encode(currentPassword));
    user.setLogin("change-password-wrong-existing-password");
    user.setEmail("change-password-wrong-existing-password@example.com");
    userRepository.save(user);
    restMvc.perform(post("/api/account/change-password").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(new PasswordChangeDTO("1" + currentPassword, "new password")))).andExpect(status().isBadRequest());
    User updatedUser = userRepository.findOneByLogin("change-password-wrong-existing-password").orElse(null);
    assertThat(passwordEncoder.matches("new password", updatedUser.getPassword())).isFalse();
    assertThat(passwordEncoder.matches(currentPassword, updatedUser.getPassword())).isTrue();
}
Also used : User(io.github.jhipster.sample.domain.User) WithMockUser(org.springframework.security.test.context.support.WithMockUser) PasswordChangeDTO(io.github.jhipster.sample.service.dto.PasswordChangeDTO) WithMockUser(org.springframework.security.test.context.support.WithMockUser) AbstractCassandraTest(io.github.jhipster.sample.AbstractCassandraTest) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 5 with PasswordChangeDTO

use of io.github.jhipster.sample.service.dto.PasswordChangeDTO in project jhipster-sample-app-cassandra by jhipster.

the class AccountResourceIntTest method testChangePasswordTooSmall.

@Test
@WithMockUser("change-password-too-small")
public void testChangePasswordTooSmall() throws Exception {
    User user = new User();
    user.setId(UUID.randomUUID().toString());
    String currentPassword = RandomStringUtils.random(60);
    user.setPassword(passwordEncoder.encode(currentPassword));
    user.setLogin("change-password-too-small");
    user.setEmail("change-password-too-small@example.com");
    userRepository.save(user);
    restMvc.perform(post("/api/account/change-password").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(new PasswordChangeDTO(currentPassword, "new")))).andExpect(status().isBadRequest());
    User updatedUser = userRepository.findOneByLogin("change-password-too-small").orElse(null);
    assertThat(updatedUser.getPassword()).isEqualTo(user.getPassword());
}
Also used : User(io.github.jhipster.sample.domain.User) WithMockUser(org.springframework.security.test.context.support.WithMockUser) PasswordChangeDTO(io.github.jhipster.sample.service.dto.PasswordChangeDTO) WithMockUser(org.springframework.security.test.context.support.WithMockUser) AbstractCassandraTest(io.github.jhipster.sample.AbstractCassandraTest) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

User (io.github.jhipster.sample.domain.User)24 PasswordChangeDTO (io.github.jhipster.sample.service.dto.PasswordChangeDTO)24 Test (org.junit.Test)24 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)24 WithMockUser (org.springframework.security.test.context.support.WithMockUser)24 Transactional (org.springframework.transaction.annotation.Transactional)16 AbstractCassandraTest (io.github.jhipster.sample.AbstractCassandraTest)4