use of com.nexblocks.authguard.service.model.OneTimePasswordBO in project AuthGuard by AuthGuard.
the class SmsOtpSubscriber method onMessage.
@Override
public void onMessage(final Message message) {
if (message.getEventType() == EventType.OTP_GENERATED) {
final OtpMessageBody messageBody = (OtpMessageBody) message.getMessageBody();
final AccountBO account = messageBody.getAccount();
final OneTimePasswordBO otp = messageBody.getOtp();
if (messageBody.isByEmail()) {
sendEmail(account, otp);
} else {
LOG.warn("Email OTP subscriber is enabled but a OTP event was received not to be sent by email");
}
}
}
use of com.nexblocks.authguard.service.model.OneTimePasswordBO in project AuthGuard by AuthGuard.
the class SmsOtpSubscriberTest method onValidMessage.
@Test
void onValidMessage() {
final OneTimePasswordBO otp = OneTimePasswordBO.builder().password("password").build();
final AccountBO account = AccountBO.builder().phoneNumber(PhoneNumberBO.builder().number("+178945632").build()).firstName("first").lastName("second").build();
final OtpMessageBody messageBody = new OtpMessageBody(otp, account, true, false);
final Message message = Messages.otpGenerated(messageBody);
final ImmutableTextMessage expectedEmail = ImmutableTextMessage.builder().to(account.getPhoneNumber().getNumber()).parameters(ImmutableMap.of("password", otp.getPassword(), "firstName", account.getFirstName(), "lastName", account.getLastName())).build();
otpSubscriber.onMessage(message);
final ArgumentCaptor<ImmutableTextMessage> sentSmsCaptor = ArgumentCaptor.forClass(ImmutableTextMessage.class);
Mockito.verify(smsProvider).send(sentSmsCaptor.capture());
assertThat(sentSmsCaptor.getValue()).isEqualTo(expectedEmail);
}
use of com.nexblocks.authguard.service.model.OneTimePasswordBO in project AuthGuard by AuthGuard.
the class SmsOtpSubscriberTest method onWrongMessageType.
@Test
void onWrongMessageType() {
final OneTimePasswordBO otp = OneTimePasswordBO.builder().password("password").build();
final AccountBO account = AccountBO.builder().phoneNumber(PhoneNumberBO.builder().number("+178945632").build()).build();
final OtpMessageBody messageBody = new OtpMessageBody(otp, account, true, false);
final Message message = Messages.otpGenerated(messageBody).withEventType(EventType.ADMIN);
otpSubscriber.onMessage(message);
Mockito.verify(smsProvider, Mockito.never()).send(Mockito.any());
}
use of com.nexblocks.authguard.service.model.OneTimePasswordBO in project AuthGuard by AuthGuard.
the class SmsOtpSubscriberTest method onValidMessageNoPhoneNumber.
@Test
void onValidMessageNoPhoneNumber() {
final OneTimePasswordBO otp = OneTimePasswordBO.builder().password("password").build();
final AccountBO account = AccountBO.builder().build();
final OtpMessageBody messageBody = new OtpMessageBody(otp, account, true, false);
final Message message = Messages.otpGenerated(messageBody);
otpSubscriber.onMessage(message);
Mockito.verify(smsProvider, Mockito.never()).send(Mockito.any());
}
Aggregations