Search in sources :

Example 31 with AccountBO

use of com.nexblocks.authguard.service.model.AccountBO 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 32 with AccountBO

use of com.nexblocks.authguard.service.model.AccountBO 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 33 with AccountBO

use of com.nexblocks.authguard.service.model.AccountBO 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)

Example 34 with AccountBO

use of com.nexblocks.authguard.service.model.AccountBO in project AuthGuard by AuthGuard.

the class SmsPasswordlessSubscriberTest method onWrongMessageType.

@Test
void onWrongMessageType() {
    final AccountTokenDO accountToken = AccountTokenDO.builder().token("token").build();
    final AccountBO account = AccountBO.builder().phoneNumber(PhoneNumberBO.builder().number("+178945632").build()).build();
    final PasswordlessMessageBody messageBody = new PasswordlessMessageBody(accountToken, account);
    final Message message = Messages.passwordlessGenerated(messageBody).withEventType(EventType.ADMIN);
    smsPasswordlessSubscriber.onMessage(message);
    Mockito.verify(smsProvider, Mockito.never()).send(Mockito.any());
}
Also used : AccountBO(com.nexblocks.authguard.service.model.AccountBO) ImmutableTextMessage(com.nexblocks.authguard.external.sms.ImmutableTextMessage) Message(com.nexblocks.authguard.emb.model.Message) AccountTokenDO(com.nexblocks.authguard.dal.model.AccountTokenDO) PasswordlessMessageBody(com.nexblocks.authguard.basic.passwordless.PasswordlessMessageBody) Test(org.junit.jupiter.api.Test)

Example 35 with AccountBO

use of com.nexblocks.authguard.service.model.AccountBO in project AuthGuard by AuthGuard.

the class SmsPasswordlessSubscriberTest method onValidMessage.

@Test
void onValidMessage() {
    final AccountTokenDO accountToken = AccountTokenDO.builder().token("token").build();
    final AccountBO account = AccountBO.builder().phoneNumber(PhoneNumberBO.builder().number("+178945632").build()).firstName("first").lastName("second").build();
    final PasswordlessMessageBody messageBody = new PasswordlessMessageBody(accountToken, account);
    final Message message = Messages.passwordlessGenerated(messageBody);
    final ImmutableTextMessage expectedSms = ImmutableTextMessage.builder().to(account.getPhoneNumber().getNumber()).parameters(ImmutableMap.of("token", accountToken.getToken(), "firstName", account.getFirstName(), "lastName", account.getLastName())).build();
    smsPasswordlessSubscriber.onMessage(message);
    final ArgumentCaptor<ImmutableTextMessage> sentSmsCaptor = ArgumentCaptor.forClass(ImmutableTextMessage.class);
    Mockito.verify(smsProvider).send(sentSmsCaptor.capture());
    assertThat(sentSmsCaptor.getValue()).isEqualTo(expectedSms);
}
Also used : AccountBO(com.nexblocks.authguard.service.model.AccountBO) ImmutableTextMessage(com.nexblocks.authguard.external.sms.ImmutableTextMessage) Message(com.nexblocks.authguard.emb.model.Message) AccountTokenDO(com.nexblocks.authguard.dal.model.AccountTokenDO) ImmutableTextMessage(com.nexblocks.authguard.external.sms.ImmutableTextMessage) PasswordlessMessageBody(com.nexblocks.authguard.basic.passwordless.PasswordlessMessageBody) Test(org.junit.jupiter.api.Test)

Aggregations

AccountBO (com.nexblocks.authguard.service.model.AccountBO)55 Test (org.junit.jupiter.api.Test)43 AccountTokenDO (com.nexblocks.authguard.dal.model.AccountTokenDO)21 Message (com.nexblocks.authguard.emb.model.Message)15 AuthResponseBO (com.nexblocks.authguard.service.model.AuthResponseBO)15 OtpMessageBody (com.nexblocks.authguard.basic.otp.OtpMessageBody)8 PasswordlessMessageBody (com.nexblocks.authguard.basic.passwordless.PasswordlessMessageBody)8 OneTimePasswordBO (com.nexblocks.authguard.service.model.OneTimePasswordBO)8 ServiceAuthorizationException (com.nexblocks.authguard.service.exceptions.ServiceAuthorizationException)7 DecodedJWT (com.auth0.jwt.interfaces.DecodedJWT)6 ImmutableTextMessage (com.nexblocks.authguard.external.sms.ImmutableTextMessage)6 RequestContextBO (com.nexblocks.authguard.service.model.RequestContextBO)6 ImmutableEmail (com.nexblocks.authguard.external.email.ImmutableEmail)5 JwtConfig (com.nexblocks.authguard.service.config.JwtConfig)5 StrategyConfig (com.nexblocks.authguard.service.config.StrategyConfig)5 ServiceException (com.nexblocks.authguard.service.exceptions.ServiceException)5 AuthRequestBO (com.nexblocks.authguard.service.model.AuthRequestBO)5 CreateAccountRequestDTO (com.nexblocks.authguard.api.dto.requests.CreateAccountRequestDTO)4 OtpConfig (com.nexblocks.authguard.basic.config.OtpConfig)4 CreateCompleteAccountRequestDTO (com.nexblocks.authguard.api.dto.requests.CreateCompleteAccountRequestDTO)3