mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(apigateway): implement account management endpoints and models (#867)
* feat(apigateway): implement account management endpoints and models * feat(apigateway): enhance patch operation validation and update throttle settings defaults * feat(api-gateway): add account management operations to API Gateway v1 * feat(api-gateway): add compatibility tests for account management and update logic * feat(api-gateway): add missing import for assertions in account compatibility test
This commit is contained in:
1 parent
647b170494
commit
15720e2ee6
9 files changed
+504
-31
No files matched your search
+188
@@ -0,0 +1,188 @@
|
||||
package io.github.hectorvent.floci.services.apigateway;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasItem;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import static io.restassured.RestAssured.given;
|
||||
import io.restassured.http.ContentType;
|
||||
|
||||
@QuarkusTest
|
||||
class ApiGatewayAccountIntegrationTest {
|
||||
|
||||
@BeforeEach
|
||||
void resetAccount() {
|
||||
String removePatch = "{\"patchOperations\":[{\"op\":\"remove\",\"path\":\"/cloudwatchRoleArn\"}]}";
|
||||
try {
|
||||
given().contentType(ContentType.JSON).body(removePatch).when().patch("/account");
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void getAccount_returnsDefaultShape() {
|
||||
given()
|
||||
.when().get("/account")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("apiKeyVersion", notNullValue())
|
||||
.body("features", hasItem("UsagePlans"))
|
||||
.body("throttleSettings.burstLimit", equalTo(5000))
|
||||
.body("throttleSettings.rateLimit", equalTo(10000.0f));
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateAccount_updatesCloudwatchRoleArn() {
|
||||
String arn = "arn:aws:iam::123456789012:role/apigAwsProxyRole";
|
||||
String patch = """
|
||||
{
|
||||
"patchOperations": [
|
||||
{
|
||||
"op": "replace",
|
||||
"path": "/cloudwatchRoleArn",
|
||||
"value": "%s"
|
||||
}
|
||||
]
|
||||
}
|
||||
""".formatted(arn);
|
||||
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body(patch)
|
||||
.when().patch("/account")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("cloudwatchRoleArn", equalTo(arn));
|
||||
|
||||
given()
|
||||
.when().get("/account")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("cloudwatchRoleArn", equalTo(arn));
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateAccount_rejectsThrottleSettingsPatch() {
|
||||
String patch = """
|
||||
{
|
||||
"patchOperations": [
|
||||
{
|
||||
"op": "replace",
|
||||
"path": "/throttleSettings/rateLimit",
|
||||
"value": "100"
|
||||
}
|
||||
]
|
||||
}
|
||||
""";
|
||||
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body(patch)
|
||||
.when().patch("/account")
|
||||
.then()
|
||||
.statusCode(400);
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateAccount_removesCloudwatchRoleArn() {
|
||||
String arn = "arn:aws:iam::123456789012:role/apigAwsProxyRole";
|
||||
String setPatch = """
|
||||
{
|
||||
"patchOperations": [
|
||||
{
|
||||
"op": "replace",
|
||||
"path": "/cloudwatchRoleArn",
|
||||
"value": "%s"
|
||||
}
|
||||
]
|
||||
}
|
||||
""".formatted(arn);
|
||||
|
||||
String removePatch = """
|
||||
{
|
||||
"patchOperations": [
|
||||
{
|
||||
"op": "remove",
|
||||
"path": "/cloudwatchRoleArn"
|
||||
}
|
||||
]
|
||||
}
|
||||
""";
|
||||
|
||||
given().contentType(ContentType.JSON).body(setPatch)
|
||||
.when().patch("/account")
|
||||
.then().statusCode(200).body("cloudwatchRoleArn", equalTo(arn));
|
||||
|
||||
given().contentType(ContentType.JSON).body(removePatch)
|
||||
.when().patch("/account")
|
||||
.then().statusCode(200).body("cloudwatchRoleArn", nullValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateAccount_rejectsUnsupportedPatchPath() {
|
||||
String patch = """
|
||||
{
|
||||
"patchOperations": [
|
||||
{
|
||||
"op": "replace",
|
||||
"path": "/apiKeyVersion",
|
||||
"value": "5"
|
||||
}
|
||||
]
|
||||
}
|
||||
""";
|
||||
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body(patch)
|
||||
.when().patch("/account")
|
||||
.then()
|
||||
.statusCode(400);
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateAccount_rejectsNullPatchOperation() {
|
||||
String patch = """
|
||||
{
|
||||
"patchOperations": [null]
|
||||
}
|
||||
""";
|
||||
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body(patch)
|
||||
.when().patch("/account")
|
||||
.then()
|
||||
.statusCode(400);
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateAccount_rejectsNonObjectPatchOperation() {
|
||||
String patch = """
|
||||
{
|
||||
"patchOperations": ["invalid"]
|
||||
}
|
||||
""";
|
||||
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body(patch)
|
||||
.when().patch("/account")
|
||||
.then()
|
||||
.statusCode(400);
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateAccount_rejectsEmptyBody() {
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("")
|
||||
.when().patch("/account")
|
||||
.then()
|
||||
.statusCode(400);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user