-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove CC of team on password resets. (#1225)
* Remove CC of team on password resets. Signed-off-by: Aindriu Lavelle <[email protected]> * Use cache instead of DB lookup for username. Signed-off-by: Aindriu Lavelle <[email protected]> --------- Signed-off-by: Aindriu Lavelle <[email protected]>
- Loading branch information
1 parent
ceb82b0
commit aaad2b7
Showing
2 changed files
with
101 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 55 additions & 2 deletions
57
core/src/test/java/io/aiven/klaw/service/MailUtilsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,77 @@ | ||
package io.aiven.klaw.service; | ||
|
||
import static org.mockito.ArgumentMatchers.anyString; | ||
import static org.mockito.ArgumentMatchers.eq; | ||
import static org.mockito.Mockito.timeout; | ||
import static org.mockito.Mockito.when; | ||
|
||
import io.aiven.klaw.config.ManageDatabase; | ||
import io.aiven.klaw.dao.UserInfo; | ||
import io.aiven.klaw.helpers.HandleDbRequests; | ||
import io.aiven.klaw.helpers.KwConstants; | ||
import java.util.List; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.Mockito; | ||
import org.springframework.security.core.userdetails.UserDetails; | ||
import org.springframework.test.context.junit.jupiter.SpringExtension; | ||
|
||
@ExtendWith(SpringExtension.class) | ||
public class MailUtilsTest { | ||
|
||
public static final String LOGIN_URL = "https://localhost:9097"; | ||
@Mock UserDetails userDetails; | ||
|
||
private MailUtils mailService; | ||
@Mock HandleDbRequests handleDbRequests; | ||
|
||
@Mock EmailService emailService; | ||
|
||
@Mock ManageDatabase manageDatabase; | ||
|
||
@InjectMocks private MailUtils mailService; | ||
|
||
@BeforeEach | ||
public void setUp() throws Exception { | ||
mailService = new MailUtils(); | ||
// mailService = new MailUtils(); | ||
} | ||
|
||
@Test | ||
public void getUserDetails() {} | ||
|
||
@Test | ||
public void resetPasswordEmail_noCCTeam() throws InterruptedException { | ||
|
||
String username = "Octopus"; | ||
UserInfo info = new UserInfo(); | ||
info.setUsername(username); | ||
info.setMailid("Octopus.klaw@mailid"); | ||
when(manageDatabase.selectAllCachedUserInfo()).thenReturn(List.of(info)); | ||
when(manageDatabase.getKwPropertyValue(eq("klaw.mail.passwordreset.content"), eq(101))) | ||
.thenReturn(KwConstants.MAIL_PASSWORDRESET_CONTENT); | ||
mailService.sendMailResetPwd(username, "KlawPassword", handleDbRequests, 101, LOGIN_URL); | ||
|
||
Thread.sleep(1000); | ||
Mockito.verify(emailService, timeout(1000).times(1)) | ||
.sendSimpleMessage( | ||
eq(info.getMailid()), eq(null), anyString(), anyString(), eq(101), eq(LOGIN_URL)); | ||
} | ||
|
||
@Test | ||
public void resetPasswordEmail_noSuchUser() { | ||
|
||
String username = "Octopus"; | ||
UserInfo info = new UserInfo(); | ||
info.setUsername("Octi"); | ||
info.setMailid("Octi.klaw@mailid"); | ||
when(manageDatabase.selectAllCachedUserInfo()).thenReturn(List.of(info)); | ||
when(manageDatabase.getKwPropertyValue(eq("klaw.mail.passwordreset.content"), eq(101))) | ||
.thenReturn(KwConstants.MAIL_PASSWORDRESET_CONTENT); | ||
mailService.sendMailResetPwd(username, "KlawPassword", handleDbRequests, 101, LOGIN_URL); | ||
Mockito.verify(emailService, timeout(1000).times(0)) | ||
.sendSimpleMessage( | ||
eq(info.getMailid()), eq(null), anyString(), anyString(), eq(101), eq(LOGIN_URL)); | ||
} | ||
} |