Search in sources :

Example 1 with KeyAndPasswordVM

use of io.github.jhipster.sample.web.rest.vm.KeyAndPasswordVM in project jhipster-sample-app-dto by jhipster.

the class AccountResourceIntTest method testFinishPasswordReset.

@Test
@Transactional
public void testFinishPasswordReset() throws Exception {
    User user = new User();
    user.setPassword(RandomStringUtils.random(60));
    user.setLogin("finish-password-reset");
    user.setEmail("finish-password-reset@example.com");
    user.setResetDate(Instant.now().plusSeconds(60));
    user.setResetKey("reset key");
    userRepository.saveAndFlush(user);
    KeyAndPasswordVM keyAndPassword = new KeyAndPasswordVM();
    keyAndPassword.setKey(user.getResetKey());
    keyAndPassword.setNewPassword("new password");
    restMvc.perform(post("/api/account/reset-password/finish").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(keyAndPassword))).andExpect(status().isOk());
    User updatedUser = userRepository.findOneByLogin(user.getLogin()).orElse(null);
    assertThat(passwordEncoder.matches(keyAndPassword.getNewPassword(), updatedUser.getPassword())).isTrue();
}
Also used : KeyAndPasswordVM(io.github.jhipster.sample.web.rest.vm.KeyAndPasswordVM) User(io.github.jhipster.sample.domain.User) 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 KeyAndPasswordVM

use of io.github.jhipster.sample.web.rest.vm.KeyAndPasswordVM in project jhipster-sample-app-websocket by jhipster.

the class AccountResourceIntTest method testFinishPasswordResetWrongKey.

@Test
@Transactional
public void testFinishPasswordResetWrongKey() throws Exception {
    KeyAndPasswordVM keyAndPassword = new KeyAndPasswordVM();
    keyAndPassword.setKey("wrong reset key");
    keyAndPassword.setNewPassword("new password");
    restMvc.perform(post("/api/account/reset-password/finish").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(keyAndPassword))).andExpect(status().isInternalServerError());
}
Also used : KeyAndPasswordVM(io.github.jhipster.sample.web.rest.vm.KeyAndPasswordVM) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with KeyAndPasswordVM

use of io.github.jhipster.sample.web.rest.vm.KeyAndPasswordVM in project jhipster-sample-app-mongodb by jhipster.

the class AccountResourceIntTest method testFinishPasswordReset.

@Test
public void testFinishPasswordReset() throws Exception {
    User user = new User();
    user.setPassword(RandomStringUtils.random(60));
    user.setLogin("finish-password-reset");
    user.setEmail("finish-password-reset@example.com");
    user.setResetDate(Instant.now().plusSeconds(60));
    user.setResetKey("reset key");
    userRepository.save(user);
    KeyAndPasswordVM keyAndPassword = new KeyAndPasswordVM();
    keyAndPassword.setKey(user.getResetKey());
    keyAndPassword.setNewPassword("new password");
    restMvc.perform(post("/api/account/reset-password/finish").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(keyAndPassword))).andExpect(status().isOk());
    User updatedUser = userRepository.findOneByLogin(user.getLogin()).orElse(null);
    assertThat(passwordEncoder.matches(keyAndPassword.getNewPassword(), updatedUser.getPassword())).isTrue();
}
Also used : KeyAndPasswordVM(io.github.jhipster.sample.web.rest.vm.KeyAndPasswordVM) User(io.github.jhipster.sample.domain.User) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with KeyAndPasswordVM

use of io.github.jhipster.sample.web.rest.vm.KeyAndPasswordVM in project jhipster-sample-app-mongodb by jhipster.

the class AccountResourceIntTest method testFinishPasswordResetTooSmall.

@Test
public void testFinishPasswordResetTooSmall() throws Exception {
    User user = new User();
    user.setPassword(RandomStringUtils.random(60));
    user.setLogin("finish-password-reset-too-small");
    user.setEmail("finish-password-reset-too-small@example.com");
    user.setResetDate(Instant.now().plusSeconds(60));
    user.setResetKey("reset key too small");
    userRepository.save(user);
    KeyAndPasswordVM keyAndPassword = new KeyAndPasswordVM();
    keyAndPassword.setKey(user.getResetKey());
    keyAndPassword.setNewPassword("foo");
    restMvc.perform(post("/api/account/reset-password/finish").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(keyAndPassword))).andExpect(status().isBadRequest());
    User updatedUser = userRepository.findOneByLogin(user.getLogin()).orElse(null);
    assertThat(passwordEncoder.matches(keyAndPassword.getNewPassword(), updatedUser.getPassword())).isFalse();
}
Also used : KeyAndPasswordVM(io.github.jhipster.sample.web.rest.vm.KeyAndPasswordVM) User(io.github.jhipster.sample.domain.User) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 5 with KeyAndPasswordVM

use of io.github.jhipster.sample.web.rest.vm.KeyAndPasswordVM in project jhipster-sample-app-elasticsearch by jhipster.

the class AccountResourceIntTest method testFinishPasswordResetWrongKey.

@Test
@Transactional
public void testFinishPasswordResetWrongKey() throws Exception {
    KeyAndPasswordVM keyAndPassword = new KeyAndPasswordVM();
    keyAndPassword.setKey("wrong reset key");
    keyAndPassword.setNewPassword("new password");
    restMvc.perform(post("/api/account/reset-password/finish").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(keyAndPassword))).andExpect(status().isInternalServerError());
}
Also used : KeyAndPasswordVM(io.github.jhipster.sample.web.rest.vm.KeyAndPasswordVM) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

KeyAndPasswordVM (io.github.jhipster.sample.web.rest.vm.KeyAndPasswordVM)18 Test (org.junit.Test)18 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)18 User (io.github.jhipster.sample.domain.User)12 WithMockUser (org.springframework.security.test.context.support.WithMockUser)12 Transactional (org.springframework.transaction.annotation.Transactional)12 AbstractCassandraTest (io.github.jhipster.sample.AbstractCassandraTest)3