use of uk.gov.di.accountmanagement.entity.SendNotificationRequest in project di-authentication-api by alphagov.
the class SendOtpNotificationIntegrationTest method shouldReturn400ForVerifyEmailRequestWhenUserAlreadyExists.
@Test
void shouldReturn400ForVerifyEmailRequestWhenUserAlreadyExists() throws Exception {
String password = "password-1";
userStore.signUp(TEST_EMAIL, password);
var response = makeRequest(Optional.of(new SendNotificationRequest(TEST_EMAIL, VERIFY_EMAIL, TEST_PHONE_NUMBER)), Collections.emptyMap(), Collections.emptyMap());
assertThat(response, hasStatus(HttpStatus.SC_BAD_REQUEST));
assertThat(response, hasBody(new ObjectMapper().writeValueAsString(ErrorResponse.ERROR_1009)));
NotificationAssertionHelper.assertNoNotificationsReceived(notificationsQueue);
assertNoAuditEventsReceived(auditTopic);
}
use of uk.gov.di.accountmanagement.entity.SendNotificationRequest in project di-authentication-api by alphagov.
the class SendOtpNotificationHandler method handleRequest.
@Override
public APIGatewayProxyResponseEvent handleRequest(APIGatewayProxyRequestEvent input, Context context) {
return isWarming(input).orElseGet(() -> {
String sessionId = RequestHeaderHelper.getHeaderValueOrElse(input.getHeaders(), SESSION_ID_HEADER, "");
attachSessionIdToLogs(sessionId);
LOG.info("Request received in SendOtp Lambda");
try {
SendNotificationRequest sendNotificationRequest = objectMapper.readValue(input.getBody(), SendNotificationRequest.class);
switch(sendNotificationRequest.getNotificationType()) {
case VERIFY_EMAIL:
LOG.info("NotificationType is VERIFY_EMAIL");
Optional<ErrorResponse> emailErrorResponse = validationService.validateEmailAddress(sendNotificationRequest.getEmail());
if (emailErrorResponse.isPresent()) {
return generateApiGatewayProxyErrorResponse(400, emailErrorResponse.get());
}
if (dynamoService.userExists(sendNotificationRequest.getEmail())) {
return generateApiGatewayProxyErrorResponse(400, ErrorResponse.ERROR_1009);
}
return handleNotificationRequest(sendNotificationRequest.getEmail(), sendNotificationRequest, input, context);
case VERIFY_PHONE_NUMBER:
LOG.info("NotificationType is VERIFY_PHONE_NUMBER");
Optional<ErrorResponse> phoneNumberValidationError = validationService.validatePhoneNumber(sendNotificationRequest.getPhoneNumber());
if (phoneNumberValidationError.isPresent()) {
return generateApiGatewayProxyErrorResponse(400, phoneNumberValidationError.get());
}
return handleNotificationRequest(sendNotificationRequest.getPhoneNumber(), sendNotificationRequest, input, context);
}
return generateApiGatewayProxyErrorResponse(400, ERROR_1002);
} catch (SdkClientException ex) {
LOG.error("Error sending message to queue", ex);
return generateApiGatewayProxyResponse(500, "Error sending message to queue");
} catch (JsonProcessingException e) {
return generateApiGatewayProxyErrorResponse(400, ERROR_1001);
}
});
}
use of uk.gov.di.accountmanagement.entity.SendNotificationRequest in project di-authentication-api by alphagov.
the class SendOtpNotificationHandler method sendOtpRequestHandler.
public APIGatewayProxyResponseEvent sendOtpRequestHandler(APIGatewayProxyRequestEvent input, Context context) {
return isWarming(input).orElseGet(() -> {
String sessionId = RequestHeaderHelper.getHeaderValueOrElse(input.getHeaders(), SESSION_ID_HEADER, "");
attachSessionIdToLogs(sessionId);
LOG.info("Request received in SendOtp Lambda");
try {
SendNotificationRequest sendNotificationRequest = objectMapper.readValue(input.getBody(), SendNotificationRequest.class);
switch(sendNotificationRequest.getNotificationType()) {
case VERIFY_EMAIL:
LOG.info("NotificationType is VERIFY_EMAIL");
Optional<ErrorResponse> emailErrorResponse = ValidationHelper.validateEmailAddress(sendNotificationRequest.getEmail());
if (emailErrorResponse.isPresent()) {
return generateApiGatewayProxyErrorResponse(400, emailErrorResponse.get());
}
if (dynamoService.userExists(sendNotificationRequest.getEmail())) {
return generateApiGatewayProxyErrorResponse(400, ErrorResponse.ERROR_1009);
}
return handleNotificationRequest(sendNotificationRequest.getEmail(), sendNotificationRequest, input, context);
case VERIFY_PHONE_NUMBER:
LOG.info("NotificationType is VERIFY_PHONE_NUMBER");
Optional<ErrorResponse> phoneNumberValidationError = ValidationHelper.validatePhoneNumber(sendNotificationRequest.getPhoneNumber());
if (phoneNumberValidationError.isPresent()) {
return generateApiGatewayProxyErrorResponse(400, phoneNumberValidationError.get());
}
return handleNotificationRequest(sendNotificationRequest.getPhoneNumber(), sendNotificationRequest, input, context);
}
return generateApiGatewayProxyErrorResponse(400, ERROR_1002);
} catch (SdkClientException ex) {
LOG.error("Error sending message to queue", ex);
return generateApiGatewayProxyResponse(500, "Error sending message to queue");
} catch (JsonException e) {
return generateApiGatewayProxyErrorResponse(400, ERROR_1001);
}
});
}
Aggregations