use of com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent in project di-authentication-api by alphagov.
the class CheckUserExistsHandlerTest method shouldReturn200IfUserTransitionsFromUserNotFoundAndUserDoesNotExist.
@Test
public void shouldReturn200IfUserTransitionsFromUserNotFoundAndUserDoesNotExist() throws JsonProcessingException {
usingValidSession();
when(authenticationService.userExists(eq("joe.bloggs"))).thenReturn(false);
APIGatewayProxyRequestEvent event = new APIGatewayProxyRequestEvent();
event.setBody("{ \"email\": \"joe.bloggs\" }");
event.setHeaders(Map.of("Session-Id", session.getSessionId()));
event.setRequestContext(contextWithSourceIp("123.123.123.123"));
APIGatewayProxyResponseEvent result = handler.handleRequest(event, context);
assertEquals(200, result.getStatusCode());
CheckUserExistsResponse checkUserExistsResponse = objectMapper.readValue(result.getBody(), CheckUserExistsResponse.class);
assertEquals("joe.bloggs", checkUserExistsResponse.getEmail());
assertFalse(checkUserExistsResponse.doesUserExist());
verify(auditService).submitAuditEvent(FrontendAuditableEvent.CHECK_USER_NO_ACCOUNT_WITH_EMAIL, "aws-session-id", session.getSessionId(), "", auditService.UNKNOWN, "joe.bloggs", "123.123.123.123", AuditService.UNKNOWN, PersistentIdHelper.PERSISTENT_ID_UNKNOWN_VALUE);
}
use of com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent in project di-authentication-api by alphagov.
the class SendNotificationHandlerTest method shouldReturn400WhenPhoneNumberIsInvalid.
@Test
void shouldReturn400WhenPhoneNumberIsInvalid() {
when(validationService.validatePhoneNumber(eq("123456789"))).thenReturn(Optional.of(ErrorResponse.ERROR_1012));
usingValidSession();
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, "123456789"));
APIGatewayProxyResponseEvent result = handler.handleRequest(event, context);
assertEquals(400, result.getStatusCode());
assertThat(result, hasJsonBody(ErrorResponse.ERROR_1012));
}
use of com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent 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 com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent in project di-authentication-api by alphagov.
the class ResetPasswordHandlerTest method shouldReturn204ForSuccessfulRequest.
@Test
public void shouldReturn204ForSuccessfulRequest() throws JsonProcessingException {
when(codeStorageService.getSubjectWithPasswordResetCode(CODE)).thenReturn(Optional.of(SUBJECT));
when(authenticationService.getUserCredentialsFromSubject(SUBJECT)).thenReturn(generateUserCredentials());
usingValidSession();
NotifyRequest notifyRequest = new NotifyRequest(EMAIL, NotificationType.PASSWORD_RESET_CONFIRMATION);
Map<String, String> headers = new HashMap<>();
headers.put(PersistentIdHelper.PERSISTENT_ID_HEADER_NAME, PERSISTENT_ID);
headers.put("Session-Id", session.getSessionId());
APIGatewayProxyRequestEvent event = new APIGatewayProxyRequestEvent();
event.setHeaders(headers);
event.setBody(format("{ \"code\": \"%s\", \"password\": \"%s\"}", CODE, NEW_PASSWORD));
event.setRequestContext(contextWithSourceIp("123.123.123.123"));
APIGatewayProxyResponseEvent result = handler.handleRequest(event, context);
assertThat(result, hasStatus(204));
verify(sqsClient, times(1)).send(new ObjectMapper().writeValueAsString(notifyRequest));
verify(authenticationService, times(1)).updatePassword(EMAIL, NEW_PASSWORD);
verify(codeStorageService, times(1)).deleteSubjectWithPasswordResetCode(CODE);
verify(auditService).submitAuditEvent(FrontendAuditableEvent.PASSWORD_RESET_SUCCESSFUL, context.getAwsRequestId(), session.getSessionId(), AuditService.UNKNOWN, AuditService.UNKNOWN, EMAIL, "123.123.123.123", AuditService.UNKNOWN, PERSISTENT_ID);
}
use of com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent in project spring-cloud-function by spring-cloud.
the class SpringBootApiGatewayRequestHandlerTests method functionBean.
@Test
public void functionBean() {
handler = new SpringBootApiGatewayRequestHandler(FunctionConfig.class);
handler.initialize();
APIGatewayProxyRequestEvent request = new APIGatewayProxyRequestEvent();
request.setBody("{\"value\":\"foo\"}");
Object output = handler.handleRequest(request, null);
assertThat(output).isInstanceOf(APIGatewayProxyResponseEvent.class);
assertThat(((APIGatewayProxyResponseEvent) output).getStatusCode()).isEqualTo(200);
assertThat(((APIGatewayProxyResponseEvent) output).getBody()).isEqualTo("{\"value\":\"FOO\"}");
}
Aggregations