Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.concurrent.ArrayBlockingQueue;

import jakarta.ws.rs.BadRequestException;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
Expand Down Expand Up @@ -109,6 +110,7 @@ public ArrayBlockingQueue<EmitDataImpl> getEmitDataQueue(int size) {
* @throws Exception
*/
@POST
@Consumes("application/json")
@Produces("application/json")
public Response post(InputStream is, @Context HttpHeaders httpHeaders, @Context UriInfo info) throws Exception {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.Map;

import jakarta.ws.rs.BadRequestException;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
Expand Down Expand Up @@ -84,6 +85,7 @@ public PipesResource(PipesParser pipesParser, PipesConfig pipesConfig) {
* @throws Exception
*/
@POST
@Consumes("application/json")
@Produces("application/json")
public Response postRmeta(InputStream is, @Context HttpHeaders httpHeaders, @Context UriInfo info) throws Exception {
FetchEmitTuple t = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ private Response post(String body) {
return WebClient
.create(endPoint + ASYNC_PATH)
.accept("application/json")
.type("application/json")
.post(body);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ public void testRequestMayNotRaiseWriteLimit() throws Exception {
Response response = WebClient
.create(endPoint + "/pipes")
.accept("application/json")
.type("application/json")
.post(tuple);
assertEquals(200, response.getStatus());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.StringWriter;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
Expand Down Expand Up @@ -194,6 +198,7 @@ public void testPost() throws Exception {
Response response = WebClient
.create(getUrl)
.accept("application/json")
.type("application/json")
.post(writer.toString());
assertEquals(200, response.getStatus());

Expand Down Expand Up @@ -234,6 +239,7 @@ public void testPostXML() throws Exception {
Response response = WebClient
.create(getUrl)
.accept("application/json")
.type("application/json")
.post(writer.toString());
assertEquals(200, response.getStatus());

Expand Down Expand Up @@ -265,6 +271,7 @@ public void testPostNPE() throws Exception {
Response response = WebClient
.create(getUrl)
.accept("application/json")
.type("application/json")
.post(writer.toString());
assertEquals(200, response.getStatus());

Expand Down Expand Up @@ -299,6 +306,7 @@ public void testPostNPENoEmit() throws Exception {
Response response = WebClient
.create(getUrl)
.accept("application/json")
.type("application/json")
.post(writer.toString());
assertEquals(200, response.getStatus());

Expand Down Expand Up @@ -334,6 +342,7 @@ private Response postTuple(FetchEmitTuple t) throws Exception {
return WebClient
.create(endPoint + PIPES_PATH)
.accept("application/json")
.type("application/json")
.post(writer.toString());
}

Expand Down Expand Up @@ -370,6 +379,7 @@ public void testMalformedBodyIs400() throws Exception {
Response response = WebClient
.create(endPoint + PIPES_PATH)
.accept("application/json")
.type("application/json")
.post("this is not json");
assertEquals(400, response.getStatus());
assertContains("/pipes request body",
Expand All @@ -383,10 +393,36 @@ public void testUnknownTupleFieldIs400() throws Exception {
Response response = WebClient
.create(endPoint + PIPES_PATH)
.accept("application/json")
.type("application/json")
.post(body);
assertEquals(400, response.getStatus());
assertContains("bogusField",
getStringFromInputStream((InputStream) response.getEntity()));
}

/**
* A web page can POST to /pipes without a CORS preflight only with a text/plain,
* form-urlencoded or multipart content type, or with none at all; refusing those
* keeps a browser on the server's network from running tuples cross-site.
*/
@Test
public void testCrossSiteSimpleRequestIsRefused() throws Exception {
FetchEmitTuple t = new FetchEmitTuple("myId",
new FetchKey(FETCHER_ID, HELLO_WORLD), new EmitKey(EMITTER_JSON_ID, ""), new Metadata());
StringWriter writer = new StringWriter();
JsonFetchEmitTuple.toJson(t, writer);
HttpClient client = HttpClient.newHttpClient();
for (String contentType : new String[]{"text/plain", "application/x-www-form-urlencoded", null}) {
HttpRequest.Builder request = HttpRequest
.newBuilder(URI.create(endPoint + PIPES_PATH))
.POST(HttpRequest.BodyPublishers.ofString(writer.toString()));
if (contentType != null) {
request.header("Content-Type", contentType);
}
HttpResponse<String> response = client.send(request.build(), HttpResponse.BodyHandlers.ofString());
assertEquals(415, response.statusCode(), String.valueOf(contentType));
assertFalse(Files.exists(tmpOutputFile), String.valueOf(contentType));
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ private JsonNode testOneWithPerRequestTimeout(String fileName, long timeoutMilli
Response response = WebClient
.create(endPoint + "/pipes")
.accept("application/json")
.type("application/json")
.post(getJsonStringWithTimeout(fileName, timeoutMillis));
assertEquals(expectedStatus, response.getStatus());
// a crash emits nothing, even with ON_PARSE_EXCEPTION.EMIT
Expand Down Expand Up @@ -160,6 +161,7 @@ private JsonNode testOne(String fileName, boolean shouldFileExist,
Response response = WebClient
.create(endPoint + "/pipes")
.accept("application/json")
.type("application/json")
.post(getJsonString(fileName, onParseException));
assertEquals(expectedStatus, response.getStatus());
Path targFile = TEMP_OUTPUT_DIR.resolve(fileName + ".json");
Expand Down Expand Up @@ -189,6 +191,7 @@ public void testPipesRejectsParserInjection() throws Exception {
Response response = WebClient
.create(endPoint + "/pipes")
.accept("application/json")
.type("application/json")
.post(requestJson);
assertTrue(response.getStatus() != 200,
"parser injection must be rejected, got HTTP " + response.getStatus());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ public void testBasic() throws Exception {
Response response = WebClient
.create(getUrl)
.accept("application/json")
.type("application/json")
.post(writer.toString());
assertEquals(200, response.getStatus());

Expand Down Expand Up @@ -233,6 +234,7 @@ public void testConcatenated() throws Exception {
Response response = WebClient
.create(getUrl)
.accept("application/json")
.type("application/json")
.post(writer.toString());
assertEquals(200, response.getStatus());

Expand Down Expand Up @@ -262,6 +264,7 @@ public void testPDFConfig() throws Exception {
Response response = WebClient
.create(getUrl)
.accept("application/json")
.type("application/json")
.post(writer.toString());
assertEquals(200, response.getStatus());

Expand Down Expand Up @@ -315,6 +318,7 @@ public void testBytes() throws Exception {
Response response = WebClient
.create(getUrl)
.accept("application/json")
.type("application/json")
.post(writer.toString());
assertEquals(200, response.getStatus());

Expand Down