From b70964396575ca6d37b30d4cbce9f4092fbe545d Mon Sep 17 00:00:00 2001 From: Marcin-Here Date: Thu, 19 Nov 2026 11:11:54 +0100 Subject: [PATCH 1/2] Naksha_306: change httpClient for tests. Signed-off-by: Marcin-Here --- .../app/common/NakshaTestWebClient.java | 207 ++++++++++++------ .../app/service/ReadFeaturesByBBoxTest.java | 23 ++ .../service/ReadFeaturesByRadiusPostTest.java | 4 +- .../app/service/ReadFeaturesByRadiusTest.java | 4 +- .../ReadFeaturesByTileHttpStorageTest.java | 4 +- .../app/service/ReadFeaturesByTileTest.java | 4 +- .../testutil/PropertySearchSamples.java | 5 + 7 files changed, 178 insertions(+), 73 deletions(-) diff --git a/here-naksha-app-service/src/test/java/com/here/naksha/app/common/NakshaTestWebClient.java b/here-naksha-app-service/src/test/java/com/here/naksha/app/common/NakshaTestWebClient.java index 6eadd95a33..a44b9a877d 100644 --- a/here-naksha-app-service/src/test/java/com/here/naksha/app/common/NakshaTestWebClient.java +++ b/here-naksha-app-service/src/test/java/com/here/naksha/app/common/NakshaTestWebClient.java @@ -19,19 +19,33 @@ package com.here.naksha.app.common; import static com.here.naksha.app.common.TestUtil.HDR_STREAM_ID; -import static java.net.http.HttpClient.Version.HTTP_1_1; import static org.apache.hc.core5.http.HttpHeaders.AUTHORIZATION; +import io.vertx.core.Vertx; +import io.vertx.core.buffer.Buffer; +import io.vertx.core.http.HttpClient; +import io.vertx.core.http.HttpClientOptions; +import io.vertx.core.http.HttpClientResponse; +import io.vertx.core.http.HttpMethod; +import io.vertx.core.http.PoolOptions; +import io.vertx.core.http.RequestOptions; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; -import java.net.http.HttpClient; import java.net.http.HttpClient.Version; +import java.net.http.HttpHeaders; import java.net.http.HttpRequest; -import java.net.http.HttpRequest.BodyPublishers; -import java.net.http.HttpRequest.Builder; import java.net.http.HttpResponse; +import java.net.http.HttpTimeoutException; import java.time.Duration; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; +import javax.net.ssl.SSLSession; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; @@ -47,17 +61,29 @@ public class NakshaTestWebClient { private static final long DEFAULT_NON_DEBUG_SOCKET_TIMEOUT_SEC = 5; - private final String NAKSHA_HTTP_URI; + private static final int MAX_CONNECTIONS = 50; + + private static Vertx vertx; + private final Duration SOCKET_TIMEOUT; + private final String host; + private final int port; + private final String basePath; private final HttpClient httpClient; public NakshaTestWebClient(final @NotNull String nhUrl, final long connectTimeoutSec, final long socketTimeoutSec) { - NAKSHA_HTTP_URI = nhUrl; SOCKET_TIMEOUT = Duration.ofSeconds(socketTimeoutSec); - httpClient = HttpClient.newBuilder() - .version(HTTP_1_1) - .connectTimeout(Duration.ofSeconds(connectTimeoutSec)) - .build(); + final URI baseUri = URI.create(nhUrl); + final boolean ssl = "https".equalsIgnoreCase(baseUri.getScheme()); + host = baseUri.getHost(); + port = baseUri.getPort() != -1 ? baseUri.getPort() : (ssl ? 443 : 80); + basePath = (baseUri.getRawPath() == null || baseUri.getRawPath().isEmpty()) ? "/" : baseUri.getRawPath(); + final HttpClientOptions clientOptions = new HttpClientOptions() + .setSsl(ssl) + .setConnectTimeout((int) TimeUnit.SECONDS.toMillis(connectTimeoutSec)) + .setMaxHeaderSize(32 * 1024); + final PoolOptions poolOptions = new PoolOptions().setHttp1MaxSize(MAX_CONNECTIONS); + httpClient = sharedVertx().createHttpClient(clientOptions, poolOptions); } public NakshaTestWebClient(long socketTimeoutSec) { @@ -70,14 +96,9 @@ public NakshaTestWebClient() { public HttpResponse get(String subPath, String streamId, Duration timeout, @Nullable String jwt) throws URISyntaxException, IOException, InterruptedException { - Builder requestBuilder = requestBuilder(timeout) - .uri(nakshaPath(subPath)) - .GET() - .header(HDR_STREAM_ID, streamId); - if (jwt != null) { - requestBuilder.header(AUTHORIZATION,jwt); - } - return sendOnce(requestBuilder.build()); + final RequestOptions request = request(HttpMethod.GET, subPath).addHeader(HDR_STREAM_ID, streamId); + addJwt(request, jwt); + return sendOnce(request, null, timeout); } public HttpResponse get(String subPath, String streamId) @@ -92,15 +113,11 @@ public HttpResponse get(String subPath, String streamId, String jwt) public HttpResponse post(String subPath, String jsonBody, String streamId, Duration timeout, @Nullable String jwt) throws URISyntaxException, IOException, InterruptedException { - Builder requestBuilder = requestBuilder(timeout) - .uri(nakshaPath(subPath)) - .POST(BodyPublishers.ofString(jsonBody)) - .header("Content-Type", "application/json") - .header(HDR_STREAM_ID, streamId); - if (jwt != null) { - requestBuilder.header(AUTHORIZATION,jwt); - } - return sendOnce(requestBuilder.build()); + final RequestOptions request = request(HttpMethod.POST, subPath) + .addHeader("Content-Type", "application/json") + .addHeader(HDR_STREAM_ID, streamId); + addJwt(request, jwt); + return sendOnce(request, jsonBody, timeout); } public HttpResponse post(String subPath, String jsonBody, String streamId) @@ -125,38 +142,28 @@ public HttpResponse put(String subPath, String jsonBody, String streamId public HttpResponse put(String subPath, String jsonBody, String streamId, @Nullable String jwt) throws URISyntaxException, IOException, InterruptedException { - Builder requestBuilder = requestBuilder(SOCKET_TIMEOUT) - .uri(nakshaPath(subPath)) - .PUT(BodyPublishers.ofString(jsonBody)) - .header("Content-Type", "application/json") - .header(HDR_STREAM_ID, streamId); - if (jwt != null) { - requestBuilder.header(AUTHORIZATION, jwt); - } - return sendOnce(requestBuilder.build()); + final RequestOptions request = request(HttpMethod.PUT, subPath) + .addHeader("Content-Type", "application/json") + .addHeader(HDR_STREAM_ID, streamId); + addJwt(request, jwt); + return sendOnce(request, jsonBody, SOCKET_TIMEOUT); } public HttpResponse options(String subPath, String originHeader, String requestMethod, String reqHeaderKeys) throws URISyntaxException, IOException, InterruptedException { - HttpRequest optionsRequest = requestBuilder(SOCKET_TIMEOUT) - .uri(nakshaPath(subPath)) - .method("OPTIONS", HttpRequest.BodyPublishers.noBody()) - .header("Origin", originHeader) - .header("Access-Control-Request-Method", requestMethod) - .header("Access-Control-Request-Headers", reqHeaderKeys) - .build(); - return sendOnce(optionsRequest); + final RequestOptions request = request(HttpMethod.OPTIONS, subPath) + .addHeader("Origin", originHeader) + .addHeader("Access-Control-Request-Method", requestMethod) + .addHeader("Access-Control-Request-Headers", reqHeaderKeys); + return sendOnce(request, null, SOCKET_TIMEOUT); } public HttpResponse patch(String subPath, String jsonBody, String streamId) throws URISyntaxException, IOException, InterruptedException { - HttpRequest patchRequest = requestBuilder(SOCKET_TIMEOUT) - .uri(nakshaPath(subPath)) - .method("PATCH",BodyPublishers.ofString(jsonBody)) - .header("Content-Type", "application/json") - .header(HDR_STREAM_ID, streamId) - .build(); - return sendOnce(patchRequest); + final RequestOptions request = request(HttpMethod.PATCH, subPath) + .addHeader("Content-Type", "application/json") + .addHeader(HDR_STREAM_ID, streamId); + return sendOnce(request, jsonBody, SOCKET_TIMEOUT); } public HttpResponse delete(String subPath, String streamId) @@ -166,28 +173,66 @@ public HttpResponse delete(String subPath, String streamId) public HttpResponse delete(String subPath, String streamId, @Nullable String jwt) throws URISyntaxException, IOException, InterruptedException { - Builder requestBuilder = requestBuilder(SOCKET_TIMEOUT) - .uri(nakshaPath(subPath)) - .DELETE() - .header("Content-Type", "application/json") - .header(HDR_STREAM_ID, streamId); + final RequestOptions request = request(HttpMethod.DELETE, subPath) + .addHeader("Content-Type", "application/json") + .addHeader(HDR_STREAM_ID, streamId); + addJwt(request, jwt); + return sendOnce(request, null, SOCKET_TIMEOUT); + } + + /** + * Creates request options for the given sub-path. The path is passed to Vert.x as a raw string, so it is sent + * without any encoding (e.g. {@code >=} stays {@code >=} and is not turned into {@code %3E=}). + */ + private RequestOptions request(HttpMethod method, String subPath) { + return new RequestOptions() + .setMethod(method) + .setHost(host) + .setPort(port) + .setURI(basePath + subPath); + } + + private static void addJwt(RequestOptions request, @Nullable String jwt) { if (jwt != null) { - requestBuilder.header(AUTHORIZATION, jwt); + request.addHeader(AUTHORIZATION, jwt); } - return sendOnce(requestBuilder.build()); } - private HttpResponse sendOnce(HttpRequest request) throws IOException, InterruptedException { - logger.info("Sending {} request to {}", request.method(), request.uri()); - return httpClient.send(request, HttpResponse.BodyHandlers.ofString()); + private HttpResponse sendOnce(RequestOptions request, @Nullable String body, Duration timeout) + throws IOException, InterruptedException { + logger.info("Sending {} request to {}", request.getMethod(), request.getURI()); + request.setIdleTimeout(timeout.toMillis()); + try { + return httpClient + .request(request) + .compose(req -> body == null ? req.send() : req.send(Buffer.buffer(body))) + .compose(resp -> resp.body().map(respBody -> toHttpResponse(resp, respBody))) + .toCompletionStage() + .toCompletableFuture() + // the idle timeout above should fire first, this is only a safety net + .get(timeout.toMillis() + 1000, TimeUnit.MILLISECONDS); + } catch (TimeoutException e) { + throw new HttpTimeoutException("Request timed out: " + request.getMethod() + " " + request.getURI()); + } catch (ExecutionException e) { + throw new IOException("Request failed: " + request.getMethod() + " " + request.getURI(), e.getCause()); + } } - private HttpRequest.Builder requestBuilder(Duration soTimeout) { - return HttpRequest.newBuilder().version(Version.HTTP_1_1).timeout(soTimeout); + private static HttpResponse toHttpResponse(HttpClientResponse resp, Buffer body) { + final Map> headers = new LinkedHashMap<>(); + for (String name : resp.headers().names()) { + headers.put(name, resp.headers().getAll(name)); + } + return new StringResponse(resp.statusCode(), HttpHeaders.of(headers, (name, value) -> true), body.toString()); } - private URI nakshaPath(String subPath) throws URISyntaxException { - return new URI(NAKSHA_HTTP_URI + subPath); + private static synchronized Vertx sharedVertx() { + if (vertx == null) { + final Vertx created = Vertx.vertx(); + Runtime.getRuntime().addShutdownHook(new Thread(created::close, "naksha-test-web-client-shutdown")); + vertx = created; + } + return vertx; } private static long chooseSocketTimeout(){ @@ -196,4 +241,36 @@ private static long chooseSocketTimeout(){ } return DEFAULT_NON_DEBUG_SOCKET_TIMEOUT_SEC; } + + /** + * Minimal {@link HttpResponse} holding what tests use: status code, headers and body. The request and URI are not + * available, because the raw request path might not be a valid {@link URI}. + */ + private record StringResponse(int statusCode, HttpHeaders headers, String body) implements HttpResponse { + + @Override + public HttpRequest request() { + throw new UnsupportedOperationException("request() is not available in NakshaTestWebClient responses"); + } + + @Override + public Optional> previousResponse() { + return Optional.empty(); + } + + @Override + public Optional sslSession() { + return Optional.empty(); + } + + @Override + public URI uri() { + throw new UnsupportedOperationException("uri() is not available in NakshaTestWebClient responses"); + } + + @Override + public Version version() { + return Version.HTTP_1_1; + } + } } diff --git a/here-naksha-app-service/src/test/java/com/here/naksha/app/service/ReadFeaturesByBBoxTest.java b/here-naksha-app-service/src/test/java/com/here/naksha/app/service/ReadFeaturesByBBoxTest.java index f839fa5a8a..f167209a23 100644 --- a/here-naksha-app-service/src/test/java/com/here/naksha/app/service/ReadFeaturesByBBoxTest.java +++ b/here-naksha-app-service/src/test/java/com/here/naksha/app/service/ReadFeaturesByBBoxTest.java @@ -924,4 +924,27 @@ void tc0735_testBBox3WithClipTrue() throws Exception { .hasJsonBody(expectedBodyPart, "Get Feature response body doesn't match"); } + @Test + void tc0736_testBBox2WithSearchOnNumberRawGTE() throws Exception { + // Test API : GET /hub/spaces/{spaceId}/bbox + // Validate that a raw (not url-encoded) ">=" operator, as sent e.g. by curl, is interpreted as "greater than or equal to" + // and returns the same features as the "=gte=" operator in tc0720 + + // Given: Features By BBox request (against configured space) + final String bboxQueryParam = "west=8.6476&south=50.1175&east=8.6729&north=50.1248"; + final String propQueryParam = "p.length>=10.5"; + final String expectedBodyPart = + loadFileOrFail("ReadFeatures/ByBBox/TC0720_BBox2_PropNumGTE/feature_response_part.json"); + String streamId = UUID.randomUUID().toString(); + + // When: Get Features By BBox request is submitted to NakshaHub + HttpResponse response = nakshaClient + .get("hub/spaces/" + SPACE_ID + "/bbox?" + bboxQueryParam + "&" + propQueryParam, streamId); + + // Then: Perform assertions + assertThat(response) + .hasStatus(200) + .hasStreamIdHeader(streamId) + .hasJsonBody(expectedBodyPart, "Get Feature response body doesn't match"); + } } diff --git a/here-naksha-app-service/src/test/java/com/here/naksha/app/service/ReadFeaturesByRadiusPostTest.java b/here-naksha-app-service/src/test/java/com/here/naksha/app/service/ReadFeaturesByRadiusPostTest.java index 2160dccd8b..1042ecdd7b 100644 --- a/here-naksha-app-service/src/test/java/com/here/naksha/app/service/ReadFeaturesByRadiusPostTest.java +++ b/here-naksha-app-service/src/test/java/com/here/naksha/app/service/ReadFeaturesByRadiusPostTest.java @@ -227,7 +227,7 @@ void baseTestExecution( // Given: Request parameters String urlQueryParams = ""; if (queryParamList!=null && !queryParamList.isEmpty()) { - urlQueryParams += String.join("&", queryParamList); + urlQueryParams = "?" + String.join("&", queryParamList); } final String streamId = UUID.randomUUID().toString(); @@ -239,7 +239,7 @@ void baseTestExecution( final String expectedBodyPart = (strictChecking) ? loadedString.replaceAll("\\{\\{streamId}}",streamId) : loadedString; // When: Get Features By Radius request is submitted to NakshaHub final HttpResponse response = nakshaClient - .post("hub/spaces/" + SPACE_ID + "/spatial?" + urlQueryParams, requestBody, streamId); + .post("hub/spaces/" + SPACE_ID + "/spatial" + urlQueryParams, requestBody, streamId); // Then: Perform standard assertions assertThat(response) diff --git a/here-naksha-app-service/src/test/java/com/here/naksha/app/service/ReadFeaturesByRadiusTest.java b/here-naksha-app-service/src/test/java/com/here/naksha/app/service/ReadFeaturesByRadiusTest.java index 800035a59b..20166c8d01 100644 --- a/here-naksha-app-service/src/test/java/com/here/naksha/app/service/ReadFeaturesByRadiusTest.java +++ b/here-naksha-app-service/src/test/java/com/here/naksha/app/service/ReadFeaturesByRadiusTest.java @@ -353,7 +353,7 @@ void baseTestExecution( // Given: Request parameters String urlQueryParams = ""; if (queryParamList!=null && !queryParamList.isEmpty()) { - urlQueryParams += String.join("&", queryParamList); + urlQueryParams = "?" + String.join("&", queryParamList); } final String streamId = UUID.randomUUID().toString(); @@ -363,7 +363,7 @@ void baseTestExecution( // When: Get Features By Radius request is submitted to NakshaHub final HttpResponse response = nakshaClient - .get("hub/spaces/" + SPACE_ID + "/spatial?" + urlQueryParams, streamId); + .get("hub/spaces/" + SPACE_ID + "/spatial" + urlQueryParams, streamId); // Then: Perform standard assertions assertThat(response) diff --git a/here-naksha-app-service/src/test/java/com/here/naksha/app/service/ReadFeaturesByTileHttpStorageTest.java b/here-naksha-app-service/src/test/java/com/here/naksha/app/service/ReadFeaturesByTileHttpStorageTest.java index c4e8117ae0..c0d6316a5d 100644 --- a/here-naksha-app-service/src/test/java/com/here/naksha/app/service/ReadFeaturesByTileHttpStorageTest.java +++ b/here-naksha-app-service/src/test/java/com/here/naksha/app/service/ReadFeaturesByTileHttpStorageTest.java @@ -169,7 +169,7 @@ void standardTestExecution( // Given: Request parameters String urlQueryParams = ""; if (queryParamList != null && !queryParamList.isEmpty()) { - urlQueryParams += String.join("&", queryParamList); + urlQueryParams = "?" + String.join("&", queryParamList); } final String streamId = UUID.randomUUID().toString(); @@ -187,7 +187,7 @@ void standardTestExecution( // When: Get Features By Tile request is submitted to NakshaHub final HttpResponse response = getNakshaClient() - .get("%s/%s/%s?%s".formatted(NAKSHA_ENDPOINT, tileType, tileId, urlQueryParams), streamId); + .get("%s/%s/%s%s".formatted(NAKSHA_ENDPOINT, tileType, tileId, urlQueryParams), streamId); // Then: Perform standard assertions assertThat(response) diff --git a/here-naksha-app-service/src/test/java/com/here/naksha/app/service/ReadFeaturesByTileTest.java b/here-naksha-app-service/src/test/java/com/here/naksha/app/service/ReadFeaturesByTileTest.java index cec3dd2f40..3ed1da9b0a 100644 --- a/here-naksha-app-service/src/test/java/com/here/naksha/app/service/ReadFeaturesByTileTest.java +++ b/here-naksha-app-service/src/test/java/com/here/naksha/app/service/ReadFeaturesByTileTest.java @@ -418,7 +418,7 @@ void standardTestExecution( // Given: Request parameters String urlQueryParams = ""; if (queryParamList!=null && !queryParamList.isEmpty()) { - urlQueryParams += String.join("&", queryParamList); + urlQueryParams = "?" + String.join("&", queryParamList); } final String streamId = UUID.randomUUID().toString(); @@ -428,7 +428,7 @@ void standardTestExecution( // When: Get Features By Tile request is submitted to NakshaHub final HttpResponse response = nakshaClient - .get("hub/spaces/" + SPACE_ID + "/tile/"+ tileType +"/"+ tileId +"?" + urlQueryParams, streamId); + .get("hub/spaces/" + SPACE_ID + "/tile/"+ tileType +"/"+ tileId + urlQueryParams, streamId); // Then: Perform standard assertions assertThat(response) diff --git a/here-naksha-app-service/src/test/java/com/here/naksha/app/service/testutil/PropertySearchSamples.java b/here-naksha-app-service/src/test/java/com/here/naksha/app/service/testutil/PropertySearchSamples.java index b399e126a9..09d5783b42 100644 --- a/here-naksha-app-service/src/test/java/com/here/naksha/app/service/testutil/PropertySearchSamples.java +++ b/here-naksha-app-service/src/test/java/com/here/naksha/app/service/testutil/PropertySearchSamples.java @@ -24,6 +24,11 @@ public static Stream queryParams() { Pair.of("properties.very.very.very.nested.even.more=1", "properties.very.very.very.nested.even.more=1"), Pair.of("properties.prop=gte=2,22", "properties.prop=gte=2,22"), Pair.of("properties.prop=lte=1", "properties.prop=lte=1"), + Pair.of("properties.prop<10", "properties.prop=lt=10"), + Pair.of("properties.prop>10", "properties.prop=gt=10"), + Pair.of("properties.prop>=10", "properties.prop=gte=10"), + Pair.of("properties.prop<=10", "properties.prop=lte=10"), + Pair.of("properties.array_1@>element_1", "properties.array_1=cs=element_1"), Pair.of("properties.prop=.null", "properties.prop=.null"), Pair.of("properties.prop=null", "properties.prop=null"), Pair.of("properties.prop!=.null", "properties.prop!=.null"), From 3e54134d3c7e8da62f87ca839d031a0a446f49f1 Mon Sep 17 00:00:00 2001 From: Marcin-Here Date: Thu, 19 Nov 2026 14:16:14 +0100 Subject: [PATCH 2/2] NAKSHA-306: added new Naksha version. Signed-off-by: Marcin-Here --- CHANGELOG.md | 3 +++ gradle.properties | 2 +- .../src/main/resources/swagger/openapi.yaml | 2 +- .../src/main/java/com/here/naksha/lib/core/NakshaVersion.java | 4 +++- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 79f8027ddd..8b95bf151a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## Naksha_2.2.30 +- Updated the test HTTP client to use Vert.x. + ## Naksha_2.2.29 - Fixed SQL injection via property names in property search by whitelisting allowed characters. diff --git a/gradle.properties b/gradle.properties index 46d4ad7a27..19b16c464e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -11,5 +11,5 @@ mavenPassword=YourPassword # - here-naksha-lib-core/src/main/com/here/naksha/lib/core/NakshaVersion (static property: latest) # - here-naksha-app-service/src/main/resources/swagger/openapi.yaml (info.version property) # - CHANGELOG.md -version=2.2.29 +version=2.2.30 diff --git a/here-naksha-app-service/src/main/resources/swagger/openapi.yaml b/here-naksha-app-service/src/main/resources/swagger/openapi.yaml index 2eaf0f52ea..8d85fb26df 100644 --- a/here-naksha-app-service/src/main/resources/swagger/openapi.yaml +++ b/here-naksha-app-service/src/main/resources/swagger/openapi.yaml @@ -12,7 +12,7 @@ servers: info: title: "Naksha Hub-API" description: "Naksha Hub-API is a REST API to provide simple access to geo data." - version: "2.2.29" + version: "2.2.30" security: - AccessToken: [ ] diff --git a/here-naksha-lib-core/src/main/java/com/here/naksha/lib/core/NakshaVersion.java b/here-naksha-lib-core/src/main/java/com/here/naksha/lib/core/NakshaVersion.java index 6bd3ca13be..d46b57247f 100644 --- a/here-naksha-lib-core/src/main/java/com/here/naksha/lib/core/NakshaVersion.java +++ b/here-naksha-lib-core/src/main/java/com/here/naksha/lib/core/NakshaVersion.java @@ -87,12 +87,14 @@ public class NakshaVersion implements Comparable { public static final String v2_2_27 = "2.2.27"; public static final String v2_2_28 = "2.2.28"; public static final String v2_2_29 = "2.2.29"; + public static final String v2_2_30 = "2.2.30"; + /** * The latest version of the naksha-extension stored in the resources. */ @AvailableSince(v2_0_5) - public static final NakshaVersion latest = of(v2_2_29); + public static final NakshaVersion latest = of(v2_2_30); private final int major; private final int minor;