use of uk.gov.di.authentication.shared.entity.NotifyRequest in project di-authentication-api by alphagov.
the class NotificationHandlerIntegrationTest method shouldCallNotifyWhenValidMfaRequestIsAddedToQueue.
@Test
void shouldCallNotifyWhenValidMfaRequestIsAddedToQueue() throws JsonProcessingException {
handler.handleRequest(createSqsEvent(new NotifyRequest(TEST_PHONE_NUMBER, MFA_SMS, CODE)), mock(Context.class));
JsonNode request = notifyStub.waitForRequest(60);
assertThat(request, hasFieldWithValue("phone_number", equalTo(TEST_PHONE_NUMBER)));
assertThat(request, hasField("personalisation"));
JsonNode personalisation = request.get("personalisation");
assertThat(personalisation, hasFieldWithValue("validation-code", equalTo(CODE)));
assertThat(personalisation, hasFieldWithValue("validation-code", withLength(equalTo(VERIFICATION_CODE_LENGTH))));
}
use of uk.gov.di.authentication.shared.entity.NotifyRequest in project di-authentication-api by alphagov.
the class NotificationHandlerIntegrationTest method shouldCallNotifyWhenValidAccountCreatedRequestIsAddedToQueue.
@Test
void shouldCallNotifyWhenValidAccountCreatedRequestIsAddedToQueue() throws JsonProcessingException {
handler.handleRequest(createSqsEvent(new NotifyRequest(TEST_EMAIL_ADDRESS, ACCOUNT_CREATED_CONFIRMATION)), mock(Context.class));
JsonNode request = notifyStub.waitForRequest(60);
assertThat(request, hasFieldWithValue("email_address", equalTo(TEST_EMAIL_ADDRESS)));
assertThat(request, hasField("personalisation"));
JsonNode personalisation = request.get("personalisation");
assertThat(personalisation, hasFieldWithValue("contact-us-link", equalTo("http://localhost:3000/frontend/contact-us")));
}
use of uk.gov.di.authentication.shared.entity.NotifyRequest in project di-authentication-api by alphagov.
the class NotificationHandlerIntegrationTest method shouldCallNotifyWhenValidEmailRequestIsAddedToQueue.
@Test
void shouldCallNotifyWhenValidEmailRequestIsAddedToQueue() throws JsonProcessingException {
handler.handleRequest(createSqsEvent(new NotifyRequest(TEST_EMAIL_ADDRESS, VERIFY_EMAIL, CODE)), mock(Context.class));
JsonNode request = notifyStub.waitForRequest(60);
assertThat(request, hasFieldWithValue("email_address", equalTo(TEST_EMAIL_ADDRESS)));
assertThat(request, hasField("personalisation"));
JsonNode personalisation = request.get("personalisation");
assertThat(personalisation, hasFieldWithValue("email-address", equalTo(TEST_EMAIL_ADDRESS)));
assertThat(personalisation, hasFieldWithValue("validation-code", equalTo(CODE)));
assertThat(personalisation, hasFieldWithValue("validation-code", withLength(equalTo(VERIFICATION_CODE_LENGTH))));
}
use of uk.gov.di.authentication.shared.entity.NotifyRequest in project di-authentication-api by alphagov.
the class ResetPasswordRequestHandlerTest method shouldReturn200AndPutMessageOnQueueForAValidRequest.
@Test
void shouldReturn200AndPutMessageOnQueueForAValidRequest() throws JsonProcessingException {
String persistentId = "some-persistent-id-value";
Map<String, String> headers = new HashMap<>();
headers.put(PersistentIdHelper.PERSISTENT_ID_HEADER_NAME, persistentId);
headers.put("Session-Id", session.getSessionId());
Subject subject = new Subject("subject_1");
when(validationService.validateEmailAddress(eq(TEST_EMAIL_ADDRESS))).thenReturn(Optional.empty());
when(authenticationService.getSubjectFromEmail(TEST_EMAIL_ADDRESS)).thenReturn(subject);
when(resetPasswordService.buildResetPasswordLink(TEST_SIX_DIGIT_CODE, session.getSessionId(), persistentId)).thenReturn(TEST_RESET_PASSWORD_LINK);
NotifyRequest notifyRequest = new NotifyRequest(TEST_EMAIL_ADDRESS, RESET_PASSWORD, TEST_RESET_PASSWORD_LINK);
ObjectMapper objectMapper = new ObjectMapper();
String serialisedRequest = objectMapper.writeValueAsString(notifyRequest);
usingValidSession();
APIGatewayProxyRequestEvent event = new APIGatewayProxyRequestEvent();
event.setRequestContext(contextWithSourceIp("123.123.123.123"));
event.setHeaders(headers);
event.setBody(format("{ \"email\": \"%s\" }", TEST_EMAIL_ADDRESS));
APIGatewayProxyResponseEvent result = handler.handleRequest(event, context);
assertEquals(204, result.getStatusCode());
verify(awsSqsClient).send(serialisedRequest);
verify(codeStorageService).savePasswordResetCode(subject.getValue(), TEST_SIX_DIGIT_CODE, CODE_EXPIRY_TIME, RESET_PASSWORD);
verify(sessionService).save(argThat(this::isSessionWithEmailSent));
verify(auditService).submitAuditEvent(FrontendAuditableEvent.PASSWORD_RESET_REQUESTED, context.getAwsRequestId(), session.getSessionId(), AuditService.UNKNOWN, AuditService.UNKNOWN, TEST_EMAIL_ADDRESS, "123.123.123.123", AuditService.UNKNOWN, persistentId);
}
use of uk.gov.di.authentication.shared.entity.NotifyRequest in project di-authentication-api by alphagov.
the class NotificationHandlerTest method shouldSuccessfullyProcessMfaessageFromSQSQueue.
@Test
void shouldSuccessfullyProcessMfaessageFromSQSQueue() throws JsonProcessingException, NotificationClientException {
NotifyRequest notifyRequest = new NotifyRequest(TEST_PHONE_NUMBER, MFA_SMS, "654321");
String notifyRequestString = objectMapper.writeValueAsString(notifyRequest);
SQSEvent sqsEvent = generateSQSEvent(notifyRequestString);
handler.handleRequest(sqsEvent, context);
Map<String, Object> personalisation = new HashMap<>();
personalisation.put("validation-code", "654321");
verify(notificationService).sendText(notifyRequest.getDestination(), personalisation, MFA_SMS);
}
Aggregations