Search in sources :

Example 16 with AccountTokenDO

use of com.nexblocks.authguard.dal.model.AccountTokenDO in project AuthGuard by AuthGuard.

the class EmailPasswordlessSubscriberTest method onValidMessageNoEmail.

@Test
void onValidMessageNoEmail() {
    final AccountTokenDO accountToken = AccountTokenDO.builder().token("token").build();
    final AccountBO account = AccountBO.builder().build();
    final PasswordlessMessageBody messageBody = new PasswordlessMessageBody(accountToken, account);
    final Message message = Messages.passwordlessGenerated(messageBody);
    emailPasswordlessSubscriber.onMessage(message);
    Mockito.verify(emailProvider, Mockito.never()).send(Mockito.any());
}
Also used : AccountBO(com.nexblocks.authguard.service.model.AccountBO) 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 17 with AccountTokenDO

use of com.nexblocks.authguard.dal.model.AccountTokenDO in project AuthGuard by AuthGuard.

the class EmailResetTokenSubscriberTest method onValidMessageNoEmail.

@Test
void onValidMessageNoEmail() {
    final AccountTokenDO accountToken = AccountTokenDO.builder().token("token").build();
    final AccountBO account = AccountBO.builder().build();
    final ResetTokenMessage messageBody = new ResetTokenMessage(account, accountToken);
    final Message message = Messages.passwordlessGenerated(messageBody);
    emailResetTokenSubscriber.onMessage(message);
    Mockito.verify(emailProvider, Mockito.never()).send(Mockito.any());
}
Also used : AccountBO(com.nexblocks.authguard.service.model.AccountBO) ResetTokenMessage(com.nexblocks.authguard.service.messaging.ResetTokenMessage) Message(com.nexblocks.authguard.emb.model.Message) AccountTokenDO(com.nexblocks.authguard.dal.model.AccountTokenDO) ResetTokenMessage(com.nexblocks.authguard.service.messaging.ResetTokenMessage) Test(org.junit.jupiter.api.Test)

Example 18 with AccountTokenDO

use of com.nexblocks.authguard.dal.model.AccountTokenDO in project AuthGuard by AuthGuard.

the class EmailResetTokenSubscriberTest method onValidMessage.

@Test
void onValidMessage() {
    final AccountTokenDO accountToken = AccountTokenDO.builder().token("token").build();
    final AccountBO account = AccountBO.builder().email(AccountEmailBO.builder().email("user@test.net").build()).firstName("first").lastName("second").build();
    final ResetTokenMessage messageBody = new ResetTokenMessage(account, accountToken);
    final Message message = Messages.resetTokenGenerated(messageBody);
    final ImmutableEmail expectedEmail = ImmutableEmail.builder().template("passwordReset").to(account.getEmail().getEmail()).parameters(ImmutableMap.of("token", accountToken.getToken(), "firstName", account.getFirstName(), "lastName", account.getLastName())).build();
    emailResetTokenSubscriber.onMessage(message);
    final ArgumentCaptor<ImmutableEmail> sentEmailCaptor = ArgumentCaptor.forClass(ImmutableEmail.class);
    Mockito.verify(emailProvider).send(sentEmailCaptor.capture());
    assertThat(sentEmailCaptor.getValue()).isEqualTo(expectedEmail);
}
Also used : AccountBO(com.nexblocks.authguard.service.model.AccountBO) ResetTokenMessage(com.nexblocks.authguard.service.messaging.ResetTokenMessage) Message(com.nexblocks.authguard.emb.model.Message) AccountTokenDO(com.nexblocks.authguard.dal.model.AccountTokenDO) ImmutableEmail(com.nexblocks.authguard.external.email.ImmutableEmail) ResetTokenMessage(com.nexblocks.authguard.service.messaging.ResetTokenMessage) Test(org.junit.jupiter.api.Test)

Example 19 with AccountTokenDO

use of com.nexblocks.authguard.dal.model.AccountTokenDO 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 20 with AccountTokenDO

use of com.nexblocks.authguard.dal.model.AccountTokenDO 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

AccountTokenDO (com.nexblocks.authguard.dal.model.AccountTokenDO)36 Test (org.junit.jupiter.api.Test)22 AccountBO (com.nexblocks.authguard.service.model.AccountBO)21 Message (com.nexblocks.authguard.emb.model.Message)9 PasswordlessMessageBody (com.nexblocks.authguard.basic.passwordless.PasswordlessMessageBody)8 ServiceException (com.nexblocks.authguard.service.exceptions.ServiceException)8 AuthResponseBO (com.nexblocks.authguard.service.model.AuthResponseBO)7 AccountTokensRepository (com.nexblocks.authguard.dal.cache.AccountTokensRepository)6 AuthRequestBO (com.nexblocks.authguard.service.model.AuthRequestBO)6 ServiceAuthorizationException (com.nexblocks.authguard.service.exceptions.ServiceAuthorizationException)5 ResetTokenMessage (com.nexblocks.authguard.service.messaging.ResetTokenMessage)5 OffsetDateTime (java.time.OffsetDateTime)5 ImmutableEmail (com.nexblocks.authguard.external.email.ImmutableEmail)4 ImmutableTextMessage (com.nexblocks.authguard.external.sms.ImmutableTextMessage)3 ServiceNotFoundException (com.nexblocks.authguard.service.exceptions.ServiceNotFoundException)3 ActionTokenBO (com.nexblocks.authguard.service.model.ActionTokenBO)3 Optional (java.util.Optional)3 Inject (com.google.inject.Inject)2 AccountsService (com.nexblocks.authguard.service.AccountsService)2 ErrorCode (com.nexblocks.authguard.service.exceptions.codes.ErrorCode)2