Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove CC of team on password resets. #1225

Merged
merged 2 commits into from
May 15, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion core/src/main/java/io/aiven/klaw/service/MailUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ void sendMailResetPwd(
formattedStr = String.format(passwordReset, username, pwd);
subject = KLAW_ACCESS_PASSWORD_RESET_REQUESTED;

sendMail(username, dbHandle, formattedStr, subject, false, null, tenantId, loginUrl);
sendPwdResetMail(username, dbHandle, formattedStr, subject, false, null, tenantId, loginUrl);
}

void sendMailRegisteredUserSaas(
Expand Down Expand Up @@ -355,6 +355,35 @@ private void sendMail(
});
}

private void sendPwdResetMail(
String username,
HandleDbRequests dbHandle,
String formattedStr,
String subject,
boolean registrationRequest,
String otherMailId,
int tenantId,
String loginUrl) {

CompletableFuture.runAsync(
() -> {
String emailId;

try {
emailId = dbHandle.getUsersInfo(username).getMailid();
aindriu-aiven marked this conversation as resolved.
Show resolved Hide resolved

if (emailId != null) {
emailService.sendSimpleMessage(
emailId, null, subject, formattedStr, tenantId, loginUrl);
} else {
log.error("Email id not found. Notification not sent !!");
}
} catch (Exception e) {
log.error("Email id not found. Notification not sent !! ", e);
}
});
}

public String sendMailToSaasAdmin(int tenantId, String userName, String period, String loginUrl) {
String mailtext =
"Tenant extension : Tenant " + tenantId + " username " + userName + " period " + period;
Expand Down
41 changes: 40 additions & 1 deletion core/src/test/java/io/aiven/klaw/service/MailUtilsTest.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,63 @@
package io.aiven.klaw.service;

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 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.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.test.context.junit.jupiter.SpringExtension;

import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.when;

@ExtendWith(SpringExtension.class)
public class MailUtilsTest {

public static final String LOGIN_URL = "https://localhost:9097";
@Mock UserDetails userDetails;

@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() {

String username = "Octopus";
UserInfo info = new UserInfo();
info.setUsername(username);
info.setMailid("Octopus.klaw@mailid");
when(handleDbRequests.getUsersInfo(username)).thenReturn(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,times(1)).sendSimpleMessage(eq(info.getMailid()),eq(null),anyString(),anyString(),eq(101),eq(LOGIN_URL));

}
}