use of com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent in project di-authentication-api by alphagov.
the class IPVCallbackHandlerTest method shouldThrowWhenSessionIsNotFoundInRedis.
@Test
void shouldThrowWhenSessionIsNotFoundInRedis() {
APIGatewayProxyRequestEvent event = new APIGatewayProxyRequestEvent();
event.setQueryStringParameters(Collections.emptyMap());
event.setHeaders(Map.of(COOKIE, buildCookieString()));
RuntimeException expectedException = assertThrows(RuntimeException.class, () -> handler.handleRequest(event, context), "Expected to throw exception");
assertThat(expectedException.getMessage(), containsString("Session not found"));
}
use of com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent in project di-authentication-api by alphagov.
the class TokenHandlerTest method generateApiGatewayRequest.
private APIGatewayProxyResponseEvent generateApiGatewayRequest(PrivateKeyJWT privateKeyJWT, String authorisationCode, String redirectUri) {
Map<String, List<String>> customParams = new HashMap<>();
customParams.put("grant_type", Collections.singletonList(GrantType.AUTHORIZATION_CODE.getValue()));
customParams.put("client_id", Collections.singletonList(CLIENT_ID));
customParams.put("code", Collections.singletonList(authorisationCode));
customParams.put("redirect_uri", Collections.singletonList(redirectUri));
Map<String, List<String>> privateKeyParams = privateKeyJWT.toParameters();
privateKeyParams.putAll(customParams);
String requestParams = URLUtils.serializeParameters(privateKeyParams);
APIGatewayProxyRequestEvent event = new APIGatewayProxyRequestEvent();
event.setBody(requestParams);
return handler.handleRequest(event, context);
}
use of com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent in project di-authentication-api by alphagov.
the class IPVAuthorisationHandlerTest method shouldReturn200AndRedirectURIWithClaims.
@Test
void shouldReturn200AndRedirectURIWithClaims() throws JsonProcessingException, UnsupportedEncodingException {
usingValidSession();
usingValidClientSession(TEST_CLIENT_ID);
Map<String, String> headers = new HashMap<>();
headers.put(PersistentIdHelper.PERSISTENT_ID_HEADER_NAME, PERSISTENT_SESSION_ID);
headers.put("Session-Id", session.getSessionId());
APIGatewayProxyRequestEvent event = new APIGatewayProxyRequestEvent();
event.setHeaders(headers);
event.setBody(format("{ \"email\": \"%s\"}", TEST_EMAIL_ADDRESS));
event.setRequestContext(contextWithSourceIp("123.123.123.123"));
APIGatewayProxyResponseEvent response = makeHandlerRequest(event);
assertThat(response, hasStatus(200));
IPVAuthorisationResponse body = new ObjectMapper().readValue(response.getBody(), IPVAuthorisationResponse.class);
assertThat(body.getRedirectUri(), startsWith(IPV_AUTHORISATION_URI + "/authorize"));
assertThat(splitQuery(body.getRedirectUri()).get("claims"), equalTo(claimsSetRequest.toJSONString()));
verify(authorisationService).storeState(eq(session.getSessionId()), any(State.class));
}
use of com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent 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.APIGatewayProxyRequestEvent 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));
}
Aggregations