use of com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent in project di-authentication-api by alphagov.
the class SendNotificationHandlerTest method shouldReturn400IfUserIsBlockedFromEnteringEmailOtpCodes.
@Test
void shouldReturn400IfUserIsBlockedFromEnteringEmailOtpCodes() {
when(codeStorageService.isBlockedForEmail(TEST_EMAIL_ADDRESS, CODE_BLOCKED_KEY_PREFIX)).thenReturn(true);
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_1033));
}
use of com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent in project di-authentication-api by alphagov.
the class SendNotificationHandlerTest method shouldReturn204AndPutMessageOnQueueForAValidVerifyPhoneNumberRequest.
@Test
void shouldReturn204AndPutMessageOnQueueForAValidVerifyPhoneNumberRequest() {
usingValidSession();
usingValidClientSession(CLIENT_ID);
APIGatewayProxyRequestEvent event = new APIGatewayProxyRequestEvent();
event.setHeaders(Map.of("Session-Id", session.getSessionId()));
event.setBody(format("{ \"email\": \"%s\", \"notificationType\": \"%s\", \"phoneNumber\": \"%s\" }", TEST_EMAIL_ADDRESS, VERIFY_PHONE_NUMBER, TEST_PHONE_NUMBER));
APIGatewayProxyResponseEvent result = handler.handleRequest(event, context);
assertEquals(204, result.getStatusCode());
}
use of com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent in project di-authentication-api by alphagov.
the class SendNotificationHandlerTest method shouldReturn400IfUserHasReachedThePhoneCodeRequestLimit.
@Test
void shouldReturn400IfUserHasReachedThePhoneCodeRequestLimit() {
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_PHONE_NUMBER));
APIGatewayProxyResponseEvent result = handler.handleRequest(event, context);
assertEquals(400, result.getStatusCode());
assertThat(result, hasJsonBody(ErrorResponse.ERROR_1030));
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_PHONE_NUMBER);
}
use of com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent in project di-authentication-api by alphagov.
the class SendNotificationHandlerTest method shouldReturn500IfMessageCannotBeSentToQueue.
@Test
void shouldReturn500IfMessageCannotBeSentToQueue() throws Json.JsonException {
NotifyRequest notifyRequest = new NotifyRequest(TEST_EMAIL_ADDRESS, VERIFY_EMAIL, TEST_SIX_DIGIT_CODE);
String serialisedRequest = objectMapper.writeValueAsString(notifyRequest);
Mockito.doThrow(SdkClientException.class).when(awsSqsClient).send(eq(serialisedRequest));
usingValidSession();
usingValidClientSession(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(500, result.getStatusCode());
assertTrue(result.getBody().contains("Error sending message to queue"));
}
use of com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent in project di-authentication-api by alphagov.
the class SignUpHandlerTest method shouldReturn400IfUserAlreadyExists.
@Test
void shouldReturn400IfUserAlreadyExists() {
when(authenticationService.userExists(eq("joe.bloggs@test.com"))).thenReturn(true);
usingValidSession();
APIGatewayProxyRequestEvent event = new APIGatewayProxyRequestEvent();
event.setRequestContext(contextWithSourceIp("123.123.123.123"));
event.setHeaders(Map.of("Session-Id", "a-session-id"));
event.setBody("{ \"password\": \"computer-1\", \"email\": \"joe.bloggs@test.com\" }");
APIGatewayProxyResponseEvent result = handler.handleRequest(event, context);
assertThat(result, hasStatus(400));
assertThat(result, hasJsonBody(ErrorResponse.ERROR_1009));
verify(auditService).submitAuditEvent(FrontendAuditableEvent.CREATE_ACCOUNT_EMAIL_ALREADY_EXISTS, context.getAwsRequestId(), session.getSessionId(), AuditService.UNKNOWN, AuditService.UNKNOWN, "joe.bloggs@test.com", "123.123.123.123", AuditService.UNKNOWN, PersistentIdHelper.PERSISTENT_ID_UNKNOWN_VALUE);
}
Aggregations