Search in sources :

Example 21 with ApiGatewayRequestEvent

use of com.formkiq.lambda.apigateway.ApiGatewayRequestEvent in project formkiq-core by formkiq.

the class ApiPublicWebhooksRequestTest method testPostWebhooks07.

/**
 * Post /public/webhooks without authentication and with redirect_uri and responseFields.
 *
 * @throws Exception an error has occurred
 */
@SuppressWarnings("unchecked")
@Test
public void testPostWebhooks07() throws Exception {
    // given
    createApiRequestHandler(getMap());
    for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
        String name = UUID.randomUUID().toString();
        String id = getAwsServices().webhookService().saveWebhook(siteId, name, "joe", null, "true");
        ApiGatewayRequestEvent event = toRequestEvent("/request-post-public-webhooks05.json", siteId, id);
        // when
        String response = handleRequest(event);
        // then
        Map<String, Object> m = fromJson(response, Map.class);
        final int mapsize = 2;
        assertEquals(mapsize, m.size());
        assertEquals("301.0", String.valueOf(m.get("statusCode")));
        Map<String, Object> headers = (Map<String, Object>) m.get("headers");
        assertEquals("https://www.google.ca?client=safari&fname=John&lname=Doe&kdhfsd=null", headers.get("Location"));
    }
}
Also used : ApiGatewayRequestEvent(com.formkiq.lambda.apigateway.ApiGatewayRequestEvent) DynamicObject(com.formkiq.stacks.common.objects.DynamicObject) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 22 with ApiGatewayRequestEvent

use of com.formkiq.lambda.apigateway.ApiGatewayRequestEvent in project formkiq-core by formkiq.

the class ApiPublicWebhooksRequestTest method testPostWebhooks14.

/**
 * Post /public/webhooks with enabled=private .
 *
 * @throws Exception an error has occurred
 */
@SuppressWarnings("unchecked")
@Test
public void testPostWebhooks14() throws Exception {
    // given
    createApiRequestHandler(getMap());
    for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
        String name = UUID.randomUUID().toString();
        String id = getAwsServices().webhookService().saveWebhook(siteId, name, "joe", null, "private");
        ApiGatewayRequestEvent event = toRequestEvent("/request-post-public-webhooks01.json", siteId, id);
        // when
        String response = handleRequest(event);
        // then
        Map<String, String> m = fromJson(response, Map.class);
        verifyHeaders(m, "401.0");
    }
}
Also used : ApiGatewayRequestEvent(com.formkiq.lambda.apigateway.ApiGatewayRequestEvent) Test(org.junit.jupiter.api.Test)

Example 23 with ApiGatewayRequestEvent

use of com.formkiq.lambda.apigateway.ApiGatewayRequestEvent in project formkiq-core by formkiq.

the class ApiPublicWebhooksRequestTest method testPostWebhooks12.

/**
 * Post /public/webhooks with Config 'DocumentTimeToLive'.
 *
 * @throws Exception an error has occurred
 */
@SuppressWarnings("unchecked")
@Test
public void testPostWebhooks12() throws Exception {
    // given
    createApiRequestHandler(getMap());
    for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
        String name = UUID.randomUUID().toString();
        getAwsServices().configService().save(siteId, new DynamicObject(Map.of(DOCUMENT_TIME_TO_LIVE, "1000")));
        String id = getAwsServices().webhookService().saveWebhook(siteId, name, "joe", null, "true");
        ApiGatewayRequestEvent event = toRequestEvent("/request-post-public-webhooks01.json", siteId, id);
        // when
        String response = handleRequest(event);
        // then
        Map<String, String> m = fromJson(response, Map.class);
        verifyHeaders(m, "200.0");
        Map<String, Object> body = fromJson(m.get("body"), Map.class);
        String documentId = body.get("documentId").toString();
        assertNotNull(documentId);
        // verify s3 file
        try (S3Client s3 = getS3().buildClient()) {
            String key = createDatabaseKey(siteId, documentId + FORMKIQ_DOC_EXT);
            String json = getS3().getContentAsString(s3, STAGE_BUCKET_NAME, key, null);
            Map<String, Object> map = fromJson(json, Map.class);
            assertEquals(documentId, map.get("documentId"));
            assertEquals("webhook/" + name, map.get("userId"));
            assertEquals("webhooks/" + id, map.get("path"));
            assertEquals("{\"name\":\"john smith\"}", map.get("content"));
            assertEquals("1000", map.get("TimeToLive"));
        }
    }
}
Also used : DynamicObject(com.formkiq.stacks.common.objects.DynamicObject) ApiGatewayRequestEvent(com.formkiq.lambda.apigateway.ApiGatewayRequestEvent) DynamicObject(com.formkiq.stacks.common.objects.DynamicObject) S3Client(software.amazon.awssdk.services.s3.S3Client) Test(org.junit.jupiter.api.Test)

Example 24 with ApiGatewayRequestEvent

use of com.formkiq.lambda.apigateway.ApiGatewayRequestEvent in project formkiq-core by formkiq.

the class ApiPublicWebhooksRequestTest method toRequestEvent.

private ApiGatewayRequestEvent toRequestEvent(final String file, final String siteId, final String webhookId) throws IOException {
    ApiGatewayRequestEvent event = toRequestEvent(file);
    if (webhookId != null) {
        setPathParameter(event, "webhooks", webhookId);
    }
    if (siteId != null) {
        addParameter(event, "siteId", siteId);
    }
    event.getRequestContext().setAuthorizer(new HashMap<>());
    event.getRequestContext().setIdentity(new HashMap<>());
    return event;
}
Also used : ApiGatewayRequestEvent(com.formkiq.lambda.apigateway.ApiGatewayRequestEvent)

Example 25 with ApiGatewayRequestEvent

use of com.formkiq.lambda.apigateway.ApiGatewayRequestEvent in project formkiq-core by formkiq.

the class ApiRequestHandlerTest method testVersion01.

/**
 * /version request.
 *
 * @throws Exception an error has occurred
 */
@SuppressWarnings("unchecked")
@Test
public void testVersion01() throws Exception {
    // given
    ApiGatewayRequestEvent event = toRequestEvent("/request-version.json");
    // when
    String response = handleRequest(event);
    // then
    Map<String, String> m = fromJson(response, Map.class);
    final int mapsize = 3;
    assertEquals(mapsize, m.size());
    assertEquals("200.0", String.valueOf(m.get("statusCode")));
    assertEquals(getHeaders(), "\"headers\":" + GsonUtil.getInstance().toJson(m.get("headers")));
    Map<String, String> resp = fromJson(m.get("body"), Map.class);
    assertEquals("1.1", resp.get("version"));
    assertEquals("core", resp.get("type"));
}
Also used : ApiGatewayRequestEvent(com.formkiq.lambda.apigateway.ApiGatewayRequestEvent) Test(org.junit.jupiter.api.Test)

Aggregations

ApiGatewayRequestEvent (com.formkiq.lambda.apigateway.ApiGatewayRequestEvent)131 Test (org.junit.jupiter.api.Test)121 Date (java.util.Date)49 DynamicObject (com.formkiq.stacks.common.objects.DynamicObject)46 Map (java.util.Map)45 DocumentTag (com.formkiq.stacks.dynamodb.DocumentTag)34 DocumentItemDynamoDb (com.formkiq.stacks.dynamodb.DocumentItemDynamoDb)28 HashMap (java.util.HashMap)13 List (java.util.List)11 S3Client (software.amazon.awssdk.services.s3.S3Client)10 ZonedDateTime (java.time.ZonedDateTime)9 ApiMessageResponse (com.formkiq.lambda.apigateway.ApiMessageResponse)8 LambdaLogger (com.amazonaws.services.lambda.runtime.LambdaLogger)7 ApiAuthorizer (com.formkiq.lambda.apigateway.ApiAuthorizer)7 ApiGatewayRequestEventUtil (com.formkiq.lambda.apigateway.ApiGatewayRequestEventUtil)7 ApiGatewayRequestHandler (com.formkiq.lambda.apigateway.ApiGatewayRequestHandler)7 ApiRequestHandlerResponse (com.formkiq.lambda.apigateway.ApiRequestHandlerResponse)7 SC_OK (com.formkiq.lambda.apigateway.ApiResponseStatus.SC_OK)7 AwsServiceCache (com.formkiq.lambda.apigateway.AwsServiceCache)7 LocalDate (java.time.LocalDate)6