Search in sources :

Example 1 with User

use of com.furyviewer.domain.User in project FuryViewer by TheDoctor-95.

the class AccountResourceIntTest method testRegisterNullPassword.

@Test
@Transactional
public void testRegisterNullPassword() throws Exception {
    ManagedUserVM invalidUser = new ManagedUserVM(// id
    null, // login
    "bob", // invalid null password
    null, // firstName
    "Bob", // lastName
    "Green", // email
    "bob@example.com", // activated
    true, // imageUrl
    "http://placehold.it/50x50", // langKey
    Constants.DEFAULT_LANGUAGE, // createdBy
    null, // createdDate
    null, // lastModifiedBy
    null, // lastModifiedDate
    null, new HashSet<>(Collections.singletonList(AuthoritiesConstants.USER)));
    restUserMockMvc.perform(post("/api/register").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(invalidUser))).andExpect(status().isBadRequest());
    Optional<User> user = userRepository.findOneByLogin("bob");
    assertThat(user.isPresent()).isFalse();
}
Also used : User(com.furyviewer.domain.User) WithMockUser(org.springframework.security.test.context.support.WithMockUser) ManagedUserVM(com.furyviewer.web.rest.vm.ManagedUserVM) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with User

use of com.furyviewer.domain.User in project FuryViewer by TheDoctor-95.

the class AccountResourceIntTest method testChangePassword.

@Test
@Transactional
@WithMockUser("change-password")
public void testChangePassword() throws Exception {
    User user = new User();
    user.setPassword(RandomStringUtils.random(60));
    user.setLogin("change-password");
    user.setEmail("change-password@example.com");
    userRepository.saveAndFlush(user);
    restMvc.perform(post("/api/account/change-password").content("new password")).andExpect(status().isOk());
    User updatedUser = userRepository.findOneByLogin("change-password").orElse(null);
    assertThat(passwordEncoder.matches("new password", updatedUser.getPassword())).isTrue();
}
Also used : User(com.furyviewer.domain.User) WithMockUser(org.springframework.security.test.context.support.WithMockUser) 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 User

use of com.furyviewer.domain.User in project FuryViewer by TheDoctor-95.

the class AccountResourceIntTest method testSaveAccount.

@Test
@Transactional
@WithMockUser("save-account")
public void testSaveAccount() throws Exception {
    User user = new User();
    user.setLogin("save-account");
    user.setEmail("save-account@example.com");
    user.setPassword(RandomStringUtils.random(60));
    user.setActivated(true);
    userRepository.saveAndFlush(user);
    UserDTO userDTO = new UserDTO(// id
    null, // login
    "not-used", // firstName
    "firstname", // lastName
    "lastname", // email
    "save-account@example.com", // activated
    false, // imageUrl
    "http://placehold.it/50x50", // langKey
    Constants.DEFAULT_LANGUAGE, // createdBy
    null, // createdDate
    null, // lastModifiedBy
    null, // lastModifiedDate
    null, new HashSet<>(Collections.singletonList(AuthoritiesConstants.ADMIN)));
    restMvc.perform(post("/api/account").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(userDTO))).andExpect(status().isOk());
    User updatedUser = userRepository.findOneByLogin(user.getLogin()).orElse(null);
    assertThat(updatedUser.getFirstName()).isEqualTo(userDTO.getFirstName());
    assertThat(updatedUser.getLastName()).isEqualTo(userDTO.getLastName());
    assertThat(updatedUser.getEmail()).isEqualTo(userDTO.getEmail());
    assertThat(updatedUser.getLangKey()).isEqualTo(userDTO.getLangKey());
    assertThat(updatedUser.getPassword()).isEqualTo(user.getPassword());
    assertThat(updatedUser.getImageUrl()).isEqualTo(userDTO.getImageUrl());
    assertThat(updatedUser.getActivated()).isEqualTo(true);
    assertThat(updatedUser.getAuthorities()).isEmpty();
}
Also used : User(com.furyviewer.domain.User) WithMockUser(org.springframework.security.test.context.support.WithMockUser) UserDTO(com.furyviewer.service.dto.UserDTO) 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 User

use of com.furyviewer.domain.User in project FuryViewer by TheDoctor-95.

the class AccountResourceIntTest method testRegisterInvalidLogin.

@Test
@Transactional
public void testRegisterInvalidLogin() throws Exception {
    ManagedUserVM invalidUser = new ManagedUserVM(// id
    null, // login <-- invalid
    "funky-log!n", // password
    "password", // firstName
    "Funky", // lastName
    "One", // email
    "funky@example.com", // activated
    true, // imageUrl
    "http://placehold.it/50x50", // langKey
    Constants.DEFAULT_LANGUAGE, // createdBy
    null, // createdDate
    null, // lastModifiedBy
    null, // lastModifiedDate
    null, new HashSet<>(Collections.singletonList(AuthoritiesConstants.USER)));
    restUserMockMvc.perform(post("/api/register").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(invalidUser))).andExpect(status().isBadRequest());
    Optional<User> user = userRepository.findOneByEmailIgnoreCase("funky@example.com");
    assertThat(user.isPresent()).isFalse();
}
Also used : User(com.furyviewer.domain.User) WithMockUser(org.springframework.security.test.context.support.WithMockUser) ManagedUserVM(com.furyviewer.web.rest.vm.ManagedUserVM) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with User

use of com.furyviewer.domain.User in project FuryViewer by TheDoctor-95.

the class AccountResourceIntTest method testFinishPasswordResetTooSmall.

@Test
@Transactional
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.saveAndFlush(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(com.furyviewer.web.rest.vm.KeyAndPasswordVM) User(com.furyviewer.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)

Aggregations

User (com.furyviewer.domain.User)65 Test (org.junit.Test)52 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)52 Transactional (org.springframework.transaction.annotation.Transactional)37 WithMockUser (org.springframework.security.test.context.support.WithMockUser)22 ManagedUserVM (com.furyviewer.web.rest.vm.ManagedUserVM)16 Authority (com.furyviewer.domain.Authority)6 UserDTO (com.furyviewer.service.dto.UserDTO)5 Instant (java.time.Instant)4 MimeMessage (javax.mail.internet.MimeMessage)4 Timed (com.codahale.metrics.annotation.Timed)2 KeyAndPasswordVM (com.furyviewer.web.rest.vm.KeyAndPasswordVM)2 LoginVM (com.furyviewer.web.rest.vm.LoginVM)2 UserExt (com.furyviewer.domain.UserExt)1 UserRepository (com.furyviewer.repository.UserRepository)1 BadRequestAlertException (com.furyviewer.web.rest.errors.BadRequestAlertException)1 EmailAlreadyUsedException (com.furyviewer.web.rest.errors.EmailAlreadyUsedException)1 LoginAlreadyUsedException (com.furyviewer.web.rest.errors.LoginAlreadyUsedException)1 URI (java.net.URI)1 java.util (java.util)1