Search in sources :

Example 6 with OtpMessageBody

use of com.nexblocks.authguard.basic.otp.OtpMessageBody 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);
}
Also used : AccountBO(com.nexblocks.authguard.service.model.AccountBO) OtpMessageBody(com.nexblocks.authguard.basic.otp.OtpMessageBody) ImmutableTextMessage(com.nexblocks.authguard.external.sms.ImmutableTextMessage) Message(com.nexblocks.authguard.emb.model.Message) OneTimePasswordBO(com.nexblocks.authguard.service.model.OneTimePasswordBO) ImmutableTextMessage(com.nexblocks.authguard.external.sms.ImmutableTextMessage) Test(org.junit.jupiter.api.Test)

Example 7 with OtpMessageBody

use of com.nexblocks.authguard.basic.otp.OtpMessageBody 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());
}
Also used : AccountBO(com.nexblocks.authguard.service.model.AccountBO) OtpMessageBody(com.nexblocks.authguard.basic.otp.OtpMessageBody) ImmutableTextMessage(com.nexblocks.authguard.external.sms.ImmutableTextMessage) Message(com.nexblocks.authguard.emb.model.Message) OneTimePasswordBO(com.nexblocks.authguard.service.model.OneTimePasswordBO) Test(org.junit.jupiter.api.Test)

Example 8 with OtpMessageBody

use of com.nexblocks.authguard.basic.otp.OtpMessageBody 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());
}
Also used : AccountBO(com.nexblocks.authguard.service.model.AccountBO) OtpMessageBody(com.nexblocks.authguard.basic.otp.OtpMessageBody) ImmutableTextMessage(com.nexblocks.authguard.external.sms.ImmutableTextMessage) Message(com.nexblocks.authguard.emb.model.Message) OneTimePasswordBO(com.nexblocks.authguard.service.model.OneTimePasswordBO) Test(org.junit.jupiter.api.Test)

Aggregations

OtpMessageBody (com.nexblocks.authguard.basic.otp.OtpMessageBody)8 AccountBO (com.nexblocks.authguard.service.model.AccountBO)8 OneTimePasswordBO (com.nexblocks.authguard.service.model.OneTimePasswordBO)8 Message (com.nexblocks.authguard.emb.model.Message)6 Test (org.junit.jupiter.api.Test)6 ImmutableTextMessage (com.nexblocks.authguard.external.sms.ImmutableTextMessage)3 ImmutableEmail (com.nexblocks.authguard.external.email.ImmutableEmail)1