mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(apigateway): refuse an empty or blank position on GetUsage (#9628)
This commit is contained in:
1 parent
904ae0203a
commit
d9ac9d2418
3 files changed
+26
-5
No files matched your search
@@ -1005,10 +1005,11 @@ public class ApiGatewayController {
|
||||
@QueryParam("endDate") String endDate,
|
||||
@QueryParam("keyId") String keyId,
|
||||
@QueryParam("limit") String limit,
|
||||
@QueryParam("position") String position) {
|
||||
@QueryParam("position") String position,
|
||||
@Context UriInfo uriInfo) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
ApiGatewayService.UsageReport report =
|
||||
service.getUsage(region, usagePlanId, startDate, endDate, keyId, pageLimit(limit), position);
|
||||
ApiGatewayService.UsageReport report = service.getUsage(region, usagePlanId, startDate, endDate, keyId,
|
||||
pageLimit(limit), requestedPosition(position, uriInfo));
|
||||
|
||||
ObjectNode root = objectMapper.createObjectNode();
|
||||
// The wire key is "values", not "items": the Usage shape models this map with
|
||||
|
||||
@@ -1962,9 +1962,10 @@ public class ApiGatewayService implements ResourceProvider, Resettable, PassedRo
|
||||
|
||||
// The page token is the last key id already returned, so a page resumes after it rather
|
||||
// than at a positional offset a concurrent key attachment could shift. Measured: an
|
||||
// unrecognised token is a BadRequestException, not an empty page.
|
||||
// unrecognised token is a BadRequestException, not an empty page. An empty or blank one
|
||||
// is refused the same way, as on the collections paged by pageById.
|
||||
int from = 0;
|
||||
if (position != null && !position.isBlank()) {
|
||||
if (position != null) {
|
||||
int previous = -1;
|
||||
for (int i = 0; i < keys.size(); i++) {
|
||||
if (position.equals(keys.get(i).getId())) {
|
||||
|
||||
@@ -4,6 +4,8 @@ import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.http.ContentType;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.aMapWithSize;
|
||||
import static org.hamcrest.Matchers.anEmptyMap;
|
||||
@@ -182,6 +184,23 @@ class ApiGatewayGetUsageIntegrationTest {
|
||||
.body(containsString("Invalid position parameter"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void anEmptyOrBlankPositionIsRejected() {
|
||||
String planId = createUsagePlan("usage-blankpos");
|
||||
createApiKeyOnPlan(planId, "usage-blankpos-key");
|
||||
|
||||
for (String position : List.of("", " ")) {
|
||||
given()
|
||||
.queryParam("startDate", "2026-09-01")
|
||||
.queryParam("endDate", "2026-09-02")
|
||||
.queryParam("position", position)
|
||||
.when().get("/usageplans/" + planId + "/usage")
|
||||
.then().statusCode(400)
|
||||
.body("__type", equalTo("BadRequestException"))
|
||||
.body("message", equalTo("Invalid position parameter"));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void aLimitBelowOneIsRejected() {
|
||||
String planId = createUsagePlan("usage-zerolimit");
|
||||
|
||||
Reference in new issue
Block a user