use of com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent in project aws-lambda-powertools-java by awslabs.
the class BasePersistenceStoreTest method saveInProgress_jmespath.
@Test
public void saveInProgress_jmespath() {
APIGatewayProxyRequestEvent event = EventLoader.loadApiGatewayRestEvent("apigw_event.json");
persistenceStore.configure(IdempotencyConfig.builder().withEventKeyJMESPath("powertools_json(body).id").build(), "myfunc");
Instant now = Instant.now();
persistenceStore.saveInProgress(JsonConfig.get().getObjectMapper().valueToTree(event), now);
assertThat(dr.getStatus()).isEqualTo(DataRecord.Status.INPROGRESS);
assertThat(dr.getExpiryTimestamp()).isEqualTo(now.plus(3600, ChronoUnit.SECONDS).getEpochSecond());
assertThat(dr.getResponseData()).isNull();
assertThat(dr.getIdempotencyKey()).isEqualTo("testFunction.myfunc#2fef178cc82be5ce3da6c5e0466a6182");
assertThat(dr.getPayloadHash()).isEqualTo("");
assertThat(status).isEqualTo(1);
}
use of com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent in project aws-lambda-powertools-java by awslabs.
the class BasePersistenceStoreTest method saveSuccess_shouldUpdateRecord.
// </editor-fold>
// =================================================================
// =================================================================
// <editor-fold desc="saveSuccess">
@Test
public void saveSuccess_shouldUpdateRecord() throws JsonProcessingException {
APIGatewayProxyRequestEvent event = EventLoader.loadApiGatewayRestEvent("apigw_event.json");
LRUCache<String, DataRecord> cache = new LRUCache<>(2);
persistenceStore.configure(IdempotencyConfig.builder().build(), null, cache);
Product product = new Product(34543, "product", 42);
Instant now = Instant.now();
persistenceStore.saveSuccess(JsonConfig.get().getObjectMapper().valueToTree(event), product, now);
assertThat(dr.getStatus()).isEqualTo(DataRecord.Status.COMPLETED);
assertThat(dr.getExpiryTimestamp()).isEqualTo(now.plus(3600, ChronoUnit.SECONDS).getEpochSecond());
assertThat(dr.getResponseData()).isEqualTo(JsonConfig.get().getObjectMapper().writeValueAsString(product));
assertThat(dr.getIdempotencyKey()).isEqualTo("testFunction#47261bd5b456f400f8d191cfb3a7482f");
assertThat(dr.getPayloadHash()).isEqualTo("");
assertThat(status).isEqualTo(2);
assertThat(cache).isEmpty();
}
use of com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent in project aws-lambda-powertools-java by awslabs.
the class BasePersistenceStoreTest method saveInProgress_jmespath_NotFound_shouldNotThrowException.
@Test
public void saveInProgress_jmespath_NotFound_shouldNotThrowException() {
APIGatewayProxyRequestEvent event = EventLoader.loadApiGatewayRestEvent("apigw_event.json");
persistenceStore.configure(IdempotencyConfig.builder().withEventKeyJMESPath("unavailable").build(), "");
Instant now = Instant.now();
persistenceStore.saveInProgress(JsonConfig.get().getObjectMapper().valueToTree(event), now);
assertThat(dr.getStatus()).isEqualTo(DataRecord.Status.INPROGRESS);
assertThat(status).isEqualTo(1);
}
use of com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent in project aws-lambda-powertools-java by awslabs.
the class ValidationAspectTest method validate_inputOK_schemaInClasspath_shouldValidate.
@Test
public void validate_inputOK_schemaInClasspath_shouldValidate() {
ValidationInboundClasspathHandler handler = new ValidationInboundClasspathHandler();
APIGatewayProxyRequestEvent event = new APIGatewayProxyRequestEvent();
event.setBody("{" + " \"id\": 1," + " \"name\": \"Lampshade\"," + " \"price\": 42" + "}");
assertThat(handler.handleRequest(event, context)).isEqualTo("OK");
}
use of com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent in project di-authentication-api by alphagov.
the class AuthorisationHandler method handleRequest.
@Override
public APIGatewayProxyResponseEvent handleRequest(APIGatewayProxyRequestEvent input, Context context) {
return isWarming(input).orElseGet(() -> {
var persistentSessionId = authorizationService.getExistingOrCreateNewPersistentSessionId(input.getHeaders());
var ipAddress = IpAddressHelper.extractIpAddress(input);
auditService.submitAuditEvent(OidcAuditableEvent.AUTHORISATION_REQUEST_RECEIVED, context.getAwsRequestId(), AuditService.UNKNOWN, AuditService.UNKNOWN, AuditService.UNKNOWN, AuditService.UNKNOWN, ipAddress, AuditService.UNKNOWN, persistentSessionId);
attachLogFieldToLogs(PERSISTENT_SESSION_ID, persistentSessionId);
attachLogFieldToLogs(AWS_REQUEST_ID, context.getAwsRequestId());
LOG.info("Received authentication request");
Map<String, List<String>> queryStringParameters;
AuthenticationRequest authRequest;
try {
queryStringParameters = input.getQueryStringParameters().entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, entry -> List.of(entry.getValue())));
authRequest = AuthenticationRequest.parse(queryStringParameters);
} catch (ParseException e) {
if (e.getRedirectionURI() == null) {
LOG.warn("Authentication request could not be parsed: redirect URI or Client ID is missing from auth request");
throw new RuntimeException("Redirect URI or ClientID is missing from auth request", e);
}
LOG.warn("Authentication request could not be parsed", e);
return generateErrorResponse(e.getRedirectionURI(), e.getState(), e.getResponseMode(), e.getErrorObject(), context, ipAddress, persistentSessionId);
} catch (NullPointerException e) {
LOG.warn("No query string parameters are present in the Authentication request", e);
throw new RuntimeException("No query string parameters are present in the Authentication request", e);
}
var error = authorizationService.validateAuthRequest(authRequest);
return error.map(e -> generateErrorResponse(authRequest.getRedirectionURI(), authRequest.getState(), authRequest.getResponseMode(), e, context, ipAddress, persistentSessionId)).orElseGet(() -> getOrCreateSessionAndRedirect(queryStringParameters, sessionService.getSessionFromSessionCookie(input.getHeaders()), authRequest, context, ipAddress, persistentSessionId));
});
}
Aggregations