Search in sources :

Example 1 with EmailAddress

use of org.simbasecurity.core.domain.user.EmailAddress in project simba-os by cegeka.

the class CredentialServiceImplTest method findUserByMail_UserFoundForGivenEmail_ReturnsOptionalWithFoundUser.

@Test
public void findUserByMail_UserFoundForGivenEmail_ReturnsOptionalWithFoundUser() throws Exception {
    EmailAddress email = emailFactory.email("bruce@wayneindustries.com");
    User user = aUser().build();
    when(mockUserRepository.findByEmail(email)).thenReturn(user);
    Optional<User> maybeUser = credentialService.findUserByMail(email);
    assertThat(maybeUser).contains(user);
}
Also used : User(org.simbasecurity.core.domain.User) UserTestBuilder.aUser(org.simbasecurity.core.domain.UserTestBuilder.aUser) EmailAddress(org.simbasecurity.core.domain.user.EmailAddress) Test(org.junit.Test)

Example 2 with EmailAddress

use of org.simbasecurity.core.domain.user.EmailAddress in project simba-os by cegeka.

the class UserDatabaseRepositoryTest method findUserByMail_WillNOTReturnUser_IfPresentInDatabase_AndInactive.

@Test
public void findUserByMail_WillNOTReturnUser_IfPresentInDatabase_AndInactive() throws Exception {
    EmailAddress email = emailFactory.email("morganfreeman@wayneindustries.com");
    User inactiveUser = aDefaultUser().withUserName("fmorgan").withEmail(email).withStatus(Status.INACTIVE).build();
    persistAndRefresh(inactiveUser);
    User user = userDatabaseRepository.findByEmail(email);
    Assertions.assertThat(user).isEqualTo(null);
}
Also used : UserTestBuilder.aDefaultUser(org.simbasecurity.core.domain.UserTestBuilder.aDefaultUser) EmailAddress(org.simbasecurity.core.domain.user.EmailAddress) Test(org.junit.Test)

Example 3 with EmailAddress

use of org.simbasecurity.core.domain.user.EmailAddress in project simba-os by cegeka.

the class UserDatabaseRepositoryTest method findUserByMailCaseInsensitive2_WillReturnUser_IfPresentInDatabase.

@Test
public void findUserByMailCaseInsensitive2_WillReturnUser_IfPresentInDatabase() throws Exception {
    EmailAddress email = emailFactory.email("Alfred@WayneIndustries.com");
    EmailAddress otherEmail = emailFactory.email("alfred@wayneindustries.com");
    User expectedUser = aDefaultUser().withEmail(email).build();
    persistAndRefresh(expectedUser);
    User user = userDatabaseRepository.findByEmail(otherEmail);
    Assertions.assertThat(user).isEqualTo(expectedUser);
}
Also used : UserTestBuilder.aDefaultUser(org.simbasecurity.core.domain.UserTestBuilder.aDefaultUser) EmailAddress(org.simbasecurity.core.domain.user.EmailAddress) Test(org.junit.Test)

Example 4 with EmailAddress

use of org.simbasecurity.core.domain.user.EmailAddress in project simba-os by cegeka.

the class LinkGeneratorTest method generateResetPasswordUrl_WillGenerateLinksToResetPassword_BasedOnSimbaProperty_WithTokenAndUsername.

@Test
public void generateResetPasswordUrl_WillGenerateLinksToResetPassword_BasedOnSimbaProperty_WithTokenAndUsername() throws Exception {
    List<String> links = Arrays.asList("https://www.simba.be:1000/simba", "https://www.dag.no:8080/FYFAEN");
    when(configurationServiceMock.getValue(PASSWORD_RESET_TOKEN_URL)).thenReturn(links);
    EmailAddress email = emailFactory.email("myEmail@myProvider.com");
    String urlEscapedEmail = "myEmail%40myProvider.com";
    Token token = generateToken();
    List<URL> urls = linkGenerator.generateResetPasswordLinks(email, token);
    String queryParams = String.format("email=%s&token=%s", urlEscapedEmail, token.asString());
    assertThat(urls).extracting(URL::getHost, URL::getProtocol, URL::getPort, URL::getQuery, URL::getPath).containsExactly(tuple("www.simba.be", "https", 1000, queryParams, "/simba/http/simba-new-pwd"), tuple("www.dag.no", "https", 8080, queryParams, "/FYFAEN/http/simba-new-pwd"));
}
Also used : Token.generateToken(org.simbasecurity.core.domain.communication.token.Token.generateToken) Token(org.simbasecurity.core.domain.communication.token.Token) EmailAddress(org.simbasecurity.core.domain.user.EmailAddress) PASSWORD_RESET_TOKEN_URL(org.simbasecurity.core.config.SimbaConfigurationParameter.PASSWORD_RESET_TOKEN_URL) URL(java.net.URL) Test(org.junit.Test)

Example 5 with EmailAddress

use of org.simbasecurity.core.domain.user.EmailAddress in project simba-os by cegeka.

the class UserDatabaseRepositoryTest method findUserByMail_WillReturnUser_IfPresentInDatabase_AndActiveOrBlocked.

@Test
public void findUserByMail_WillReturnUser_IfPresentInDatabase_AndActiveOrBlocked() throws Exception {
    EmailAddress email = emailFactory.email("alfred@wayneindustries.com");
    User expectedUser = aDefaultUser().withEmail(email).withStatus(Status.ACTIVE).build();
    persistAndRefresh(expectedUser);
    User user = userDatabaseRepository.findByEmail(email);
    Assertions.assertThat(user).isEqualTo(expectedUser);
}
Also used : UserTestBuilder.aDefaultUser(org.simbasecurity.core.domain.UserTestBuilder.aDefaultUser) EmailAddress(org.simbasecurity.core.domain.user.EmailAddress) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)10 EmailAddress (org.simbasecurity.core.domain.user.EmailAddress)10 UserTestBuilder.aDefaultUser (org.simbasecurity.core.domain.UserTestBuilder.aDefaultUser)7 User (org.simbasecurity.core.domain.User)4 URL (java.net.URL)3 Token (org.simbasecurity.core.domain.communication.token.Token)3 AuditLogEvent (org.simbasecurity.core.audit.AuditLogEvent)2 UserTestBuilder.aUser (org.simbasecurity.core.domain.UserTestBuilder.aUser)2 TemplateWithLinks (org.simbasecurity.core.service.communication.mail.template.TemplateWithLinks)2 PASSWORD_RESET_TOKEN_URL (org.simbasecurity.core.config.SimbaConfigurationParameter.PASSWORD_RESET_TOKEN_URL)1 Token.generateToken (org.simbasecurity.core.domain.communication.token.Token.generateToken)1