mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(apigateway): API key import/usage-plan fidelity and update-operation fixes (#2631)
* feat(apigateway): complete the REST API resource lifecycle
Adds the missing delete and update operations across authorizers,
integrations, integration responses, methods, method responses, models,
request validators, resources, rest APIs, stages, deployments, domain names
and base path mappings, plus tag/untag, usage plan and usage plan key CRUD,
and ImportApiKeys backed by a new ApiKeyCsvParser.
Each operation has a wire-level integration test.
* feat(apigatewayv2): allow clearing an HTTP API CORS configuration
deleteCorsConfiguration unsets the optional CORS block on a stored API so
the response omits it rather than echoing a stale configuration.
* fix(apigateway): accept the AWS-native ImportApiKeys CSV format
The header validator required exactly `name,value,enabled` in lowercase and
read every row by fixed position. Real AWS ships `Name,Key,Description,
Enabled,UsagePlanIds`, so the CLI, SDKs and Terraform all took a 400 on their
first call. Columns are now resolved case-insensitively by name into an index
map, `value` is kept as an alias for `Key`, a missing or blank `Enabled`
defaults to true as AWS does, and rows shorter than the header no longer throw.
Imported keys are also created with generateDistinctId, because the CSV `Key`
column is the key VALUE and AWS generates the id separately — reusing the value
as the id let one row silently clobber an existing key and detach its usage
plan associations.
ImportApiKeys now reports warnings for real: a row whose key value duplicates an
earlier row in the same import raises one, and `failonwarnings=true` turns those
warnings into a BadRequestException instead of being ignored.
* fix(apigateway): honour the patchOperations envelope on UpdateModel and UpdateUsagePlan
Both handlers parsed the PATCH body as a flat map. Real AWS sends
`{"patchOperations":[{"op":"replace","path":"/description","value":"x"}]}`, so
the flat parse succeeded, matched nothing, and returned the untouched resource
with a 200 — a silent no-op. Both now walk the ops list the way the six sibling
endpoints in this controller already do.
UpdateModel supports /description, /schema and /contentType, and rejects /name
with a BadRequestException: AWS treats a model name as an immutable identifier.
That also removes the delete-then-put rename, which had no existence check on
the target key and so destroyed any model already using the new name.
UpdateUsagePlan supports /name, /description and add/remove of /apiStages as
"apiId:stage", covering what the flat handler could do. UsagePlan carries no
throttle or quota state, so those paths are left unsupported rather than faked.
UpdateAuthorizer now parses /authorizerResultTtlInSeconds before mutating
anything. A non-numeric value used to be written straight to the store, after
which serialisation threw on the PATCH and on every later GetAuthorizer and
GetAuthorizers for that resource — unrecoverable short of delete and recreate.
* fix(apigateway): reject duplicate sibling paths and bad parentId on resources
UpdateResource pointed at an unknown /parentId surfaced getResource's 404
"Invalid resource id specified", which reads as though the resource being
patched is missing; the `parent == null` guard beneath it was unreachable for
the same reason. AWS answers 400, so the lookup failure is now rethrown as a
BadRequestException naming the offending value.
Neither CreateResource nor UpdateResource checked for a sibling collision, so
two children of one parent could end up with the same path and request routing
became order-dependent. Both now go through a shared guard that raises
ConflictException (409) when another child of the effective parent already uses
that pathPart.
UpdateResource also stopped mutating as it goes. The store hands back live
objects, so applying ops in-place meant a later rejected op left the earlier
ones visible in memory; the patch is now resolved into pending parentId and
pathPart values, validated, and only then applied.
* style(apigateway): put HttpHeaders first in deleteAuthorizer
Every other handler in the controller takes @Context HttpHeaders as its first
parameter. No behaviour change.
* fix(apigateway): answer BadRequestException for a malformed patchOperations envelope
The PATCH handlers parsed the envelope with convertValue(node, List.class)
inside a catch that only covered IOException. convertValue throws
IllegalArgumentException, which no mapper handles, so a non-array
patchOperations returned 500 instead of the modelled BadRequestException.
The raw List.class conversion also deferred a structured operation value
into the service layer as a ClassCastException, a second 500.
Extract one parsePatchOperations helper that converts through a
TypeReference<List<Map<String, String>>> and widens the catch, so scalar
values coerce and structured ones are rejected at the boundary.
* fix(apigateway): dispatch ImportApiKeys on mode, not on media type
ImportApiKeys was annotated @Consumes("text/csv"), but botocore sends the
operation with no Content-Type header at all — only Accept: application/json.
A request with no Content-Type is application/octet-stream to JAX-RS, so it
never matched, and fell through to the sibling CreateApiKey handler, which
fed the CSV body to the JSON parser and answered a spurious
BadRequestException. Every existing test hid this by setting text/csv
explicitly, a header no client sends.
Fold both operations into one POST /apikeys handler that consumes any media
type and tells them apart by the mode query parameter, the way AWS does, and
cover it with a raw-client case that sends no Content-Type.
* docs(apigateway): document the operations this branch added
The branch added 13 v1 management operations and DeleteCorsConfiguration on
v2 without touching docs, and the Not Implemented list still named
UpdateAuthorizer, DeleteAuthorizer, ImportApiKeys, GetUsagePlan,
UpdateUsagePlan and UpdateModel as absent. GetDeployment and DeleteDeployment
were already implemented but had never been listed either.
api-gateway.md is hand-maintained — ApiGatewayController is a REST controller
and is not registered in tools/docs/services.yaml — so the tables are updated
by hand and the index counts follow the tables: v1 64 -> 79, v2 48 -> 49.
Also record how CreateApiKey and ImportApiKeys share POST /apikeys.
* fix(apigateway): extend the patchOperations boundary parse to the inherited handlers
Six PATCH handlers predate this branch and still parsed the envelope with
convertValue(node, List.class) inside an IOException-only catch, so
updateRestApi, updateResource, updateMethod, updateIntegration, updateStage
and updateApiKey kept answering 500 for a malformed envelope while the eight
handlers this branch added answered 400. A reviewer would rightly ask why
only some of the surface agrees with AWS.
This is a deliberate scope extension beyond the audit's finding: point all
six at the existing parsePatchOperations helper so every PATCH operation on
the service shares one boundary contract. updateAccount stays as it is — it
validates each operation itself and already raises a modelled 400.
* docs(apigatewayv2): correct the VPC Link operations, which are implemented
The v2 Not Implemented list named all five VPC Link operations as absent, but
CreateVpcLink, GetVpcLink, GetVpcLinks and DeleteVpcLink have been routed on
/v2/vpclinks and backed by ApiGatewayV2Service since before this branch. Only
UpdateVpcLink is genuinely missing — there is no PATCH route for it.
Verified each claimed route against ApiGatewayController before editing. Adds
the VPC Links row the v2 table never had and carries the four operations into
the index count: 49 -> 53.
* fix(apigateway): enforce the modelled op enum on patchOperations
Botocore models PatchOperation.op as an enum of add, remove, replace,
move, copy and test. The boundary parse read the envelope's shape but
never the op value, and the handlers behind it disagree about what to do
with an unrecognised one: UpdateModel throws, UpdateApiKey and UpdateStage
skip it. On the skipping handlers an unmodelled op was answered 200 with
the resource untouched, which reads to the caller as an applied patch.
Check op against the enum in parsePatchOperations, the boundary this
branch already made responsible for the envelope on every PATCH handler.
The set is the model's, not the intersection of what the handlers
implement: whether a handler supports move is its own business, but a
value outside the enum should never reach one.
* fix(apigateway): reject a null element in the patchOperations envelope
parsePatchOperations silently skipped a null element in the patchOperations
array instead of rejecting it. Several handlers that predate the shared
boundary parse (updateRestApi, updateStage, updateApiKey, updateMethod) have
no null guard of their own and call op.get("op") directly, so a null element
reached them as an unhandled NullPointerException -- a 500 instead of AWS's
modelled BadRequestException.
Reject the null at the boundary all handlers already share, the same place
that already validates the op enum.
* fix(apigateway): apply patchOperations atomically instead of partially
updateAuthorizer, updateUsagePlan, updateRequestValidator, updateModel,
updateDomainName and updateBasePathMapping mutated the live stored object as
each op was validated. The store hands back live objects (no defensive
copy), so a valid op followed by an invalid one left the valid op's change
visible even though the request answered 400 -- the same partial-apply bug
already fixed for updateResource in an earlier commit on this branch, which
established the fix: resolve every op into pending local values, validate
the whole list, and only mutate the stored object once the patch is known
to be entirely good.
Each handler also now rejects a null patchOperations element explicitly, on
top of the shared boundary's own rejection, matching the defensive style
already used by updateRequestValidator and updateModel before this change.
* fix(apigateway): translate a malformed ImportApiKeys CSV into BadRequestException
ApiKeyCsvParser.parse throws IllegalArgumentException on an unterminated
quoted field, but only AwsException is registered with an ExceptionMapper.
The unmapped exception escaped as a 500 instead of AWS's modelled 400,
letting a malformed import request past the error boundary entirely.
Catch the parser's IllegalArgumentException at the one call site and
translate it into the same BadRequestException every other CSV validation
failure in this method already raises.
* style(apigateway): brace the new conditionals this branch added
New single-line if statements in the domain-name serialization, CSV import
column/cell handling, and resource sibling-collision check violated the
repository's mandatory conditional-brace convention. No behaviour change.
* fix(apigateway): validate all UpdateIntegration patch ops before applying any
updateIntegration mutated the live stored integration inside the same loop that validated later operations, so a PATCH with a valid op followed by an unsupported path left the earlier op applied even though the request as a whole was rejected with 400.
This commit is contained in:
1 parent
75f8f42d5f
commit
9b9e7f56a2
37 files changed
+3232
-84
No files matched your search
+8
@@ -234,4 +234,12 @@ class ApiGatewayApiKeyIntegrationTest {
|
||||
.body("id", equalTo(keyId))
|
||||
.body("value", not(equalTo(keyId)));
|
||||
}
|
||||
@Test @Order(15)
|
||||
void getDeletedApiKeyNotFound() {
|
||||
given()
|
||||
.when().get("/apikeys/" + apiKeyId)
|
||||
.then()
|
||||
.statusCode(404)
|
||||
.body("__type", equalTo("NotFoundException"));
|
||||
}
|
||||
}
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
package io.github.hectorvent.floci.services.apigateway;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasItem;
|
||||
|
||||
@QuarkusTest
|
||||
class ApiGatewayDeleteAuthorizerIntegrationTest {
|
||||
|
||||
@Test
|
||||
void testDeleteAuthorizerFlow() {
|
||||
String apiId = given()
|
||||
.contentType("application/json")
|
||||
.body("{\"name\":\"delete-authorizer-api\"}")
|
||||
.when()
|
||||
.post("/restapis")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.extract()
|
||||
.path("id");
|
||||
|
||||
String authorizerId = given()
|
||||
.contentType("application/json")
|
||||
.body("{\"name\":\"to-delete\",\"type\":\"TOKEN\",\"authorizerUri\":\"arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/arn:aws:lambda:us-east-1:000000000000:function:any/invocations\"}")
|
||||
.when()
|
||||
.post("/restapis/" + apiId + "/authorizers")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.extract()
|
||||
.path("id");
|
||||
|
||||
given()
|
||||
.when()
|
||||
.get("/restapis/" + apiId + "/authorizers/" + authorizerId)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("id", equalTo(authorizerId))
|
||||
.body("name", equalTo("to-delete"));
|
||||
|
||||
given()
|
||||
.when()
|
||||
.get("/restapis/" + apiId + "/authorizers")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("item.id", hasItem(authorizerId));
|
||||
|
||||
given()
|
||||
.when()
|
||||
.delete("/restapis/" + apiId + "/authorizers/" + authorizerId)
|
||||
.then()
|
||||
.statusCode(202);
|
||||
|
||||
given()
|
||||
.when()
|
||||
.get("/restapis/" + apiId + "/authorizers/" + authorizerId)
|
||||
.then()
|
||||
.statusCode(404)
|
||||
.body("__type", equalTo("NotFoundException"));
|
||||
}
|
||||
}
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
package io.github.hectorvent.floci.services.apigateway;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
@QuarkusTest
|
||||
public class ApiGatewayDeleteIntegrationIntegrationTest {
|
||||
|
||||
@Test
|
||||
public void testDeleteIntegration() {
|
||||
String apiId = given()
|
||||
.contentType("application/json")
|
||||
.body("{\"name\":\"delete-integration-api\"}")
|
||||
.when()
|
||||
.post("/restapis")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.extract()
|
||||
.path("id");
|
||||
|
||||
String rootId = given()
|
||||
.pathParam("apiId", apiId)
|
||||
.when()
|
||||
.get("/restapis/{apiId}/resources")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.extract()
|
||||
.path("item[0].id");
|
||||
|
||||
String resourceId = given()
|
||||
.pathParam("apiId", apiId)
|
||||
.pathParam("parentId", rootId)
|
||||
.contentType("application/json")
|
||||
.body("{\"pathPart\":\"work\"}")
|
||||
.when()
|
||||
.post("/restapis/{apiId}/resources/{parentId}")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.extract()
|
||||
.path("id");
|
||||
|
||||
given()
|
||||
.pathParam("apiId", apiId)
|
||||
.pathParam("resourceId", resourceId)
|
||||
.contentType("application/json")
|
||||
.body("{\"authorizationType\":\"NONE\"}")
|
||||
.when()
|
||||
.put("/restapis/{apiId}/resources/{resourceId}/methods/GET")
|
||||
.then()
|
||||
.statusCode(201);
|
||||
|
||||
given()
|
||||
.pathParam("apiId", apiId)
|
||||
.pathParam("resourceId", resourceId)
|
||||
.contentType("application/json")
|
||||
.body("{\"type\":\"MOCK\"}")
|
||||
.when()
|
||||
.put("/restapis/{apiId}/resources/{resourceId}/methods/GET/integration")
|
||||
.then()
|
||||
.statusCode(201);
|
||||
|
||||
given()
|
||||
.pathParam("apiId", apiId)
|
||||
.pathParam("resourceId", resourceId)
|
||||
.when()
|
||||
.delete("/restapis/{apiId}/resources/{resourceId}/methods/GET/integration")
|
||||
.then()
|
||||
.statusCode(204);
|
||||
|
||||
given()
|
||||
.pathParam("apiId", apiId)
|
||||
.pathParam("resourceId", resourceId)
|
||||
.when()
|
||||
.get("/restapis/{apiId}/resources/{resourceId}/methods/GET/integration")
|
||||
.then()
|
||||
.statusCode(404)
|
||||
.body("__type", equalTo("NotFoundException"));
|
||||
}
|
||||
}
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
package io.github.hectorvent.floci.services.apigateway;
|
||||
|
||||
import io.quarkus.test.common.http.TestHTTPEndpoint;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.http.ContentType;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
@QuarkusTest
|
||||
@TestHTTPEndpoint(ApiGatewayController.class)
|
||||
class ApiGatewayDeleteIntegrationResponseIntegrationTest {
|
||||
|
||||
@Test
|
||||
void testDeleteIntegrationResponse() {
|
||||
String apiId = given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("{\"name\":\"delete-integration-response-api\"}")
|
||||
.when()
|
||||
.post("/restapis")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.extract()
|
||||
.path("id");
|
||||
|
||||
String resourceId = given()
|
||||
.when()
|
||||
.get("/restapis/" + apiId + "/resources")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.extract()
|
||||
.path("item[0].id");
|
||||
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("{\"authorizationType\":\"NONE\"}")
|
||||
.when()
|
||||
.put("/restapis/" + apiId + "/resources/" + resourceId + "/methods/GET")
|
||||
.then()
|
||||
.statusCode(201);
|
||||
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("{\"type\":\"MOCK\"}")
|
||||
.when()
|
||||
.put("/restapis/" + apiId + "/resources/" + resourceId + "/methods/GET/integration")
|
||||
.then()
|
||||
.statusCode(201);
|
||||
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("{\"selectionPattern\":\"before\"}")
|
||||
.when()
|
||||
.put("/restapis/" + apiId + "/resources/" + resourceId + "/methods/GET/integration/responses/200")
|
||||
.then()
|
||||
.statusCode(201);
|
||||
|
||||
given()
|
||||
.when()
|
||||
.delete("/restapis/" + apiId + "/resources/" + resourceId + "/methods/GET/integration/responses/200")
|
||||
.then()
|
||||
.statusCode(204);
|
||||
|
||||
given()
|
||||
.when()
|
||||
.get("/restapis/" + apiId + "/resources/" + resourceId + "/methods/GET/integration/responses/200")
|
||||
.then()
|
||||
.statusCode(404)
|
||||
.body("__type", equalTo("NotFoundException"));
|
||||
}
|
||||
}
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
package io.github.hectorvent.floci.services.apigateway;
|
||||
|
||||
import io.quarkus.test.common.http.TestHTTPEndpoint;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static io.restassured.http.ContentType.JSON;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
@QuarkusTest
|
||||
@TestHTTPEndpoint(ApiGatewayController.class)
|
||||
class ApiGatewayDeleteMethodIntegrationTest {
|
||||
|
||||
@Test
|
||||
void testDeleteMethodWorkflow() {
|
||||
String apiId = given()
|
||||
.contentType(JSON)
|
||||
.body("{\"name\":\"delete-method-api\"}")
|
||||
.when()
|
||||
.post("/restapis")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.extract()
|
||||
.path("id");
|
||||
|
||||
String resourceId = given()
|
||||
.pathParam("apiId", apiId)
|
||||
.when()
|
||||
.get("/restapis/{apiId}/resources")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.extract()
|
||||
.path("item[0].id");
|
||||
|
||||
given()
|
||||
.contentType(JSON)
|
||||
.body("{\"authorizationType\":\"NONE\"}")
|
||||
.when()
|
||||
.put("/restapis/{apiId}/resources/{resourceId}/methods/GET", apiId, resourceId)
|
||||
.then()
|
||||
.statusCode(201);
|
||||
|
||||
given()
|
||||
.when()
|
||||
.delete("/restapis/{apiId}/resources/{resourceId}/methods/GET", apiId, resourceId)
|
||||
.then()
|
||||
.statusCode(202);
|
||||
|
||||
given()
|
||||
.when()
|
||||
.get("/restapis/{apiId}/resources/{resourceId}/methods/GET", apiId, resourceId)
|
||||
.then()
|
||||
.statusCode(404)
|
||||
.body("__type", equalTo("NotFoundException"));
|
||||
}
|
||||
}
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
package io.github.hectorvent.floci.services.apigateway;
|
||||
|
||||
import io.quarkus.test.common.http.TestHTTPEndpoint;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.http.ContentType;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
@QuarkusTest
|
||||
@TestHTTPEndpoint(ApiGatewayController.class)
|
||||
class ApiGatewayDeleteMethodResponseIntegrationTest {
|
||||
|
||||
@Test
|
||||
void testDeleteMethodResponse() {
|
||||
String apiId = given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("{\"name\":\"delete-method-response-api\"}")
|
||||
.when()
|
||||
.post("/restapis")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.extract()
|
||||
.path("id");
|
||||
|
||||
String resourceId = given()
|
||||
.when()
|
||||
.get("/restapis/{apiId}/resources", apiId)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.extract()
|
||||
.path("item[0].id");
|
||||
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("{\"authorizationType\":\"NONE\"}")
|
||||
.when()
|
||||
.put("/restapis/{apiId}/resources/{resourceId}/methods/GET", apiId, resourceId)
|
||||
.then()
|
||||
.statusCode(201);
|
||||
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("{}")
|
||||
.when()
|
||||
.put("/restapis/{apiId}/resources/{resourceId}/methods/GET/responses/200", apiId, resourceId)
|
||||
.then()
|
||||
.statusCode(201);
|
||||
|
||||
given()
|
||||
.when()
|
||||
.delete("/restapis/{apiId}/resources/{resourceId}/methods/GET/responses/200", apiId, resourceId)
|
||||
.then()
|
||||
.statusCode(204);
|
||||
|
||||
given()
|
||||
.when()
|
||||
.get("/restapis/{apiId}/resources/{resourceId}/methods/GET/responses/200", apiId, resourceId)
|
||||
.then()
|
||||
.statusCode(404)
|
||||
.body("__type", equalTo("NotFoundException"));
|
||||
}
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
package io.github.hectorvent.floci.services.apigateway;
|
||||
|
||||
import io.quarkus.test.common.http.TestHTTPEndpoint;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.http.ContentType;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
@QuarkusTest
|
||||
@TestHTTPEndpoint(ApiGatewayController.class)
|
||||
class ApiGatewayDeleteModelIntegrationTest {
|
||||
|
||||
@Test
|
||||
void testDeleteModelFlow() {
|
||||
String apiId = given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("{\"name\":\"delete-model-api\"}")
|
||||
.when()
|
||||
.post("/restapis")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.extract()
|
||||
.path("id");
|
||||
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("{\"name\":\"DeleteMe\",\"schema\":\"{}\"}")
|
||||
.when()
|
||||
.post("/restapis/" + apiId + "/models")
|
||||
.then()
|
||||
.statusCode(201);
|
||||
|
||||
given()
|
||||
.when()
|
||||
.delete("/restapis/" + apiId + "/models/DeleteMe")
|
||||
.then()
|
||||
.statusCode(202);
|
||||
|
||||
given()
|
||||
.when()
|
||||
.get("/restapis/" + apiId + "/models/DeleteMe")
|
||||
.then()
|
||||
.statusCode(404)
|
||||
.body("__type", equalTo("NotFoundException"));
|
||||
}
|
||||
}
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
package io.github.hectorvent.floci.services.apigateway;
|
||||
|
||||
import io.quarkus.test.common.http.TestHTTPEndpoint;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.http.ContentType;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
@QuarkusTest
|
||||
@TestHTTPEndpoint(ApiGatewayController.class)
|
||||
class ApiGatewayDeleteRequestValidatorIntegrationTest {
|
||||
|
||||
@Test
|
||||
void testDeleteRequestValidator() {
|
||||
String apiId = given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("{\"name\":\"validator-delete-api\"}")
|
||||
.when()
|
||||
.post("/restapis")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.extract()
|
||||
.path("id");
|
||||
|
||||
String validatorId = given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("{\"name\":\"DeleteValidator\",\"validateRequestBody\":true,\"validateRequestParameters\":false}")
|
||||
.when()
|
||||
.post("/restapis/" + apiId + "/requestvalidators")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.extract()
|
||||
.path("id");
|
||||
|
||||
given()
|
||||
.when()
|
||||
.delete("/restapis/" + apiId + "/requestvalidators/" + validatorId)
|
||||
.then()
|
||||
.statusCode(202);
|
||||
|
||||
given()
|
||||
.when()
|
||||
.get("/restapis/" + apiId + "/requestvalidators/" + validatorId)
|
||||
.then()
|
||||
.statusCode(404)
|
||||
.body("__type", equalTo("NotFoundException"));
|
||||
}
|
||||
}
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
package io.github.hectorvent.floci.services.apigateway;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
@QuarkusTest
|
||||
class ApiGatewayDeleteResourceIntegrationTest {
|
||||
|
||||
@Test
|
||||
void testDeleteResource() {
|
||||
String apiId = given()
|
||||
.contentType("application/json")
|
||||
.body("{\"name\":\"delete-resource-api\"}")
|
||||
.when()
|
||||
.post("/restapis")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.extract()
|
||||
.path("id");
|
||||
|
||||
String rootId = given()
|
||||
.when()
|
||||
.get("/restapis/{apiId}/resources", apiId)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.extract()
|
||||
.path("item[0].id");
|
||||
|
||||
String resourceId = given()
|
||||
.contentType("application/json")
|
||||
.pathParam("apiId", apiId)
|
||||
.pathParam("parentId", rootId)
|
||||
.body("{\"pathPart\":\"gone\"}")
|
||||
.when()
|
||||
.post("/restapis/{apiId}/resources/{parentId}")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.extract()
|
||||
.path("id");
|
||||
|
||||
given()
|
||||
.pathParam("apiId", apiId)
|
||||
.pathParam("resourceId", resourceId)
|
||||
.when()
|
||||
.delete("/restapis/{apiId}/resources/{resourceId}")
|
||||
.then()
|
||||
.statusCode(202);
|
||||
|
||||
given()
|
||||
.pathParam("apiId", apiId)
|
||||
.pathParam("resourceId", resourceId)
|
||||
.when()
|
||||
.get("/restapis/{apiId}/resources/{resourceId}")
|
||||
.then()
|
||||
.statusCode(404)
|
||||
.body("__type", equalTo("NotFoundException"));
|
||||
}
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
package io.github.hectorvent.floci.services.apigateway;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
@QuarkusTest
|
||||
class ApiGatewayGetTagsIntegrationTest {
|
||||
|
||||
@Test
|
||||
void testGetTags() {
|
||||
String apiId = given()
|
||||
.contentType("application/json")
|
||||
.body("{\"name\":\"get-tags-api\"}")
|
||||
.when()
|
||||
.post("/restapis")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.extract()
|
||||
.path("id");
|
||||
|
||||
String resourceArn = "arn:aws:apigateway:us-east-1::/restapis/" + apiId;
|
||||
|
||||
given()
|
||||
.pathParam("resourceArn", resourceArn)
|
||||
.contentType("application/json")
|
||||
.body("{\"tags\":{\"owner\":\"network\"}}")
|
||||
.when()
|
||||
.put("/tags/{resourceArn}")
|
||||
.then()
|
||||
.statusCode(204);
|
||||
|
||||
given()
|
||||
.pathParam("resourceArn", resourceArn)
|
||||
.when()
|
||||
.get("/tags/{resourceArn}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("tags.owner", equalTo("network"));
|
||||
}
|
||||
}
|
||||
+190
@@ -0,0 +1,190 @@
|
||||
package io.github.hectorvent.floci.services.apigateway;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.RestAssured;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
@QuarkusTest
|
||||
class ApiGatewayImportApiKeysIntegrationTest {
|
||||
|
||||
/**
|
||||
* Botocore sends ImportApiKeys with no Content-Type header at all — only {@code Accept:
|
||||
* application/json} — so the handler has to be reachable without one. RestAssured stamps a
|
||||
* default Content-Type on any request carrying a body, so this case uses a raw client.
|
||||
*/
|
||||
@Test
|
||||
void testImportApiKeysWithoutContentTypeHeader() throws Exception {
|
||||
HttpResponse<String> response = HttpClient.newHttpClient().send(
|
||||
HttpRequest.newBuilder()
|
||||
.uri(URI.create("http://localhost:" + RestAssured.port
|
||||
+ "/apikeys?mode=import&format=csv&failonwarnings=false"))
|
||||
.header("Accept", "application/json")
|
||||
.POST(HttpRequest.BodyPublishers.ofString("Name,Key\nno-content-type-key,no-content-type-secret\n"))
|
||||
.build(),
|
||||
HttpResponse.BodyHandlers.ofString());
|
||||
|
||||
assertEquals(201, response.statusCode(), "ImportApiKeys must dispatch without a Content-Type: " + response.body());
|
||||
assertTrue(response.body().contains("\"ids\""), response.body());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testImportApiKeys() {
|
||||
String importedId = given()
|
||||
.contentType("text/csv")
|
||||
.body("name,value,enabled\nimported-key,secret-value,true\n")
|
||||
.when()
|
||||
.post("/apikeys?mode=import&format=csv&failonwarnings=false")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.body("ids", hasSize(1))
|
||||
.extract().path("ids[0]");
|
||||
|
||||
given()
|
||||
.pathParam("importedId", importedId)
|
||||
.when()
|
||||
.get("/apikeys/{importedId}?includeValue=true")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("name", org.hamcrest.Matchers.equalTo("imported-key"))
|
||||
.body("value", org.hamcrest.Matchers.equalTo("secret-value"))
|
||||
.body("enabled", org.hamcrest.Matchers.equalTo(true));
|
||||
}
|
||||
|
||||
/** AWS ImportApiKeys uses the TitleCase header {@code Name,Key,Description,Enabled,UsagePlanIds}. */
|
||||
@Test
|
||||
void testImportApiKeysAcceptsAwsNativeHeader() {
|
||||
String importedId = given()
|
||||
.contentType("text/csv")
|
||||
.body("Name,Key,Description,Enabled,UsagePlanIds\n"
|
||||
+ "aws-format-key,aws-format-secret-value,a description,true,\n")
|
||||
.when()
|
||||
.post("/apikeys?mode=import&format=csv&failonwarnings=false")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.body("ids", hasSize(1))
|
||||
.extract().path("ids[0]");
|
||||
|
||||
given()
|
||||
.pathParam("importedId", importedId)
|
||||
.when()
|
||||
.get("/apikeys/{importedId}?includeValue=true")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("name", equalTo("aws-format-key"))
|
||||
.body("value", equalTo("aws-format-secret-value"))
|
||||
.body("description", equalTo("a description"))
|
||||
.body("enabled", equalTo(true));
|
||||
}
|
||||
|
||||
/** Columns are addressed by name, not by position, and a missing Enabled column defaults to true. */
|
||||
@Test
|
||||
void testImportApiKeysReadsColumnsByNameAndDefaultsEnabled() {
|
||||
String importedId = given()
|
||||
.contentType("text/csv")
|
||||
.body("Key,UsagePlanIds,Name\nreordered-secret,,reordered-key\n")
|
||||
.when()
|
||||
.post("/apikeys?mode=import&format=csv&failonwarnings=false")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.body("ids", hasSize(1))
|
||||
.extract().path("ids[0]");
|
||||
|
||||
given()
|
||||
.pathParam("importedId", importedId)
|
||||
.when()
|
||||
.get("/apikeys/{importedId}?includeValue=true")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("name", equalTo("reordered-key"))
|
||||
.body("value", equalTo("reordered-secret"))
|
||||
.body("enabled", equalTo(true));
|
||||
}
|
||||
|
||||
/** The CSV Key column is the key VALUE; AWS generates a distinct id, so it must not be reused as the id. */
|
||||
@Test
|
||||
void testImportedKeyIdIsDistinctFromKeyValue() {
|
||||
String importedId = given()
|
||||
.contentType("text/csv")
|
||||
.body("Name,Key\ndistinct-id-key,distinct-id-secret-value\n")
|
||||
.when()
|
||||
.post("/apikeys?mode=import&format=csv&failonwarnings=false")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.extract().path("ids[0]");
|
||||
|
||||
org.junit.jupiter.api.Assertions.assertNotEquals("distinct-id-secret-value", importedId);
|
||||
|
||||
given()
|
||||
.pathParam("importedId", importedId)
|
||||
.when()
|
||||
.get("/apikeys/{importedId}?includeValue=true")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("id", not(equalTo("distinct-id-secret-value")))
|
||||
.body("value", equalTo("distinct-id-secret-value"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDuplicateKeyValueEmitsWarning() {
|
||||
given()
|
||||
.contentType("text/csv")
|
||||
.body("Name,Key\nwarn-a,duplicate-secret\nwarn-b,duplicate-secret\n")
|
||||
.when()
|
||||
.post("/apikeys?mode=import&format=csv&failonwarnings=false")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.body("ids", hasSize(2))
|
||||
.body("warnings", hasSize(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDuplicateKeyValueFailsWhenFailOnWarnings() {
|
||||
given()
|
||||
.contentType("text/csv")
|
||||
.body("Name,Key\nfail-a,fail-duplicate-secret\nfail-b,fail-duplicate-secret\n")
|
||||
.when()
|
||||
.post("/apikeys?mode=import&format=csv&failonwarnings=true")
|
||||
.then()
|
||||
.statusCode(400);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testHeaderWithoutKeyColumnIsRejected() {
|
||||
given()
|
||||
.contentType("text/csv")
|
||||
.body("Name,Description\nno-key,nope\n")
|
||||
.when()
|
||||
.post("/apikeys?mode=import&format=csv&failonwarnings=false")
|
||||
.then()
|
||||
.statusCode(400);
|
||||
}
|
||||
|
||||
/**
|
||||
* A malformed CSV (unterminated quote) fails inside {@code ApiKeyCsvParser.parse} with an
|
||||
* {@code IllegalArgumentException}, which no exception mapper handles — only {@code AwsException}
|
||||
* is mapped. The request must still answer the modelled 400, not a 500 that escapes the AWS
|
||||
* error boundary.
|
||||
*/
|
||||
@Test
|
||||
void testMalformedCsvWithUnterminatedQuoteIsRejectedAsBadRequest() {
|
||||
given()
|
||||
.contentType("text/csv")
|
||||
.body("Name,Key\n\"unterminated,secret-value\n")
|
||||
.when()
|
||||
.post("/apikeys?mode=import&format=csv&failonwarnings=false")
|
||||
.then()
|
||||
.statusCode(400);
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -340,7 +340,7 @@ class ApiGatewayIntegrationTest {
|
||||
given()
|
||||
.when().delete("/restapis/" + apiId + "/deployments/" + deploymentId)
|
||||
.then()
|
||||
.statusCode(204);
|
||||
.statusCode(202);
|
||||
|
||||
given()
|
||||
.when().get("/restapis/" + apiId + "/deployments/" + deploymentId)
|
||||
@@ -354,7 +354,7 @@ class ApiGatewayIntegrationTest {
|
||||
given()
|
||||
.when().delete("/restapis/" + apiId + "/resources/" + resourceId)
|
||||
.then()
|
||||
.statusCode(204);
|
||||
.statusCode(202);
|
||||
}
|
||||
|
||||
@Test @Order(29)
|
||||
|
||||
+223
@@ -0,0 +1,223 @@
|
||||
package io.github.hectorvent.floci.services.apigateway;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.http.ContentType;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
/**
|
||||
* A malformed {@code patchOperations} envelope is a client error: AWS answers BadRequestException,
|
||||
* never a server fault. Each case below is a distinct shape that fails at a different point of the
|
||||
* shared boundary parse.
|
||||
*/
|
||||
@QuarkusTest
|
||||
class ApiGatewayPatchOperationsBoundaryIntegrationTest {
|
||||
|
||||
private String createApi(String name) {
|
||||
return given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("{\"name\":\"" + name + "\"}")
|
||||
.post("/restapis")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.extract()
|
||||
.path("id");
|
||||
}
|
||||
|
||||
private String createModel(String apiId, String modelName) {
|
||||
return given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("{\"name\":\"" + modelName + "\",\"description\":\"old\",\"contentType\":\"application/json\",\"schema\":\"{}\"}")
|
||||
.post("/restapis/" + apiId + "/models")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.extract()
|
||||
.path("name");
|
||||
}
|
||||
|
||||
private void patchModelExpecting(String bodyJson, int expectedStatus) {
|
||||
String apiId = createApi("patch-boundary-" + Integer.toHexString(bodyJson.hashCode()));
|
||||
String modelName = createModel(apiId, "BoundaryModel");
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body(bodyJson)
|
||||
.patch("/restapis/" + apiId + "/models/" + modelName)
|
||||
.then()
|
||||
.statusCode(expectedStatus);
|
||||
}
|
||||
|
||||
/** A scalar where an array belongs. */
|
||||
@Test
|
||||
void testPatchOperationsAsStringIsRejected() {
|
||||
patchModelExpecting("{\"patchOperations\":\"oops\"}", 400);
|
||||
}
|
||||
|
||||
/** A bare operation object rather than a one-element array. */
|
||||
@Test
|
||||
void testPatchOperationsAsObjectIsRejected() {
|
||||
patchModelExpecting("{\"patchOperations\":{\"op\":\"replace\",\"path\":\"/description\",\"value\":\"new\"}}", 400);
|
||||
}
|
||||
|
||||
/** A structured {@code value} cannot be a PatchOperation value, which AWS models as a string. */
|
||||
@Test
|
||||
void testStructuredPatchValueIsRejected() {
|
||||
patchModelExpecting("{\"patchOperations\":[{\"op\":\"replace\",\"path\":\"/description\",\"value\":{\"nested\":1}}]}", 400);
|
||||
}
|
||||
|
||||
/** Body that is not JSON at all still fails at the boundary, not in the service. */
|
||||
@Test
|
||||
void testNonJsonBodyIsRejected() {
|
||||
patchModelExpecting("not json at all", 400);
|
||||
}
|
||||
|
||||
/** A JSON scalar is coerced to the string PatchOperation values are modelled as. */
|
||||
@Test
|
||||
void testNumericPatchValueIsCoercedToString() {
|
||||
String apiId = createApi("patch-boundary-numeric");
|
||||
String modelName = createModel(apiId, "NumericModel");
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("{\"patchOperations\":[{\"op\":\"replace\",\"path\":\"/description\",\"value\":5}]}")
|
||||
.patch("/restapis/" + apiId + "/models/" + modelName)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("description", equalTo("5"));
|
||||
}
|
||||
|
||||
/** UpdateRestApi predates this branch and shares the same boundary parse. */
|
||||
@Test
|
||||
void testMalformedEnvelopeOnRestApiIsRejected() {
|
||||
String apiId = createApi("patch-boundary-restapi");
|
||||
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("{\"patchOperations\":\"oops\"}")
|
||||
.patch("/restapis/" + apiId)
|
||||
.then()
|
||||
.statusCode(400);
|
||||
}
|
||||
|
||||
/** UpdateApiKey likewise, including the structured-value shape that used to reach the service. */
|
||||
@Test
|
||||
void testStructuredPatchValueOnApiKeyIsRejected() {
|
||||
String keyId = given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("{\"name\":\"patch-boundary-key\",\"enabled\":true}")
|
||||
.post("/apikeys")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.extract()
|
||||
.path("id");
|
||||
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("{\"patchOperations\":[{\"op\":\"replace\",\"path\":\"/description\",\"value\":{\"nested\":1}}]}")
|
||||
.patch("/apikeys/" + keyId)
|
||||
.then()
|
||||
.statusCode(400);
|
||||
}
|
||||
|
||||
/**
|
||||
* A {@code null} element inside the patchOperations array must be rejected at the boundary. Every
|
||||
* downstream handler assumes each element is a map and calls {@code .get("op")} on it directly, so
|
||||
* letting a null through turns a client error into a 500 instead of the modelled 400.
|
||||
*/
|
||||
@Test
|
||||
void testNullElementInPatchOperationsArrayIsRejected() {
|
||||
patchModelExpecting("{\"patchOperations\":[null]}", 400);
|
||||
}
|
||||
|
||||
/**
|
||||
* UpdateRestApi has no per-handler null guard of its own, unlike some of the newer handlers — this
|
||||
* is the case that would 500 (NPE on {@code op.get("op")}) without the shared boundary rejecting
|
||||
* the null element before it ever reaches the service layer.
|
||||
*/
|
||||
@Test
|
||||
void testNullElementInPatchOperationsArrayIsRejectedOnRestApi() {
|
||||
String apiId = createApi("patch-boundary-restapi-null-op");
|
||||
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("{\"patchOperations\":[null]}")
|
||||
.patch("/restapis/" + apiId)
|
||||
.then()
|
||||
.statusCode(400);
|
||||
}
|
||||
|
||||
/** The same boundary contract holds on a second handler, proving the parse is shared. */
|
||||
@Test
|
||||
void testMalformedEnvelopeOnRequestValidatorIsRejected() {
|
||||
String apiId = createApi("patch-boundary-validator");
|
||||
String validatorId = given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("{\"name\":\"before\",\"validateRequestBody\":false,\"validateRequestParameters\":true}")
|
||||
.post("/restapis/" + apiId + "/requestvalidators")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.extract()
|
||||
.path("id");
|
||||
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("{\"patchOperations\":\"oops\"}")
|
||||
.patch("/restapis/" + apiId + "/requestvalidators/" + validatorId)
|
||||
.then()
|
||||
.statusCode(400);
|
||||
}
|
||||
|
||||
// ── op (botocore: enum add|remove|replace|move|copy|test) ──
|
||||
|
||||
private String createApiKey(String name) {
|
||||
return given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("{\"name\":\"" + name + "\",\"enabled\":true}")
|
||||
.post("/apikeys")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.extract()
|
||||
.path("id");
|
||||
}
|
||||
|
||||
/**
|
||||
* UpdateApiKey skips any operation it does not recognise, so an unmodelled op used to answer
|
||||
* 200 with the resource untouched — success for a request AWS rejects outright.
|
||||
*/
|
||||
@Test
|
||||
void testUnmodelledOpOnApiKeyIsRejected() {
|
||||
String keyId = createApiKey("patch-boundary-op-enum");
|
||||
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("{\"patchOperations\":[{\"op\":\"frobnicate\",\"path\":\"/name\",\"value\":\"after\"}]}")
|
||||
.patch("/apikeys/" + keyId)
|
||||
.then()
|
||||
.statusCode(400);
|
||||
|
||||
given()
|
||||
.get("/apikeys/" + keyId)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("name", equalTo("patch-boundary-op-enum"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testUnmodelledOpOnModelIsRejected() {
|
||||
patchModelExpecting("{\"patchOperations\":[{\"op\":\"REPLACE\",\"path\":\"/description\",\"value\":\"new\"}]}", 400);
|
||||
}
|
||||
|
||||
/** A modelled op the handler does support must still go through. */
|
||||
@Test
|
||||
void testModelledOpOnApiKeyIsAccepted() {
|
||||
String keyId = createApiKey("patch-boundary-op-modelled");
|
||||
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("{\"patchOperations\":[{\"op\":\"replace\",\"path\":\"/name\",\"value\":\"after\"}]}")
|
||||
.patch("/apikeys/" + keyId)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("name", equalTo("after"));
|
||||
}
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
package io.github.hectorvent.floci.services.apigateway;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
@QuarkusTest
|
||||
class ApiGatewayTagResourceIntegrationTest {
|
||||
|
||||
@Test
|
||||
void testTagResource() {
|
||||
String apiId = given()
|
||||
.contentType("application/json")
|
||||
.body("{\"name\":\"taggable-api\"}")
|
||||
.when()
|
||||
.post("/restapis")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.extract().path("id");
|
||||
|
||||
String resourceArn = "arn:aws:apigateway:us-east-1::/restapis/" + apiId;
|
||||
|
||||
given()
|
||||
.pathParam("resourceArn", resourceArn)
|
||||
.contentType("application/json")
|
||||
.body("{\"tags\":{\"environment\":\"test\"}}")
|
||||
.when()
|
||||
.put("/tags/{resourceArn}")
|
||||
.then()
|
||||
.statusCode(204);
|
||||
|
||||
given()
|
||||
.pathParam("apiId", apiId)
|
||||
.when()
|
||||
.get("/restapis/{apiId}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("tags.environment", equalTo("test"));
|
||||
}
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
package io.github.hectorvent.floci.services.apigateway;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
|
||||
@QuarkusTest
|
||||
public class ApiGatewayUntagResourceIntegrationTest {
|
||||
|
||||
@Test
|
||||
public void testUntagResource() {
|
||||
String apiId = given()
|
||||
.contentType("application/json")
|
||||
.body("{\"name\":\"untaggable-api\"}")
|
||||
.when()
|
||||
.post("/restapis")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.extract().path("id");
|
||||
|
||||
String resourceArn = "arn:aws:apigateway:us-east-1::/restapis/" + apiId;
|
||||
|
||||
given()
|
||||
.pathParam("resourceArn", resourceArn)
|
||||
.contentType("application/json")
|
||||
.body("{\"tags\":{\"team\":\"platform\"}}")
|
||||
.when()
|
||||
.put("/tags/{resourceArn}")
|
||||
.then()
|
||||
.statusCode(204);
|
||||
|
||||
given()
|
||||
.pathParam("resourceArn", resourceArn)
|
||||
.queryParam("tagKeys", "team")
|
||||
.when()
|
||||
.delete("/tags/{resourceArn}")
|
||||
.then()
|
||||
.statusCode(204);
|
||||
|
||||
given()
|
||||
.pathParam("apiId", apiId)
|
||||
.when()
|
||||
.get("/restapis/{apiId}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("tags.team", nullValue());
|
||||
}
|
||||
}
|
||||
+213
@@ -0,0 +1,213 @@
|
||||
package io.github.hectorvent.floci.services.apigateway;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
@QuarkusTest
|
||||
class ApiGatewayUpdateAuthorizerIntegrationTest {
|
||||
|
||||
@Test
|
||||
void shouldUpdateAuthorizerAndPersistChanges() {
|
||||
// Step 1: Create API
|
||||
Map<String, Object> createApiBody = new HashMap<>();
|
||||
createApiBody.put("name", "update-authorizer-api");
|
||||
|
||||
String apiId = given()
|
||||
.contentType("application/json")
|
||||
.body(createApiBody)
|
||||
.when()
|
||||
.post("/restapis")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.extract()
|
||||
.path("id");
|
||||
|
||||
// Step 2: Create Authorizer
|
||||
Map<String, Object> createAuthorizerBody = new HashMap<>();
|
||||
createAuthorizerBody.put("name", "before-update");
|
||||
createAuthorizerBody.put("type", "TOKEN");
|
||||
createAuthorizerBody.put("authorizerUri", "arn:aws:lambda:us-east-1:123456789012:function:my-authorizer");
|
||||
createAuthorizerBody.put("identitySource", "method.request.header.Authorization");
|
||||
createAuthorizerBody.put("authorizerResultTtlInSeconds", 300);
|
||||
|
||||
String authorizerId = given()
|
||||
.contentType("application/json")
|
||||
.body(createAuthorizerBody)
|
||||
.when()
|
||||
.post("/restapis/" + apiId + "/authorizers")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.extract()
|
||||
.path("id");
|
||||
|
||||
// Step 3: Update Authorizer via PATCH
|
||||
Map<String, Object> patchOp1 = new HashMap<>();
|
||||
patchOp1.put("op", "replace");
|
||||
patchOp1.put("path", "/name");
|
||||
patchOp1.put("value", "after-update");
|
||||
|
||||
Map<String, Object> patchOp2 = new HashMap<>();
|
||||
patchOp2.put("op", "replace");
|
||||
patchOp2.put("path", "/identitySource");
|
||||
patchOp2.put("value", "method.request.header.X-Token");
|
||||
|
||||
Map<String, Object> patchBody = new HashMap<>();
|
||||
patchBody.put("patchOperations", new Object[]{patchOp1, patchOp2});
|
||||
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.body(patchBody)
|
||||
.when()
|
||||
.patch("/restapis/" + apiId + "/authorizers/" + authorizerId)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("id", equalTo(authorizerId))
|
||||
.body("name", equalTo("after-update"))
|
||||
.body("identitySource", equalTo("method.request.header.X-Token"));
|
||||
|
||||
// Step 4: GET Authorizer to verify persistence
|
||||
given()
|
||||
.when()
|
||||
.get("/restapis/" + apiId + "/authorizers/" + authorizerId)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("name", equalTo("after-update"))
|
||||
.body("identitySource", equalTo("method.request.header.X-Token"));
|
||||
}
|
||||
|
||||
/**
|
||||
* A non-numeric /authorizerResultTtlInSeconds must be rejected before any mutation, otherwise the
|
||||
* stored value can no longer be serialised and every later GET/ListAuthorizers fails permanently.
|
||||
*/
|
||||
@Test
|
||||
void shouldRejectNonNumericAuthorizerResultTtlAndLeaveAuthorizerReadable() {
|
||||
Map<String, Object> createApiBody = new HashMap<>();
|
||||
createApiBody.put("name", "ttl-validation-api");
|
||||
|
||||
String apiId = given()
|
||||
.contentType("application/json")
|
||||
.body(createApiBody)
|
||||
.when()
|
||||
.post("/restapis")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.extract()
|
||||
.path("id");
|
||||
|
||||
Map<String, Object> createAuthorizerBody = new HashMap<>();
|
||||
createAuthorizerBody.put("name", "ttl-authorizer");
|
||||
createAuthorizerBody.put("type", "TOKEN");
|
||||
createAuthorizerBody.put("authorizerUri", "arn:aws:lambda:us-east-1:123456789012:function:my-authorizer");
|
||||
createAuthorizerBody.put("identitySource", "method.request.header.Authorization");
|
||||
createAuthorizerBody.put("authorizerResultTtlInSeconds", 300);
|
||||
|
||||
String authorizerId = given()
|
||||
.contentType("application/json")
|
||||
.body(createAuthorizerBody)
|
||||
.when()
|
||||
.post("/restapis/" + apiId + "/authorizers")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.extract()
|
||||
.path("id");
|
||||
|
||||
Map<String, Object> badOp = new HashMap<>();
|
||||
badOp.put("op", "replace");
|
||||
badOp.put("path", "/authorizerResultTtlInSeconds");
|
||||
badOp.put("value", "not-a-number");
|
||||
|
||||
Map<String, Object> patchBody = new HashMap<>();
|
||||
patchBody.put("patchOperations", new Object[]{badOp});
|
||||
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.body(patchBody)
|
||||
.when()
|
||||
.patch("/restapis/" + apiId + "/authorizers/" + authorizerId)
|
||||
.then()
|
||||
.statusCode(400);
|
||||
|
||||
given()
|
||||
.when()
|
||||
.get("/restapis/" + apiId + "/authorizers/" + authorizerId)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("authorizerResultTtlInSeconds", equalTo(300));
|
||||
|
||||
given()
|
||||
.when()
|
||||
.get("/restapis/" + apiId + "/authorizers")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* A PATCH is all-or-nothing: a valid op followed by an invalid one must reject the whole request
|
||||
* without leaving the valid op's mutation visible.
|
||||
*/
|
||||
@Test
|
||||
void shouldRejectWholePatchAndLeaveNameUnchangedWhenALaterOpIsInvalid() {
|
||||
Map<String, Object> createApiBody = new HashMap<>();
|
||||
createApiBody.put("name", "partial-apply-api");
|
||||
|
||||
String apiId = given()
|
||||
.contentType("application/json")
|
||||
.body(createApiBody)
|
||||
.when()
|
||||
.post("/restapis")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.extract()
|
||||
.path("id");
|
||||
|
||||
Map<String, Object> createAuthorizerBody = new HashMap<>();
|
||||
createAuthorizerBody.put("name", "original-name");
|
||||
createAuthorizerBody.put("type", "TOKEN");
|
||||
createAuthorizerBody.put("authorizerUri", "arn:aws:lambda:us-east-1:123456789012:function:my-authorizer");
|
||||
createAuthorizerBody.put("identitySource", "method.request.header.Authorization");
|
||||
|
||||
String authorizerId = given()
|
||||
.contentType("application/json")
|
||||
.body(createAuthorizerBody)
|
||||
.when()
|
||||
.post("/restapis/" + apiId + "/authorizers")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.extract()
|
||||
.path("id");
|
||||
|
||||
Map<String, Object> validOp = new HashMap<>();
|
||||
validOp.put("op", "replace");
|
||||
validOp.put("path", "/name");
|
||||
validOp.put("value", "renamed");
|
||||
|
||||
Map<String, Object> invalidOp = new HashMap<>();
|
||||
invalidOp.put("op", "replace");
|
||||
invalidOp.put("path", "/authorizerResultTtlInSeconds");
|
||||
invalidOp.put("value", "not-a-number");
|
||||
|
||||
Map<String, Object> patchBody = new HashMap<>();
|
||||
patchBody.put("patchOperations", new Object[]{validOp, invalidOp});
|
||||
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.body(patchBody)
|
||||
.when()
|
||||
.patch("/restapis/" + apiId + "/authorizers/" + authorizerId)
|
||||
.then()
|
||||
.statusCode(400);
|
||||
|
||||
given()
|
||||
.when()
|
||||
.get("/restapis/" + apiId + "/authorizers/" + authorizerId)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("name", equalTo("original-name"));
|
||||
}
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
package io.github.hectorvent.floci.services.apigateway;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
@QuarkusTest
|
||||
class ApiGatewayUpdateBasePathMappingIntegrationTest {
|
||||
|
||||
@Test
|
||||
void testCreateAndUpdateBasePathMapping() {
|
||||
String apiId = given()
|
||||
.contentType("application/json")
|
||||
.body("{\"name\":\"mapping-api\"}")
|
||||
.when().post("/restapis").then().statusCode(201).extract().path("id");
|
||||
given().contentType("application/json").body("{\"domainName\":\"mapping.example.test\"}").when().post("/domainnames").then().statusCode(201);
|
||||
String basePath = "v1";
|
||||
String stageBefore = "before";
|
||||
String createBody = "{\"basePath\":\"" + basePath + "\",\"restApiId\":\"" + apiId + "\",\"stage\":\"" + stageBefore + "\"}";
|
||||
given().contentType("application/json").body(createBody).when().post("/domainnames/mapping.example.test/basepathmappings").then().statusCode(201);
|
||||
String patchBody = "{\"patchOperations\":[{\"op\":\"replace\",\"path\":\"/stage\",\"value\":\"after\"}]}";
|
||||
given().contentType("application/json").body(patchBody).when().patch("/domainnames/mapping.example.test/basepathmappings/v1").then().statusCode(200).body("basePath", equalTo(basePath)).body("restApiId", equalTo(apiId)).body("stage", equalTo("after"));
|
||||
given().when().get("/domainnames/mapping.example.test/basepathmappings/v1").then().statusCode(200).body("stage", equalTo("after"));
|
||||
}
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
package io.github.hectorvent.floci.services.apigateway;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
@QuarkusTest
|
||||
class ApiGatewayUpdateDeploymentIntegrationTest {
|
||||
|
||||
@Test
|
||||
void testUpdateDeployment() {
|
||||
String apiId = given()
|
||||
.contentType("application/json")
|
||||
.body("{\"name\":\"update-deployment-api\"}")
|
||||
.when()
|
||||
.post("/restapis")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.extract()
|
||||
.path("id");
|
||||
|
||||
String deploymentId = given()
|
||||
.contentType("application/json")
|
||||
.body("{\"description\":\"before-update\"}")
|
||||
.when()
|
||||
.post("/restapis/" + apiId + "/deployments")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.extract()
|
||||
.path("id");
|
||||
|
||||
String patchBody = "{\"patchOperations\":[{\"op\":\"replace\",\"path\":\"/description\",\"value\":\"after-update\"}]}";
|
||||
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.body(patchBody)
|
||||
.when()
|
||||
.patch("/restapis/" + apiId + "/deployments/" + deploymentId)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("id", equalTo(deploymentId))
|
||||
.body("description", equalTo("after-update"));
|
||||
|
||||
given()
|
||||
.when()
|
||||
.get("/restapis/" + apiId + "/deployments/" + deploymentId)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("description", equalTo("after-update"));
|
||||
}
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
package io.github.hectorvent.floci.services.apigateway;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
@QuarkusTest
|
||||
class ApiGatewayUpdateDomainNameIntegrationTest {
|
||||
|
||||
@Test
|
||||
void testUpdateDomainName() {
|
||||
// POST /domainnames
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.body("{\"domainName\":\"update.example.test\",\"certificateName\":\"before\"}")
|
||||
.when()
|
||||
.post("/domainnames")
|
||||
.then()
|
||||
.statusCode(201);
|
||||
|
||||
// PATCH /domainnames/update.example.test
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.body("{\"patchOperations\":[{\"op\":\"replace\",\"path\":\"/certificateName\",\"value\":\"after\"},{\"op\":\"replace\",\"path\":\"/securityPolicy\",\"value\":\"TLS_1_0\"}]}")
|
||||
.when()
|
||||
.patch("/domainnames/update.example.test")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("domainName", equalTo("update.example.test"))
|
||||
.body("certificateName", equalTo("after"))
|
||||
.body("securityPolicy", equalTo("TLS_1_0"));
|
||||
|
||||
// GET /domainnames/update.example.test
|
||||
given()
|
||||
.when()
|
||||
.get("/domainnames/update.example.test")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("domainName", equalTo("update.example.test"))
|
||||
.body("certificateName", equalTo("after"))
|
||||
.body("securityPolicy", equalTo("TLS_1_0"));
|
||||
}
|
||||
}
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
package io.github.hectorvent.floci.services.apigateway;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
@QuarkusTest
|
||||
class ApiGatewayUpdateIntegrationIntegrationTest {
|
||||
|
||||
@Test
|
||||
void testApiGatewayIntegrationUpdate() {
|
||||
String apiId = given()
|
||||
.contentType("application/json")
|
||||
.body("{\"name\": \"integration-update\"}")
|
||||
.when().post("/restapis").then().statusCode(201).extract().path("id");
|
||||
String rootId = given()
|
||||
.when().get("/restapis/" + apiId + "/resources")
|
||||
.then().statusCode(200).extract().path("item[0].id");
|
||||
String resourceId = given()
|
||||
.contentType("application/json")
|
||||
.body("{\"pathPart\": \"items\"}")
|
||||
.when().post("/restapis/" + apiId + "/resources/" + rootId)
|
||||
.then().statusCode(201).extract().path("id");
|
||||
given().contentType("application/json").body("{\"authorizationType\": \"NONE\"}").when().put("/restapis/" + apiId + "/resources/" + resourceId + "/methods/GET").then().statusCode(201);
|
||||
given().contentType("application/json").body("{\"type\": \"MOCK\", \"passthroughBehavior\": \"WHEN_NO_MATCH\"}").when().put("/restapis/" + apiId + "/resources/" + resourceId + "/methods/GET/integration").then().statusCode(201);
|
||||
given().contentType("application/json").body("{\"patchOperations\":[{\"op\":\"replace\",\"path\":\"/passthroughBehavior\",\"value\":\"NEVER\"}]} ").when().patch("/restapis/" + apiId + "/resources/" + resourceId + "/methods/GET/integration").then().statusCode(200).body("type", equalTo("MOCK")).body("passthroughBehavior", equalTo("NEVER"));
|
||||
given().when().get("/restapis/" + apiId + "/resources/" + resourceId + "/methods/GET/integration").then().statusCode(200).body("passthroughBehavior", equalTo("NEVER"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testRejectedPatchDoesNotPartiallyApply() {
|
||||
String apiId = given()
|
||||
.contentType("application/json")
|
||||
.body("{\"name\": \"integration-update-reject\"}")
|
||||
.when().post("/restapis").then().statusCode(201).extract().path("id");
|
||||
String rootId = given()
|
||||
.when().get("/restapis/" + apiId + "/resources")
|
||||
.then().statusCode(200).extract().path("item[0].id");
|
||||
String resourceId = given()
|
||||
.contentType("application/json")
|
||||
.body("{\"pathPart\": \"items\"}")
|
||||
.when().post("/restapis/" + apiId + "/resources/" + rootId)
|
||||
.then().statusCode(201).extract().path("id");
|
||||
given().contentType("application/json").body("{\"authorizationType\": \"NONE\"}").when().put("/restapis/" + apiId + "/resources/" + resourceId + "/methods/GET").then().statusCode(201);
|
||||
given().contentType("application/json").body("{\"type\": \"MOCK\", \"passthroughBehavior\": \"WHEN_NO_MATCH\"}").when().put("/restapis/" + apiId + "/resources/" + resourceId + "/methods/GET/integration").then().statusCode(201);
|
||||
|
||||
given().contentType("application/json")
|
||||
.body("{\"patchOperations\":["
|
||||
+ "{\"op\":\"replace\",\"path\":\"/passthroughBehavior\",\"value\":\"NEVER\"},"
|
||||
+ "{\"op\":\"replace\",\"path\":\"/notASupportedPath\",\"value\":\"x\"}"
|
||||
+ "]}")
|
||||
.when().patch("/restapis/" + apiId + "/resources/" + resourceId + "/methods/GET/integration")
|
||||
.then().statusCode(400);
|
||||
|
||||
given().when().get("/restapis/" + apiId + "/resources/" + resourceId + "/methods/GET/integration")
|
||||
.then().statusCode(200).body("passthroughBehavior", equalTo("WHEN_NO_MATCH"));
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package io.github.hectorvent.floci.services.apigateway;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
@QuarkusTest
|
||||
class ApiGatewayUpdateIntegrationResponseIntegrationTest {
|
||||
|
||||
@Test
|
||||
void testUpdateIntegrationResponse() {
|
||||
String apiId = given().contentType("application/json").body("{\"name\":\"ir-update\"}").when().post("/restapis").then().statusCode(201).extract().path("id");
|
||||
String rootId = given().when().get("/restapis/" + apiId + "/resources").then().statusCode(200).extract().path("item[0].id");
|
||||
String resourceId = given().contentType("application/json").body("{\"pathPart\":\"items\"}").when().post("/restapis/" + apiId + "/resources/" + rootId).then().statusCode(201).extract().path("id");
|
||||
given().contentType("application/json").body("{\"authorizationType\":\"NONE\"}").when().put("/restapis/" + apiId + "/resources/" + resourceId + "/methods/GET").then().statusCode(201);
|
||||
given().contentType("application/json").body("{\"type\":\"MOCK\"}").when().put("/restapis/" + apiId + "/resources/" + resourceId + "/methods/GET/integration").then().statusCode(201);
|
||||
given().contentType("application/json").body("{\"selectionPattern\":\"before\",\"responseTemplates\":{\"application/json\":\"before\"}}").when().put("/restapis/" + apiId + "/resources/" + resourceId + "/methods/GET/integration/responses/200").then().statusCode(201);
|
||||
given().contentType("application/json").body("{\"patchOperations\":[{\"op\":\"replace\",\"path\":\"/selectionPattern\",\"value\":\"after\"}]}").when().patch("/restapis/" + apiId + "/resources/" + resourceId + "/methods/GET/integration/responses/200").then().statusCode(200).body("statusCode", equalTo("200")).body("selectionPattern", equalTo("after"));
|
||||
given().when().get("/restapis/" + apiId + "/resources/" + resourceId + "/methods/GET/integration/responses/200").then().statusCode(200).body("selectionPattern", equalTo("after"));
|
||||
}
|
||||
}
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
package io.github.hectorvent.floci.services.apigateway;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
@QuarkusTest
|
||||
class ApiGatewayUpdateMethodIntegrationTest {
|
||||
|
||||
@Test
|
||||
void testUpdateMethodAuthorizationType() {
|
||||
String apiId = given()
|
||||
.contentType("application/json")
|
||||
.body("{\"name\":\"method-update\"}")
|
||||
.when()
|
||||
.post("/restapis")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.extract()
|
||||
.path("id");
|
||||
|
||||
String rootId = given()
|
||||
.when()
|
||||
.get("/restapis/" + apiId + "/resources")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.extract()
|
||||
.path("item[0].id");
|
||||
|
||||
String childId = given()
|
||||
.contentType("application/json")
|
||||
.body("{\"pathPart\":\"items\"}")
|
||||
.when()
|
||||
.post("/restapis/" + apiId + "/resources/" + rootId)
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.extract()
|
||||
.path("id");
|
||||
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.body("{\"httpMethod\":\"GET\",\"authorizationType\":\"NONE\"}")
|
||||
.when()
|
||||
.put("/restapis/" + apiId + "/resources/" + childId + "/methods/GET")
|
||||
.then()
|
||||
.statusCode(201);
|
||||
|
||||
String patchBody = "{\"patchOperations\":[{\"op\":\"replace\",\"path\":\"/authorizationType\",\"value\":\"AWS_IAM\"}]}";
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.body(patchBody)
|
||||
.when()
|
||||
.patch("/restapis/" + apiId + "/resources/" + childId + "/methods/GET")
|
||||
.then()
|
||||
.statusCode(200).body("httpMethod", equalTo("GET")).body("authorizationType", equalTo("AWS_IAM"));
|
||||
|
||||
given()
|
||||
.when()
|
||||
.get("/restapis/" + apiId + "/resources/" + childId + "/methods/GET")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("authorizationType", equalTo("AWS_IAM"));
|
||||
}
|
||||
}
|
||||
+132
@@ -0,0 +1,132 @@
|
||||
package io.github.hectorvent.floci.services.apigateway;
|
||||
|
||||
import io.quarkus.test.common.http.TestHTTPEndpoint;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.http.ContentType;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
@QuarkusTest
|
||||
@TestHTTPEndpoint(ApiGatewayController.class)
|
||||
class ApiGatewayUpdateModelIntegrationTest {
|
||||
|
||||
private String createApi(String name) {
|
||||
return given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("{\"name\":\"" + name + "\"}")
|
||||
.when()
|
||||
.post("/restapis")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.extract()
|
||||
.path("id");
|
||||
}
|
||||
|
||||
private String createModel(String apiId, String modelName) {
|
||||
return given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("{\"name\":\"" + modelName + "\",\"description\":\"old\",\"contentType\":\"application/json\",\"schema\":\"{}\"}")
|
||||
.pathParam("apiId", apiId)
|
||||
.when()
|
||||
.post("/restapis/{apiId}/models")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.extract()
|
||||
.path("name");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCreateApiAndModelWorkflow() {
|
||||
String apiId = createApi("model-test-api");
|
||||
String modelName = createModel(apiId, "TestModel");
|
||||
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("{\"patchOperations\":[{\"op\":\"replace\",\"path\":\"/description\",\"value\":\"new\"}]}")
|
||||
.pathParam("apiId", apiId)
|
||||
.pathParam("modelName", modelName)
|
||||
.when()
|
||||
.patch("/restapis/{apiId}/models/{modelName}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("description", equalTo("new"));
|
||||
|
||||
given()
|
||||
.pathParam("apiId", apiId)
|
||||
.pathParam("modelName", modelName)
|
||||
.when()
|
||||
.get("/restapis/{apiId}/models/{modelName}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("name", equalTo("TestModel"))
|
||||
.body("description", equalTo("new"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testUpdateModelSchemaAndContentTypeViaPatchOperations() {
|
||||
String apiId = createApi("model-patch-api");
|
||||
String modelName = createModel(apiId, "PatchModel");
|
||||
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("{\"patchOperations\":["
|
||||
+ "{\"op\":\"replace\",\"path\":\"/schema\",\"value\":\"{\\\"type\\\":\\\"object\\\"}\"},"
|
||||
+ "{\"op\":\"replace\",\"path\":\"/contentType\",\"value\":\"application/xml\"}]}")
|
||||
.pathParam("apiId", apiId)
|
||||
.pathParam("modelName", modelName)
|
||||
.when()
|
||||
.patch("/restapis/{apiId}/models/{modelName}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("contentType", equalTo("application/xml"))
|
||||
.body("schema", equalTo("{\"type\":\"object\"}"));
|
||||
|
||||
given()
|
||||
.pathParam("apiId", apiId)
|
||||
.pathParam("modelName", modelName)
|
||||
.when()
|
||||
.get("/restapis/{apiId}/models/{modelName}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("contentType", equalTo("application/xml"));
|
||||
}
|
||||
|
||||
/** AWS treats model names as immutable; a rename must be rejected rather than clobber a sibling. */
|
||||
@Test
|
||||
void testRenameIsRejectedAndDoesNotDestroyAnotherModel() {
|
||||
String apiId = createApi("model-rename-api");
|
||||
createModel(apiId, "SourceModel");
|
||||
createModel(apiId, "TargetModel");
|
||||
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("{\"patchOperations\":[{\"op\":\"replace\",\"path\":\"/name\",\"value\":\"TargetModel\"}]}")
|
||||
.pathParam("apiId", apiId)
|
||||
.pathParam("modelName", "SourceModel")
|
||||
.when()
|
||||
.patch("/restapis/{apiId}/models/{modelName}")
|
||||
.then()
|
||||
.statusCode(400);
|
||||
|
||||
given()
|
||||
.pathParam("apiId", apiId)
|
||||
.pathParam("modelName", "SourceModel")
|
||||
.when()
|
||||
.get("/restapis/{apiId}/models/{modelName}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("name", equalTo("SourceModel"));
|
||||
|
||||
given()
|
||||
.pathParam("apiId", apiId)
|
||||
.pathParam("modelName", "TargetModel")
|
||||
.when()
|
||||
.get("/restapis/{apiId}/models/{modelName}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("name", equalTo("TargetModel"))
|
||||
.body("description", equalTo("old"));
|
||||
}
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
package io.github.hectorvent.floci.services.apigateway;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.http.ContentType;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
@QuarkusTest
|
||||
class ApiGatewayUpdateRequestValidatorIntegrationTest {
|
||||
|
||||
@Test
|
||||
void testUpdateRequestValidator() {
|
||||
String apiId = given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("{\"name\":\"validator-update\"}")
|
||||
.post("/restapis")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.extract()
|
||||
.path("id");
|
||||
|
||||
String validatorId = given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("{\"name\":\"before\",\"validateRequestBody\":false,\"validateRequestParameters\":true}")
|
||||
.post("/restapis/" + apiId + "/requestvalidators")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.extract()
|
||||
.path("id");
|
||||
|
||||
String patchBody = "{\"patchOperations\":[{\"op\":\"replace\",\"path\":\"/name\",\"value\":\"updated-validator\"},{\"op\":\"replace\",\"path\":\"/validateRequestBody\",\"value\":\"true\"},{\"op\":\"replace\",\"path\":\"/validateRequestParameters\",\"value\":\"false\"}]}";
|
||||
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body(patchBody)
|
||||
.patch("/restapis/" + apiId + "/requestvalidators/" + validatorId)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("name", equalTo("updated-validator"))
|
||||
.body("validateRequestBody", equalTo(true))
|
||||
.body("validateRequestParameters", equalTo(false));
|
||||
|
||||
given()
|
||||
.get("/restapis/" + apiId + "/requestvalidators/" + validatorId)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("name", equalTo("updated-validator"))
|
||||
.body("validateRequestBody", equalTo(true))
|
||||
.body("validateRequestParameters", equalTo(false));
|
||||
}
|
||||
}
|
||||
+251
@@ -0,0 +1,251 @@
|
||||
package io.github.hectorvent.floci.services.apigateway;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
@QuarkusTest
|
||||
class ApiGatewayUpdateResourceIntegrationTest {
|
||||
|
||||
@Test
|
||||
void testUpdateResourcePathAndParent() {
|
||||
// 1. Create API
|
||||
String apiId = given()
|
||||
.contentType("application/json")
|
||||
.body("{\"name\":\"resource-update\"}")
|
||||
.when()
|
||||
.post("/restapis")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.extract()
|
||||
.path("id");
|
||||
|
||||
// 2. Get root resource ID
|
||||
String rootId = given()
|
||||
.pathParam("apiId", apiId)
|
||||
.when()
|
||||
.get("/restapis/{apiId}/resources")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.extract()
|
||||
.path("item[0].id");
|
||||
|
||||
// 3. Create root children: "left" and "right"
|
||||
String leftId = given()
|
||||
.pathParam("apiId", apiId)
|
||||
.pathParam("parentId", rootId)
|
||||
.contentType("application/json")
|
||||
.body("{\"pathPart\":\"left\"}")
|
||||
.when()
|
||||
.post("/restapis/{apiId}/resources/{parentId}")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.extract()
|
||||
.path("id");
|
||||
|
||||
String rightId = given()
|
||||
.pathParam("apiId", apiId)
|
||||
.pathParam("parentId", rootId)
|
||||
.contentType("application/json")
|
||||
.body("{\"pathPart\":\"right\"}")
|
||||
.when()
|
||||
.post("/restapis/{apiId}/resources/{parentId}")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.extract()
|
||||
.path("id");
|
||||
|
||||
// 4. Create child under left
|
||||
String childId = given()
|
||||
.pathParam("apiId", apiId)
|
||||
.pathParam("parentId", leftId)
|
||||
.contentType("application/json")
|
||||
.body("{\"pathPart\":\"child\"}")
|
||||
.when()
|
||||
.post("/restapis/{apiId}/resources/{parentId}")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.extract()
|
||||
.path("id");
|
||||
|
||||
// 5. Create grand under child
|
||||
String grandId = given()
|
||||
.pathParam("apiId", apiId)
|
||||
.pathParam("parentId", childId)
|
||||
.contentType("application/json")
|
||||
.body("{\"pathPart\":\"grand\"}")
|
||||
.when()
|
||||
.post("/restapis/{apiId}/resources/{parentId}")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.extract()
|
||||
.path("id");
|
||||
|
||||
// 6. PATCH child: move to right, rename to "moved"
|
||||
String patchBody = String.format(
|
||||
"{\"patchOperations\":[{\"op\":\"replace\",\"path\":\"/pathPart\",\"value\":\"moved\"},{\"op\":\"replace\",\"path\":\"/parentId\",\"value\":\"%s\"}]}",
|
||||
rightId
|
||||
);
|
||||
|
||||
given()
|
||||
.pathParam("apiId", apiId)
|
||||
.pathParam("resourceId", childId)
|
||||
.contentType("application/json")
|
||||
.body(patchBody)
|
||||
.when()
|
||||
.patch("/restapis/{apiId}/resources/{resourceId}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("parentId", equalTo(rightId))
|
||||
.body("pathPart", equalTo("moved"))
|
||||
.body("path", equalTo("/right/moved"));
|
||||
|
||||
// 7. GET grand: should now be under moved (which is under right)
|
||||
given()
|
||||
.pathParam("apiId", apiId)
|
||||
.pathParam("resourceId", grandId)
|
||||
.when()
|
||||
.get("/restapis/{apiId}/resources/{resourceId}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("parentId", equalTo(childId))
|
||||
.body("path", equalTo("/right/moved/grand"));
|
||||
|
||||
// 8. GET child: verify updated state
|
||||
given()
|
||||
.pathParam("apiId", apiId)
|
||||
.pathParam("resourceId", childId)
|
||||
.when()
|
||||
.get("/restapis/{apiId}/resources/{resourceId}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("parentId", equalTo(rightId))
|
||||
.body("pathPart", equalTo("moved"))
|
||||
.body("path", equalTo("/right/moved"));
|
||||
}
|
||||
|
||||
private String createApi(String name) {
|
||||
return given()
|
||||
.contentType("application/json")
|
||||
.body("{\"name\":\"" + name + "\"}")
|
||||
.when()
|
||||
.post("/restapis")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.extract()
|
||||
.path("id");
|
||||
}
|
||||
|
||||
private String rootResourceId(String apiId) {
|
||||
return given()
|
||||
.pathParam("apiId", apiId)
|
||||
.when()
|
||||
.get("/restapis/{apiId}/resources")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.extract()
|
||||
.path("item[0].id");
|
||||
}
|
||||
|
||||
private String createChild(String apiId, String parentId, String pathPart) {
|
||||
return given()
|
||||
.pathParam("apiId", apiId)
|
||||
.pathParam("parentId", parentId)
|
||||
.contentType("application/json")
|
||||
.body("{\"pathPart\":\"" + pathPart + "\"}")
|
||||
.when()
|
||||
.post("/restapis/{apiId}/resources/{parentId}")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.extract()
|
||||
.path("id");
|
||||
}
|
||||
|
||||
/** AWS returns 400 when /parentId names an id that does not exist, not a 404 about the patched resource. */
|
||||
@Test
|
||||
void testUpdateResourceWithUnknownParentIdReturnsBadRequest() {
|
||||
String apiId = createApi("resource-bad-parent");
|
||||
String rootId = rootResourceId(apiId);
|
||||
String childId = createChild(apiId, rootId, "thing");
|
||||
|
||||
given()
|
||||
.pathParam("apiId", apiId)
|
||||
.pathParam("resourceId", childId)
|
||||
.contentType("application/json")
|
||||
.body("{\"patchOperations\":[{\"op\":\"replace\",\"path\":\"/parentId\",\"value\":\"nosuchid\"}]}")
|
||||
.when()
|
||||
.patch("/restapis/{apiId}/resources/{resourceId}")
|
||||
.then()
|
||||
.statusCode(400);
|
||||
}
|
||||
|
||||
/** Two siblings may not share a pathPart; AWS returns ConflictException. */
|
||||
@Test
|
||||
void testUpdateResourceRejectsSiblingPathCollision() {
|
||||
String apiId = createApi("resource-collision-patch");
|
||||
String rootId = rootResourceId(apiId);
|
||||
createChild(apiId, rootId, "alpha");
|
||||
String betaId = createChild(apiId, rootId, "beta");
|
||||
|
||||
given()
|
||||
.pathParam("apiId", apiId)
|
||||
.pathParam("resourceId", betaId)
|
||||
.contentType("application/json")
|
||||
.body("{\"patchOperations\":[{\"op\":\"replace\",\"path\":\"/pathPart\",\"value\":\"alpha\"}]}")
|
||||
.when()
|
||||
.patch("/restapis/{apiId}/resources/{resourceId}")
|
||||
.then()
|
||||
.statusCode(409);
|
||||
|
||||
given()
|
||||
.pathParam("apiId", apiId)
|
||||
.pathParam("resourceId", betaId)
|
||||
.when()
|
||||
.get("/restapis/{apiId}/resources/{resourceId}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("pathPart", equalTo("beta"))
|
||||
.body("path", equalTo("/beta"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testUpdateResourceRejectsCollisionAfterReparenting() {
|
||||
String apiId = createApi("resource-collision-reparent");
|
||||
String rootId = rootResourceId(apiId);
|
||||
String leftId = createChild(apiId, rootId, "left");
|
||||
String rightId = createChild(apiId, rootId, "right");
|
||||
createChild(apiId, rightId, "shared");
|
||||
String movingId = createChild(apiId, leftId, "shared");
|
||||
|
||||
given()
|
||||
.pathParam("apiId", apiId)
|
||||
.pathParam("resourceId", movingId)
|
||||
.contentType("application/json")
|
||||
.body("{\"patchOperations\":[{\"op\":\"replace\",\"path\":\"/parentId\",\"value\":\"" + rightId + "\"}]}")
|
||||
.when()
|
||||
.patch("/restapis/{apiId}/resources/{resourceId}")
|
||||
.then()
|
||||
.statusCode(409);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCreateResourceRejectsDuplicateSiblingPathPart() {
|
||||
String apiId = createApi("resource-collision-create");
|
||||
String rootId = rootResourceId(apiId);
|
||||
createChild(apiId, rootId, "dup");
|
||||
|
||||
given()
|
||||
.pathParam("apiId", apiId)
|
||||
.pathParam("parentId", rootId)
|
||||
.contentType("application/json")
|
||||
.body("{\"pathPart\":\"dup\"}")
|
||||
.when()
|
||||
.post("/restapis/{apiId}/resources/{parentId}")
|
||||
.then()
|
||||
.statusCode(409);
|
||||
}
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
package io.github.hectorvent.floci.services.apigateway;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
@QuarkusTest
|
||||
public class ApiGatewayUpdateRestApiIntegrationTest {
|
||||
|
||||
@Test
|
||||
public void testUpdateRestApi() {
|
||||
String id = given()
|
||||
.contentType("application/json")
|
||||
.body("{\"name\":\"rest-api-update\",\"description\":\"before\"}")
|
||||
.post("/restapis")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.extract()
|
||||
.path("id");
|
||||
|
||||
String patchBody = "{\"patchOperations\":[{\"op\":\"replace\",\"path\":\"/description\",\"value\":\"updated description\"}]}";
|
||||
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.body(patchBody)
|
||||
.patch("/restapis/" + id)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("name", equalTo("rest-api-update"))
|
||||
.body("description", equalTo("updated description"));
|
||||
|
||||
given()
|
||||
.get("/restapis/" + id)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("description", equalTo("updated description"));
|
||||
}
|
||||
}
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
package io.github.hectorvent.floci.services.apigateway;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
@QuarkusTest
|
||||
class ApiGatewayUpdateStageIntegrationTest {
|
||||
@Test
|
||||
void testUpdateStageDescription() {
|
||||
String apiId = given()
|
||||
.contentType("application/json")
|
||||
.body("{\"name\":\"stage-update\"}")
|
||||
.when()
|
||||
.post("/restapis")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.extract()
|
||||
.path("id");
|
||||
String rootId = given().when().get("/restapis/" + apiId + "/resources")
|
||||
.then().statusCode(200).extract().path("item[0].id");
|
||||
String deploymentId = given().contentType("application/json")
|
||||
.body("{\"description\":\"v1\"}")
|
||||
.when()
|
||||
.post("/restapis/" + apiId + "/deployments")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.extract()
|
||||
.path("id");
|
||||
given().contentType("application/json")
|
||||
.body("{\"stageName\":\"dev\",\"deploymentId\":\"" + deploymentId + "\",\"description\":\"before\"}")
|
||||
.when()
|
||||
.post("/restapis/" + apiId + "/stages")
|
||||
.then()
|
||||
.statusCode(201);
|
||||
String patchBody = "{\"patchOperations\":[{\"op\":\"replace\",\"path\":\"/description\",\"value\":\"updated\"}]}";
|
||||
given().contentType("application/json").body(patchBody)
|
||||
.when()
|
||||
.patch("/restapis/" + apiId + "/stages/dev")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("description", equalTo("updated"));
|
||||
given().when().get("/restapis/" + apiId + "/stages/dev")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("description", equalTo("updated"));
|
||||
}
|
||||
}
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
package io.github.hectorvent.floci.services.apigateway;
|
||||
|
||||
import io.quarkus.test.common.http.TestHTTPEndpoint;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.http.ContentType;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
@QuarkusTest
|
||||
@TestHTTPEndpoint(ApiGatewayController.class)
|
||||
class ApiGatewayUsagePlanCrudIntegrationTest {
|
||||
|
||||
@Test
|
||||
void testCreateAndRetrieveUsagePlan() {
|
||||
String usagePlanId = given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("{\"name\":\"before\",\"description\":\"old\"}")
|
||||
.post("/usageplans")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.extract()
|
||||
.path("id");
|
||||
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("{\"patchOperations\":["
|
||||
+ "{\"op\":\"replace\",\"path\":\"/name\",\"value\":\"after\"},"
|
||||
+ "{\"op\":\"replace\",\"path\":\"/description\",\"value\":\"new\"}]}")
|
||||
.patch("/usageplans/{usagePlanId}", usagePlanId)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("name", equalTo("after"))
|
||||
.body("description", equalTo("new"));
|
||||
|
||||
given()
|
||||
.get("/usageplans/{usagePlanId}", usagePlanId)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("id", equalTo(usagePlanId))
|
||||
.body("name", equalTo("after"))
|
||||
.body("description", equalTo("new"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testUnsupportedPatchPathIsRejected() {
|
||||
String usagePlanId = given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("{\"name\":\"reject-path\",\"description\":\"old\"}")
|
||||
.post("/usageplans")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.extract()
|
||||
.path("id");
|
||||
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("{\"patchOperations\":[{\"op\":\"replace\",\"path\":\"/nope\",\"value\":\"x\"}]}")
|
||||
.patch("/usageplans/{usagePlanId}", usagePlanId)
|
||||
.then()
|
||||
.statusCode(400);
|
||||
}
|
||||
}
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
package io.github.hectorvent.floci.services.apigateway;
|
||||
|
||||
import io.quarkus.test.common.http.TestHTTPEndpoint;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.http.ContentType;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
|
||||
@QuarkusTest
|
||||
@TestHTTPEndpoint(ApiGatewayController.class)
|
||||
public class ApiGatewayUsagePlanKeyIntegrationTest {
|
||||
|
||||
@Test
|
||||
public void testUsagePlanKeyLifecycle() {
|
||||
String apiKeyId = given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("{\"name\":\"usage-key\",\"enabled\":true}")
|
||||
.when()
|
||||
.post("/apikeys")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.body("id", notNullValue())
|
||||
.extract()
|
||||
.path("id");
|
||||
|
||||
String usagePlanId = given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("{\"name\":\"key-plan\"}")
|
||||
.when()
|
||||
.post("/usageplans")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.body("id", notNullValue())
|
||||
.extract()
|
||||
.path("id");
|
||||
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("{\"keyId\":\"" + apiKeyId + "\",\"keyType\":\"API_KEY\"}")
|
||||
.when()
|
||||
.post("/usageplans/" + usagePlanId + "/keys")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.body("id", equalTo(apiKeyId));
|
||||
|
||||
given()
|
||||
.when()
|
||||
.get("/usageplans/" + usagePlanId + "/keys")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("item[0].id", equalTo(apiKeyId));
|
||||
|
||||
given()
|
||||
.when()
|
||||
.get("/usageplans/" + usagePlanId + "/keys/" + apiKeyId)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("id", equalTo(apiKeyId));
|
||||
|
||||
given()
|
||||
.when()
|
||||
.delete("/usageplans/" + usagePlanId + "/keys/" + apiKeyId)
|
||||
.then()
|
||||
.statusCode(202);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package io.github.hectorvent.floci.services.apigateway;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
class ApiKeyCsvParserTest {
|
||||
|
||||
@Test
|
||||
void parsesStandardCsvWithCommaInField() {
|
||||
String csv = "Name,Key,UsagePlanIds\nMyKey,abcdefghijklmnopqrst,\"up-1,up-2\"\n";
|
||||
List<List<String>> result = ApiKeyCsvParser.parse(csv);
|
||||
|
||||
assertEquals(2, result.size());
|
||||
assertEquals(List.of("Name", "Key", "UsagePlanIds"), result.get(0));
|
||||
assertEquals(List.of("MyKey", "abcdefghijklmnopqrst", "up-1,up-2"), result.get(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
void parsesEscapedQuotes() {
|
||||
String csv = "Name,Key\n\"A \"\"quoted\"\" key\",abcdefghijklmnopqrst\n";
|
||||
List<List<String>> result = ApiKeyCsvParser.parse(csv);
|
||||
|
||||
assertEquals(2, result.size());
|
||||
assertEquals(List.of("Name", "Key"), result.get(0));
|
||||
assertEquals(List.of("A \"quoted\" key", "abcdefghijklmnopqrst"), result.get(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
void parsesCRLFAndIgnoresFinalEmptyRow() {
|
||||
String csv = "Name,Key\r\nMyKey,abcdefghijklmnopqrst\r\n";
|
||||
List<List<String>> result = ApiKeyCsvParser.parse(csv);
|
||||
|
||||
assertEquals(2, result.size());
|
||||
assertEquals(List.of("Name", "Key"), result.get(0));
|
||||
assertEquals(List.of("MyKey", "abcdefghijklmnopqrst"), result.get(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
void throwsOnUnterminatedQuote() {
|
||||
String csv = "Name,Key\n\"Unfinished,Value\n";
|
||||
|
||||
assertThrows(IllegalArgumentException.class, () -> ApiKeyCsvParser.parse(csv));
|
||||
}
|
||||
}
|
||||
+22
@@ -158,6 +158,28 @@ class ApiCorsConfigurationResponseTest {
|
||||
.body("corsConfiguration", nullValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteCorsConfigurationRemovesConfiguration() {
|
||||
String apiId = given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{"name":"cors-delete","protocolType":"HTTP",
|
||||
"corsConfiguration":{"allowOrigins":["https://example.com"]}}
|
||||
""")
|
||||
.when().post("/v2/apis")
|
||||
.then().statusCode(201)
|
||||
.extract().path("apiId");
|
||||
|
||||
given()
|
||||
.when().delete("/v2/apis/" + apiId + "/cors")
|
||||
.then().statusCode(204);
|
||||
|
||||
given()
|
||||
.when().get("/v2/apis/" + apiId)
|
||||
.then().statusCode(200)
|
||||
.body("$", not(hasKey("corsConfiguration")));
|
||||
}
|
||||
|
||||
// ──────────────────────────── JSON 1.1 path ────────────────────────────
|
||||
|
||||
@Test
|
||||
|
||||
Reference in new issue
Block a user