Skip to content

Commit

Permalink
Merge pull request #236 from opengeospatial/issue#cite-internal364
Browse files Browse the repository at this point in the history
Limit requested features to prevent too large responses
  • Loading branch information
dstenger authored Apr 19, 2024
2 parents 1a181e9 + fb7ee6a commit 40de36f
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,6 @@ private OgcApiFeatures10() {
public static final int CRS_LIMIT = 20;

public static final int FEATURES_LIMIT = 100;

public static final int NUMBERMATCHED_LIMIT = 10000;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import org.opengis.cite.ogcapifeatures10.conformance.SuiteAttribute;
import org.opengis.cite.ogcapifeatures10.util.ClientUtils;
import org.opengis.cite.ogcapifeatures10.util.RequestLimitFilter;
import org.testng.ITestContext;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
Expand Down Expand Up @@ -64,7 +65,7 @@ public String getResponse() {
protected RequestSpecification init() {
JsonConfig jsonConfig = JsonConfig.jsonConfig().numberReturnType(NumberReturnType.DOUBLE);
RestAssuredConfig config = RestAssuredConfig.newConfig().jsonConfig(jsonConfig) ;
return given().filters( requestLoggingFilter, responseLoggingFilter ).log().all().with().config(config);
return given().filters( new RequestLimitFilter(), requestLoggingFilter, responseLoggingFilter ).log().all().with().config(config);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.time.ZonedDateTime;
import java.util.List;

import org.opengis.cite.ogcapifeatures10.OgcApiFeatures10;
import org.opengis.cite.ogcapifeatures10.openapi3.OpenApiUtils;
import org.opengis.cite.ogcapifeatures10.openapi3.TestPoint;
import org.testng.SkipException;
Expand Down Expand Up @@ -100,6 +101,11 @@ static void assertNumberMatched( OpenApi3 apiModel, URI iut, String collectionNa
}
}
int numberMatched = jsonPath.getInt( "numberMatched" );
if (numberMatched > OgcApiFeatures10.NUMBERMATCHED_LIMIT) {
throw new SkipException(
String.format("Number of matched features too large to check, was %d, test suite limit is %d.",
numberMatched, OgcApiFeatures10.NUMBERMATCHED_LIMIT));
}
int numberOfAllReturnedFeatures = collectNumberOfAllReturnedFeatures( jsonPath, maximumLimit );
assertEquals( numberMatched, numberOfAllReturnedFeatures,
"Value of numberReturned (" + numberMatched + ") does not match the number of features in all responses ("
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package org.opengis.cite.ogcapifeatures10.util;

import io.restassured.filter.Filter;
import io.restassured.filter.FilterContext;
import io.restassured.response.Response;
import io.restassured.specification.FilterableRequestSpecification;
import io.restassured.specification.FilterableResponseSpecification;

/**
* @author Benjamin Pross (b.pross @52north.org)
*
* This class sets a limit for certain request to collection items.
* If a limit parameter is already set, nothing is done.
*
*/
public class RequestLimitFilter implements Filter {

private static String ITEMS = "items";
private static String LIMIT = "limit";

@Override
public Response filter(FilterableRequestSpecification requestSpec,
FilterableResponseSpecification responseSpec,
FilterContext ctx) {
//make sure that the limit is set only for requests to collection items
if(requestSpec.getURI().endsWith(ITEMS) || requestSpec.getURI().endsWith(ITEMS + "/")
|| requestSpec.getURI().contains(ITEMS + "?")){
//do nothing if a limit was already specified
if(!(requestSpec.getQueryParams().containsKey(LIMIT)
|| requestSpec.getRequestParams().containsKey(LIMIT))) {
requestSpec.queryParam(LIMIT, 10);
}
}
return ctx.next(requestSpec, responseSpec);
}

}
2 changes: 2 additions & 0 deletions src/site/asciidoc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ methods that constitute the suite.
** Paging iterations: 3
** Number of tested collections, if no limit is specified: 20
** Number of tested CRSs: 20
** A limit of 10 is set for all requests to collection items (features), except if a limit is already set by the test.
** For tests for correct matched numbers of features a maximum of 10000 is set. Tests are skipped for collections that contain more features.

include::how-to-run-the-tests.adoc[]

Expand Down

0 comments on commit 40de36f

Please sign in to comment.