use of com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent in project di-authentication-api by alphagov.
the class ResetPasswordRequestHandlerTest method shouldReturn500IfMessageCannotBeSentToQueue.
@Test
public void shouldReturn500IfMessageCannotBeSentToQueue() throws Json.JsonException {
String persistentId = "some-persistent-id-value";
Subject subject = new Subject("subject_1");
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);
String serialisedRequest = objectMapper.writeValueAsString(notifyRequest);
Mockito.doThrow(SdkClientException.class).when(awsSqsClient).send(eq(serialisedRequest));
usingValidSession();
APIGatewayProxyRequestEvent event = new APIGatewayProxyRequestEvent();
Map<String, String> headers = new HashMap<>();
headers.put(PersistentIdHelper.PERSISTENT_ID_HEADER_NAME, persistentId);
headers.put("Session-Id", session.getSessionId());
event.setHeaders(headers);
event.setBody(format("{ \"email\": \"%s\" }", TEST_EMAIL_ADDRESS));
APIGatewayProxyResponseEvent result = handler.handleRequest(event, context);
assertEquals(500, result.getStatusCode());
assertTrue(result.getBody().contains("Error sending message to queue"));
}
use of com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent in project di-authentication-api by alphagov.
the class SendNotificationHandlerTest method shouldReturn204WhenSendingAccountCreationEmail.
@Test
void shouldReturn204WhenSendingAccountCreationEmail() throws Json.JsonException {
usingValidSession();
APIGatewayProxyRequestEvent event = new APIGatewayProxyRequestEvent();
event.setHeaders(Map.of("Session-Id", session.getSessionId()));
event.setBody(format("{ \"email\": \"%s\", \"notificationType\": \"%s\" }", TEST_EMAIL_ADDRESS, ACCOUNT_CREATED_CONFIRMATION));
APIGatewayProxyResponseEvent result = handler.handleRequest(event, context);
NotifyRequest notifyRequest = new NotifyRequest(TEST_EMAIL_ADDRESS, ACCOUNT_CREATED_CONFIRMATION);
verify(awsSqsClient).send(objectMapper.writeValueAsString(notifyRequest));
assertEquals(204, result.getStatusCode());
}
use of com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent in project di-authentication-api by alphagov.
the class SendNotificationHandlerTest method shouldReturn400IfUserHasReachedTheEmailCodeRequestLimit.
@Test
void shouldReturn400IfUserHasReachedTheEmailCodeRequestLimit() {
maxOutCodeRequestCount();
usingValidSession();
APIGatewayProxyRequestEvent event = new APIGatewayProxyRequestEvent();
event.setHeaders(Map.of("Session-Id", session.getSessionId()));
event.setBody(format("{ \"email\": \"%s\", \"notificationType\": \"%s\" }", TEST_EMAIL_ADDRESS, VERIFY_EMAIL));
APIGatewayProxyResponseEvent result = handler.handleRequest(event, context);
assertEquals(400, result.getStatusCode());
assertThat(result, hasJsonBody(ErrorResponse.ERROR_1029));
verify(codeStorageService).saveBlockedForEmail(TEST_EMAIL_ADDRESS, CODE_REQUEST_BLOCKED_KEY_PREFIX, BLOCKED_EMAIL_DURATION);
verify(codeStorageService, never()).saveOtpCode(TEST_EMAIL_ADDRESS, TEST_SIX_DIGIT_CODE, CODE_EXPIRY_TIME, VERIFY_EMAIL);
}
use of com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent in project di-authentication-api by alphagov.
the class SendNotificationHandlerTest method shouldReturn400WhenVerifyTypeIsVerifyPhoneNumberButRequestIsMissingNumber.
@Test
void shouldReturn400WhenVerifyTypeIsVerifyPhoneNumberButRequestIsMissingNumber() {
usingValidSession();
APIGatewayProxyRequestEvent event = new APIGatewayProxyRequestEvent();
event.setHeaders(Map.of("Session-Id", session.getSessionId()));
event.setBody(format("{ \"email\": \"%s\", \"notificationType\": \"%s\" }", TEST_EMAIL_ADDRESS, VERIFY_PHONE_NUMBER));
APIGatewayProxyResponseEvent result = handler.handleRequest(event, context);
assertEquals(400, result.getStatusCode());
assertThat(result, hasJsonBody(ErrorResponse.ERROR_1011));
}
use of com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent in project di-authentication-api by alphagov.
the class SendNotificationHandlerTest method shouldReturn204AndNotPutMessageOnQueueForAValidRequestUsingTestClientWithAllowedEmail.
@Test
void shouldReturn204AndNotPutMessageOnQueueForAValidRequestUsingTestClientWithAllowedEmail() throws Json.JsonException {
when(configurationService.isTestClientsEnabled()).thenReturn(true);
NotifyRequest notifyRequest = new NotifyRequest(TEST_EMAIL_ADDRESS, VERIFY_EMAIL, TEST_SIX_DIGIT_CODE);
String serialisedRequest = objectMapper.writeValueAsString(notifyRequest);
usingValidSession();
usingValidClientSession(TEST_CLIENT_ID);
APIGatewayProxyRequestEvent event = new APIGatewayProxyRequestEvent();
event.setHeaders(Map.of("Session-Id", session.getSessionId()));
event.setBody(format("{ \"email\": \"%s\", \"notificationType\": \"%s\" }", TEST_EMAIL_ADDRESS, VERIFY_EMAIL));
APIGatewayProxyResponseEvent result = handler.handleRequest(event, context);
assertEquals(204, result.getStatusCode());
verify(awsSqsClient, never()).send(serialisedRequest);
verify(codeStorageService).saveOtpCode(TEST_EMAIL_ADDRESS, TEST_SIX_DIGIT_CODE, CODE_EXPIRY_TIME, VERIFY_EMAIL);
verify(sessionService).save(argThat(this::isSessionWithEmailSent));
}
Aggregations