diff options
author | Tor Brede Vekterli <vekterli@yahooinc.com> | 2023-03-10 13:16:20 +0100 |
---|---|---|
committer | Tor Brede Vekterli <vekterli@yahooinc.com> | 2023-03-10 13:16:20 +0100 |
commit | c01ce2ca128ecfc6609a496ba7c5de579407aac3 (patch) | |
tree | 3764e96a34c4b09b3bec36ac6f05ef0ac0f1573f | |
parent | ec2d56866d70ac6625fb58aa2baa6f4014fd37d8 (diff) |
Do an early check that timestamp from/to range is valid
2 files changed, 12 insertions, 0 deletions
diff --git a/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/resource/DocumentV1ApiHandler.java b/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/resource/DocumentV1ApiHandler.java index 1dd4765c28e..fe1e2b46830 100644 --- a/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/resource/DocumentV1ApiHandler.java +++ b/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/resource/DocumentV1ApiHandler.java @@ -1231,6 +1231,9 @@ public class DocumentV1ApiHandler extends AbstractRequestHandler { getProperty(request, FROM_TIMESTAMP, unsignedLongParser).ifPresent(parameters::setFromTimestamp); getProperty(request, TO_TIMESTAMP, unsignedLongParser).ifPresent(parameters::setToTimestamp); + if (Long.compareUnsigned(parameters.getFromTimestamp(), parameters.getToTimestamp()) > 0) { + throw new IllegalArgumentException("toTimestamp must be greater than, or equal to, fromTimestamp"); + } StorageCluster storageCluster = resolveCluster(cluster, clusters); parameters.setRoute(storageCluster.name()); diff --git a/vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/resource/DocumentV1ApiTest.java b/vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/resource/DocumentV1ApiTest.java index 7b554c2b0fe..851a0949266 100644 --- a/vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/resource/DocumentV1ApiTest.java +++ b/vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/resource/DocumentV1ApiTest.java @@ -504,6 +504,15 @@ public class DocumentV1ApiTest { "}", response.readAll()); assertEquals(200, response.getStatus()); + // GET with from timestamp > to timestamp is an error + access.expect(parameters -> { fail("unreachable"); }); + response = driver.sendRequest("http://localhost/document/v1/?cluster=content&fromTimestamp=100&toTimestamp=99"); + assertSameJson("{" + + " \"pathId\": \"/document/v1/\"," + + " \"message\": \"toTimestamp must be greater than, or equal to, fromTimestamp\"" + + "}", response.readAll()); + assertEquals(400, response.getStatus()); + // GET with full document ID is a document get operation which returns 404 when no document is found access.session.expect((id, parameters) -> { assertEquals(doc1.getId(), id); |