use of com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent in project di-authentication-api by alphagov.
the class SignUpHandlerTest method shouldReturn400IfSessionIdMissing.
@Test
void shouldReturn400IfSessionIdMissing() {
APIGatewayProxyRequestEvent event = new APIGatewayProxyRequestEvent();
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_1000));
verifyNoInteractions(auditService);
}
use of com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent in project di-authentication-api by alphagov.
the class SignUpHandlerTest method shouldReturn400IfPasswordFailsValidation.
@Test
void shouldReturn400IfPasswordFailsValidation() {
usingValidSession();
APIGatewayProxyRequestEvent event = new APIGatewayProxyRequestEvent();
event.setHeaders(Map.of("Session-Id", session.getSessionId()));
event.setBody("{ \"password\": \"computer\", \"email\": \"joe.bloggs@test.com\" }");
APIGatewayProxyResponseEvent result = handler.handleRequest(event, context);
assertThat(result, hasStatus(400));
assertThat(result, hasJsonBody(ErrorResponse.ERROR_1007));
verifyNoInteractions(auditService);
}
use of com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent in project di-authentication-api by alphagov.
the class StartHandlerTest method shouldReturn400WhenBuildClientStartInfoThrowsException.
@Test
void shouldReturn400WhenBuildClientStartInfoThrowsException() throws ParseException, Json.JsonException {
when(startService.buildUserContext(session, clientSession)).thenReturn(userContext);
when(startService.buildClientStartInfo(userContext)).thenThrow(new ParseException("Unable to parse authentication request"));
usingValidClientSession();
usingValidSession();
Map<String, String> headers = new HashMap<>();
headers.put(PersistentIdHelper.PERSISTENT_ID_HEADER_NAME, PERSISTENT_ID);
headers.put(CLIENT_SESSION_ID_HEADER, CLIENT_SESSION_ID);
headers.put(SESSION_ID_HEADER, SESSION_ID);
APIGatewayProxyRequestEvent event = new APIGatewayProxyRequestEvent();
event.setHeaders(headers);
event.setRequestContext(contextWithSourceIp("123.123.123.123"));
APIGatewayProxyResponseEvent result = handler.handleRequest(event, context);
assertThat(result, hasStatus(400));
String expectedResponse = objectMapper.writeValueAsString(ErrorResponse.ERROR_1038);
assertThat(result, hasBody(expectedResponse));
verifyNoInteractions(auditService);
}
use of com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent in project di-authentication-api by alphagov.
the class UpdateProfileHandlerTest method shouldReturn204WhenUpdatingProfileWithConsent.
@Test
void shouldReturn204WhenUpdatingProfileWithConsent() throws ClientNotFoundException, URISyntaxException {
usingValidSession();
APIGatewayProxyRequestEvent event = new APIGatewayProxyRequestEvent();
ClientID clientID = new ClientID();
AuthorizationCode authorizationCode = new AuthorizationCode();
AuthenticationRequest authRequest = generateValidClientSessionAndAuthRequest(clientID);
AuthenticationSuccessResponse authSuccessResponse = new AuthenticationSuccessResponse(authRequest.getRedirectionURI(), authorizationCode, null, null, authRequest.getState(), null, null);
when(authenticationService.getUserProfileFromEmail(TEST_EMAIL_ADDRESS)).thenReturn(Optional.of(generateUserProfileWithoutConsent()));
event.setHeaders(Map.of(COOKIE, buildCookieString("gs", SESSION_ID + "." + CLIENT_SESSION_ID, 3600, "Secure; HttpOnly;", "domain")));
event.setBody(format("{ \"email\": \"%s\", \"updateProfileType\": \"%s\", \"profileInformation\": \"%s\" }", TEST_EMAIL_ADDRESS, CAPTURE_CONSENT, CONSENT_VALUE));
APIGatewayProxyResponseEvent result = makeHandlerRequest(event);
verify(authenticationService).updateConsent(eq(TEST_EMAIL_ADDRESS), any(ClientConsent.class));
assertThat(result, hasStatus(204));
verify(auditService).submitAuditEvent(UPDATE_PROFILE_CONSENT_UPDATED, "request-id", session.getSessionId(), clientID.getValue(), INTERNAL_SUBJECT, TEST_EMAIL_ADDRESS, "", PHONE_NUMBER, PersistentIdHelper.PERSISTENT_ID_UNKNOWN_VALUE);
}
use of com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent in project di-authentication-api by alphagov.
the class VerifyCodeHandlerTest method shouldReturn400IfSessionIdIsInvalid.
@Test
void shouldReturn400IfSessionIdIsInvalid() {
APIGatewayProxyResponseEvent result = makeCallWithCode(CODE, VERIFY_EMAIL.toString(), Optional.empty(), CLIENT_ID);
assertThat(result, hasStatus(400));
assertThat(result, hasJsonBody(ErrorResponse.ERROR_1000));
}
Aggregations