mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(apigateway): resolve _user_request_ APIs created outside default region (#1032)
Signed-off-by: JonghyeokNam <njh9750@naver.com>
This commit is contained in:
1 parent
34084fef87
commit
d12612c175
3 files changed
+216
-1
No files matched your search
+198
-1
@@ -123,4 +123,201 @@ class ApiGatewayUserRequestIntegrationTest {
|
||||
void cleanup() {
|
||||
given().when().delete("/restapis/" + apiId).then().statusCode(202);
|
||||
}
|
||||
}
|
||||
|
||||
@Test @Order(7)
|
||||
void executeViaUserRequestPathFindsRestApiCreatedInNonDefaultRegionWithoutAuthHeader() {
|
||||
String euWest2Auth = "AWS4-HMAC-SHA256 Credential=test/20260525/eu-west-2/apigateway/aws4_request, SignedHeaders=host, Signature=test";
|
||||
String localApiId = null;
|
||||
|
||||
try {
|
||||
localApiId = given()
|
||||
.contentType(ContentType.JSON)
|
||||
.header("Authorization", euWest2Auth)
|
||||
.body("{\"name\":\"user-request-region-fallback-test\"}")
|
||||
.when().post("/restapis")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.body("id", notNullValue())
|
||||
.extract().path("id");
|
||||
|
||||
String localRootId = given()
|
||||
.header("Authorization", euWest2Auth)
|
||||
.when().get("/restapis/" + localApiId + "/resources")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.extract().path("item[0].id");
|
||||
|
||||
String localResourceId = given()
|
||||
.contentType(ContentType.JSON)
|
||||
.header("Authorization", euWest2Auth)
|
||||
.body("{\"pathPart\":\"hello\"}")
|
||||
.when().post("/restapis/" + localApiId + "/resources/" + localRootId)
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.extract().path("id");
|
||||
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.header("Authorization", euWest2Auth)
|
||||
.body("{\"authorizationType\":\"NONE\"}")
|
||||
.when().put("/restapis/" + localApiId + "/resources/" + localResourceId + "/methods/GET")
|
||||
.then()
|
||||
.statusCode(201);
|
||||
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.header("Authorization", euWest2Auth)
|
||||
.body("{\"responseParameters\":{}}")
|
||||
.when().put("/restapis/" + localApiId + "/resources/" + localResourceId + "/methods/GET/responses/200")
|
||||
.then()
|
||||
.statusCode(201);
|
||||
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.header("Authorization", euWest2Auth)
|
||||
.body("{\"type\":\"MOCK\",\"requestTemplates\":{\"application/json\":\"{\\\"statusCode\\\": 200}\"}}")
|
||||
.when().put("/restapis/" + localApiId + "/resources/" + localResourceId + "/methods/GET/integration")
|
||||
.then()
|
||||
.statusCode(201);
|
||||
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.header("Authorization", euWest2Auth)
|
||||
.body("{\"selectionPattern\":\"\",\"responseTemplates\":{\"application/json\":\"{\\\"message\\\":\\\"ok\\\"}\"}}")
|
||||
.when().put("/restapis/" + localApiId + "/resources/" + localResourceId + "/methods/GET/integration/responses/200")
|
||||
.then()
|
||||
.statusCode(201);
|
||||
|
||||
String localDeploymentId = given()
|
||||
.contentType(ContentType.JSON)
|
||||
.header("Authorization", euWest2Auth)
|
||||
.body("{\"description\":\"region fallback\"}")
|
||||
.when().post("/restapis/" + localApiId + "/deployments")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.extract().path("id");
|
||||
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.header("Authorization", euWest2Auth)
|
||||
.body("{\"stageName\":\"dev\",\"deploymentId\":\"" + localDeploymentId + "\"}")
|
||||
.when().post("/restapis/" + localApiId + "/stages")
|
||||
.then()
|
||||
.statusCode(201);
|
||||
|
||||
given()
|
||||
.when().get("/restapis/" + localApiId + "/dev/_user_request_/hello")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("message", equalTo("ok"));
|
||||
} finally {
|
||||
if (localApiId != null) {
|
||||
given()
|
||||
.header("Authorization", euWest2Auth)
|
||||
.when().delete("/restapis/" + localApiId)
|
||||
.then()
|
||||
.statusCode(anyOf(equalTo(202), equalTo(404)));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Test @Order(8)
|
||||
void executeViaUserRequestPathDoesNotFallbackWhenSigV4RegionIsExplicit() {
|
||||
String euWest2Auth = "AWS4-HMAC-SHA256 Credential=test/20260525/eu-west-2/apigateway/aws4_request, SignedHeaders=host, Signature=test";
|
||||
String usEast1Auth = "AWS4-HMAC-SHA256 Credential=test/20260525/us-east-1/apigateway/aws4_request, SignedHeaders=host, Signature=test";
|
||||
String localApiId = null;
|
||||
|
||||
try {
|
||||
localApiId = given()
|
||||
.contentType(ContentType.JSON)
|
||||
.header("Authorization", euWest2Auth)
|
||||
.body("{\"name\":\"user-request-explicit-region-test\"}")
|
||||
.when().post("/restapis")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.body("id", notNullValue())
|
||||
.extract().path("id");
|
||||
|
||||
String localRootId = given()
|
||||
.header("Authorization", euWest2Auth)
|
||||
.when().get("/restapis/" + localApiId + "/resources")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.extract().path("item[0].id");
|
||||
|
||||
String localResourceId = given()
|
||||
.contentType(ContentType.JSON)
|
||||
.header("Authorization", euWest2Auth)
|
||||
.body("{\"pathPart\":\"hello\"}")
|
||||
.when().post("/restapis/" + localApiId + "/resources/" + localRootId)
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.extract().path("id");
|
||||
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.header("Authorization", euWest2Auth)
|
||||
.body("{\"authorizationType\":\"NONE\"}")
|
||||
.when().put("/restapis/" + localApiId + "/resources/" + localResourceId + "/methods/GET")
|
||||
.then()
|
||||
.statusCode(201);
|
||||
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.header("Authorization", euWest2Auth)
|
||||
.body("{\"responseParameters\":{}}")
|
||||
.when().put("/restapis/" + localApiId + "/resources/" + localResourceId + "/methods/GET/responses/200")
|
||||
.then()
|
||||
.statusCode(201);
|
||||
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.header("Authorization", euWest2Auth)
|
||||
.body("{\"type\":\"MOCK\",\"requestTemplates\":{\"application/json\":\"{\\\"statusCode\\\": 200}\"}}")
|
||||
.when().put("/restapis/" + localApiId + "/resources/" + localResourceId + "/methods/GET/integration")
|
||||
.then()
|
||||
.statusCode(201);
|
||||
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.header("Authorization", euWest2Auth)
|
||||
.body("{\"selectionPattern\":\"\",\"responseTemplates\":{\"application/json\":\"{\\\"message\\\":\\\"ok\\\"}\"}}")
|
||||
.when().put("/restapis/" + localApiId + "/resources/" + localResourceId + "/methods/GET/integration/responses/200")
|
||||
.then()
|
||||
.statusCode(201);
|
||||
|
||||
String localDeploymentId = given()
|
||||
.contentType(ContentType.JSON)
|
||||
.header("Authorization", euWest2Auth)
|
||||
.body("{\"description\":\"explicit region\"}")
|
||||
.when().post("/restapis/" + localApiId + "/deployments")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.extract().path("id");
|
||||
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.header("Authorization", euWest2Auth)
|
||||
.body("{\"stageName\":\"dev\",\"deploymentId\":\"" + localDeploymentId + "\"}")
|
||||
.when().post("/restapis/" + localApiId + "/stages")
|
||||
.then()
|
||||
.statusCode(201);
|
||||
|
||||
given()
|
||||
.header("Authorization", usEast1Auth)
|
||||
.when().get("/restapis/" + localApiId + "/dev/_user_request_/hello")
|
||||
.then()
|
||||
.statusCode(404)
|
||||
.body("message", equalTo("Invalid API id specified"));
|
||||
} finally {
|
||||
if (localApiId != null) {
|
||||
given()
|
||||
.header("Authorization", euWest2Auth)
|
||||
.when().delete("/restapis/" + localApiId)
|
||||
.then()
|
||||
.statusCode(anyOf(equalTo(202), equalTo(404)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user