Search in sources :

Example 21 with User

use of com.haozi.app.domain.User in project hello-world by haoziapple.

the class UserServiceIntTest method assertThatResetKeyMustBeValid.

@Test
@Transactional
public void assertThatResetKeyMustBeValid() {
    Instant daysAgo = Instant.now().minus(25, ChronoUnit.HOURS);
    user.setActivated(true);
    user.setResetDate(daysAgo);
    user.setResetKey("1234");
    userRepository.saveAndFlush(user);
    Optional<User> maybeUser = userService.completePasswordReset("johndoe2", user.getResetKey());
    assertThat(maybeUser).isNotPresent();
    userRepository.delete(user);
}
Also used : User(com.haozi.app.domain.User) Instant(java.time.Instant) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 22 with User

use of com.haozi.app.domain.User in project hello-world by haoziapple.

the class UserServiceIntTest method assertThatUserCanResetPassword.

@Test
@Transactional
public void assertThatUserCanResetPassword() {
    String oldPassword = user.getPassword();
    Instant daysAgo = Instant.now().minus(2, ChronoUnit.HOURS);
    String resetKey = RandomUtil.generateResetKey();
    user.setActivated(true);
    user.setResetDate(daysAgo);
    user.setResetKey(resetKey);
    userRepository.saveAndFlush(user);
    Optional<User> maybeUser = userService.completePasswordReset("johndoe2", user.getResetKey());
    assertThat(maybeUser).isPresent();
    assertThat(maybeUser.orElse(null).getResetDate()).isNull();
    assertThat(maybeUser.orElse(null).getResetKey()).isNull();
    assertThat(maybeUser.orElse(null).getPassword()).isNotEqualTo(oldPassword);
    userRepository.delete(user);
}
Also used : User(com.haozi.app.domain.User) Instant(java.time.Instant) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 23 with User

use of com.haozi.app.domain.User in project hello-world by haoziapple.

the class UserServiceIntTest method testFindNotActivatedUsersByCreationDateBefore.

@Test
@Transactional
public void testFindNotActivatedUsersByCreationDateBefore() {
    Instant now = Instant.now();
    user.setActivated(false);
    User dbUser = userRepository.saveAndFlush(user);
    dbUser.setCreatedDate(now.minus(4, ChronoUnit.DAYS));
    userRepository.saveAndFlush(user);
    List<User> users = userRepository.findAllByActivatedIsFalseAndCreatedDateBefore(now.minus(3, ChronoUnit.DAYS));
    assertThat(users).isNotEmpty();
    userService.removeNotActivatedUsers();
    users = userRepository.findAllByActivatedIsFalseAndCreatedDateBefore(now.minus(3, ChronoUnit.DAYS));
    assertThat(users).isEmpty();
}
Also used : User(com.haozi.app.domain.User) Instant(java.time.Instant) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 24 with User

use of com.haozi.app.domain.User in project hello-world by haoziapple.

the class UserJWTControllerIntTest method testAuthorizeWithRememberMe.

@Test
@Transactional
public void testAuthorizeWithRememberMe() throws Exception {
    User user = new User();
    user.setLogin("user-jwt-controller-remember-me");
    user.setEmail("user-jwt-controller-remember-me@example.com");
    user.setActivated(true);
    user.setPassword(passwordEncoder.encode("test"));
    userRepository.saveAndFlush(user);
    LoginVM login = new LoginVM();
    login.setUsername("user-jwt-controller-remember-me");
    login.setPassword("test");
    login.setRememberMe(true);
    mockMvc.perform(post("/api/authenticate").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(login))).andExpect(status().isOk()).andExpect(jsonPath("$.id_token").isString()).andExpect(jsonPath("$.id_token").isNotEmpty()).andExpect(header().string("Authorization", not(nullValue()))).andExpect(header().string("Authorization", not(isEmptyString())));
}
Also used : LoginVM(com.haozi.app.web.rest.vm.LoginVM) User(com.haozi.app.domain.User) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 25 with User

use of com.haozi.app.domain.User in project hello-world by haoziapple.

the class UserJWTControllerIntTest method testAuthorize.

@Test
@Transactional
public void testAuthorize() throws Exception {
    User user = new User();
    user.setLogin("user-jwt-controller");
    user.setEmail("user-jwt-controller@example.com");
    user.setActivated(true);
    user.setPassword(passwordEncoder.encode("test"));
    userRepository.saveAndFlush(user);
    LoginVM login = new LoginVM();
    login.setUsername("user-jwt-controller");
    login.setPassword("test");
    mockMvc.perform(post("/api/authenticate").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(login))).andExpect(status().isOk()).andExpect(jsonPath("$.id_token").isString()).andExpect(jsonPath("$.id_token").isNotEmpty()).andExpect(header().string("Authorization", not(nullValue()))).andExpect(header().string("Authorization", not(isEmptyString())));
}
Also used : LoginVM(com.haozi.app.web.rest.vm.LoginVM) User(com.haozi.app.domain.User) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

User (com.haozi.app.domain.User)52 Test (org.junit.Test)41 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)41 Transactional (org.springframework.transaction.annotation.Transactional)36 WithMockUser (org.springframework.security.test.context.support.WithMockUser)21 ManagedUserVM (com.haozi.app.web.rest.vm.ManagedUserVM)15 UserDTO (com.haozi.app.service.dto.UserDTO)5 Authority (com.haozi.app.domain.Authority)4 Instant (java.time.Instant)4 MimeMessage (javax.mail.internet.MimeMessage)4 Timed (com.codahale.metrics.annotation.Timed)2 KeyAndPasswordVM (com.haozi.app.web.rest.vm.KeyAndPasswordVM)2 LoginVM (com.haozi.app.web.rest.vm.LoginVM)2 Before (org.junit.Before)2 UserRepository (com.haozi.app.repository.UserRepository)1 BadRequestAlertException (com.haozi.app.web.rest.errors.BadRequestAlertException)1 EmailAlreadyUsedException (com.haozi.app.web.rest.errors.EmailAlreadyUsedException)1 LoginAlreadyUsedException (com.haozi.app.web.rest.errors.LoginAlreadyUsedException)1 URI (java.net.URI)1 java.util (java.util)1