Skip to content

Commit a6dcaee

Browse files
authored
Add test for GCS fixture (#118737)
Relates: ES-5679
1 parent 15bec3c commit a6dcaee

File tree

4 files changed

+520
-6
lines changed

4 files changed

+520
-6
lines changed

server/src/main/java/org/elasticsearch/rest/RestUtils.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.elasticsearch.core.Nullable;
1616
import org.elasticsearch.core.TimeValue;
1717

18+
import java.net.URI;
1819
import java.nio.charset.Charset;
1920
import java.nio.charset.StandardCharsets;
2021
import java.util.Arrays;
@@ -35,6 +36,13 @@ public class RestUtils {
3536

3637
public static final UnaryOperator<String> REST_DECODER = RestUtils::decodeComponent;
3738

39+
public static void decodeQueryString(URI uri, Map<String, String> params) {
40+
final var rawQuery = uri.getRawQuery();
41+
if (Strings.hasLength(rawQuery)) {
42+
decodeQueryString(rawQuery, 0, params);
43+
}
44+
}
45+
3846
public static void decodeQueryString(String s, int fromIndex, Map<String, String> params) {
3947
if (fromIndex < 0) {
4048
return;

test/fixtures/gcs-fixture/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
apply plugin: 'elasticsearch.java'
1010

1111
description = 'Fixture for Google Cloud Storage service'
12-
tasks.named("test").configure { enabled = false }
1312

1413
dependencies {
1514
api project(':server')

test/fixtures/gcs-fixture/src/main/java/fixture/gcs/GoogleCloudStorageHttpHandler.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public void handle(final HttpExchange exchange) throws IOException {
9595
} else if (Regex.simpleMatch("GET /storage/v1/b/" + bucket + "/o*", request)) {
9696
// List Objects https://cloud.google.com/storage/docs/json_api/v1/objects/list
9797
final Map<String, String> params = new HashMap<>();
98-
RestUtils.decodeQueryString(exchange.getRequestURI().getQuery(), 0, params);
98+
RestUtils.decodeQueryString(exchange.getRequestURI(), params);
9999
final String prefix = params.getOrDefault("prefix", "");
100100
final String delimiter = params.get("delimiter");
101101

@@ -212,7 +212,7 @@ public void handle(final HttpExchange exchange) throws IOException {
212212
} else if (Regex.simpleMatch("POST /upload/storage/v1/b/" + bucket + "/*uploadType=resumable*", request)) {
213213
// Resumable upload initialization https://cloud.google.com/storage/docs/json_api/v1/how-tos/resumable-upload
214214
final Map<String, String> params = new HashMap<>();
215-
RestUtils.decodeQueryString(exchange.getRequestURI().getQuery(), 0, params);
215+
RestUtils.decodeQueryString(exchange.getRequestURI(), params);
216216
final String blobName = params.get("name");
217217
blobs.put(blobName, BytesArray.EMPTY);
218218

@@ -237,7 +237,7 @@ public void handle(final HttpExchange exchange) throws IOException {
237237
} else if (Regex.simpleMatch("PUT /upload/storage/v1/b/" + bucket + "/o?*uploadType=resumable*", request)) {
238238
// Resumable upload https://cloud.google.com/storage/docs/json_api/v1/how-tos/resumable-upload
239239
final Map<String, String> params = new HashMap<>();
240-
RestUtils.decodeQueryString(exchange.getRequestURI().getQuery(), 0, params);
240+
RestUtils.decodeQueryString(exchange.getRequestURI(), params);
241241

242242
final String blobName = params.get("test_blob_name");
243243
if (blobs.containsKey(blobName) == false) {
@@ -269,8 +269,6 @@ public void handle(final HttpExchange exchange) throws IOException {
269269
exchange.sendResponseHeaders(RestStatus.NOT_FOUND.getStatus(), -1);
270270
}
271271
} finally {
272-
int read = exchange.getRequestBody().read();
273-
assert read == -1 : "Request body should have been fully read here but saw [" + read + "]";
274272
exchange.close();
275273
}
276274
}

0 commit comments

Comments
 (0)