use of com.formkiq.lambda.apigateway.ApiGatewayRequestEvent in project formkiq-core by formkiq.
the class ApiPublicWebhooksRequestTest method testPostWebhooks06.
/**
* Post /public/webhooks without authentication and with redirect_uri.
*
* @throws Exception an error has occurred
*/
@SuppressWarnings("unchecked")
@Test
public void testPostWebhooks06() 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-webhooks04.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", headers.get("Location"));
}
}
use of com.formkiq.lambda.apigateway.ApiGatewayRequestEvent in project formkiq-core by formkiq.
the class ApiPublicWebhooksRequestTest method testPostWebhooks04.
/**
* Post /public/webhooks to expired webhook.
*
* @throws Exception an error has occurred
*/
@SuppressWarnings("unchecked")
@Test
public void testPostWebhooks04() throws Exception {
// given
createApiRequestHandler(getMap());
for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
String name = UUID.randomUUID().toString();
ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC).plusSeconds(Long.parseLong("-1000"));
Date ttl = Date.from(now.toInstant());
String id = getAwsServices().webhookService().saveWebhook(siteId, name, "joe", ttl, "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, "400.0");
}
}
use of com.formkiq.lambda.apigateway.ApiGatewayRequestEvent in project formkiq-core by formkiq.
the class ApiPublicWebhooksRequestTest method testPostWebhooks08.
/**
* Post /public/webhooks without authentication and with redirect_uri and responseFields.
*
* @throws Exception an error has occurred
*/
@SuppressWarnings("unchecked")
@Test
public void testPostWebhooks08() 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-webhooks06.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?fname=John&lname=Doe&kdhfsd=null", headers.get("Location"));
}
}
use of com.formkiq.lambda.apigateway.ApiGatewayRequestEvent in project formkiq-core by formkiq.
the class ApiPublicWebhooksRequestTest method testPostWebhooks02.
/**
* Post /public/webhooks without authentication BASE 64 ENCODED.
*
* @throws Exception an error has occurred
*/
@SuppressWarnings("unchecked")
@Test
public void testPostWebhooks02() 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-webhooks02.json", siteId, id);
// when
String response = handleRequest(event);
// then
Map<String, String> m = fromJson(response, Map.class);
verifyHeaders(m, "200.0");
String documentId = verifyDocumentId(m);
// verify s3 file
verifyS3File(id, siteId, documentId, name, "application/json", false);
}
}
use of com.formkiq.lambda.apigateway.ApiGatewayRequestEvent in project formkiq-core by formkiq.
the class ApiPublicWebhooksRequestTest method testPostWebhooks09.
/**
* Post /public/webhooks without authentication and with redirect_uri and responseFields.
* Content-Type: application/json
*
* @throws Exception an error has occurred
*/
@SuppressWarnings("unchecked")
@Test
public void testPostWebhooks09() 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-webhooks06.json", siteId, id);
HashMap<String, String> headers = new HashMap<>(event.getHeaders());
headers.put("Content-Type", "application/json");
event.setHeaders(headers);
event.setBody("{\"name\":\"john smith\"}");
event.setIsBase64Encoded(Boolean.FALSE);
// 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")));
assertEquals("https://www.google.ca", ((Map<String, Object>) m.get("headers")).get("Location"));
}
}
Aggregations