Skip to content

Commit

Permalink
Add coverage for max parameters of multipart
Browse files Browse the repository at this point in the history
tweak mulripart tests

fix for loop initial from 0
  • Loading branch information
jcarranzan committed May 28, 2024
1 parent f9899bf commit 19de745
Showing 1 changed file with 41 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import static org.apache.http.HttpHeaders.ACCEPT_ENCODING;
import static org.apache.http.HttpHeaders.ACCEPT_LANGUAGE;
import static org.apache.http.HttpHeaders.CONTENT_TYPE;
import static org.apache.http.HttpStatus.SC_INTERNAL_SERVER_ERROR;
import static org.apache.http.HttpStatus.SC_NOT_FOUND;
import static org.apache.http.HttpStatus.SC_OK;
import static org.hamcrest.MatcherAssert.assertThat;
Expand All @@ -35,7 +36,6 @@
import static org.htmlunit.util.MimeType.IMAGE_PNG;
import static org.htmlunit.util.MimeType.TEXT_CSS;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.nio.file.Paths;
import java.time.Duration;
Expand Down Expand Up @@ -182,6 +182,46 @@ public void multipartFormDataReader() {
.body(TEXT, is(TEXT));
}

@Test
@DisplayName("RESTEasy Reactive Multipart Max Parameters test")
public void multiPartFormDataMaxParametersAllowed() {
// We are going to reach the MAX_PARAMETERS_ALLOWED in Quarkus Multipart that it's 1000
final int PARAMETERS_TO_ADD = 998;
// The file itself it's one parameter to add also
var request = getApp().given().multiPart(FILE, Paths.get("src", "test", "resources", "file.txt").toFile());

for (int i = 0; i < PARAMETERS_TO_ADD; i++) {
request = request.multiPart("param" + i, "value" + i);
}
// now we add the parameter TEXT with formParam, so we will get the max limit 1000
request.formParam(TEXT, TEXT);
request
.post(ROOT_PATH + MULTIPART_FORM_PATH)
.then()
.statusCode(SC_OK)
.body(FILE, is("File content"))
.body(TEXT, is(TEXT));

}

@DisplayName("RESTEasy Reactive Multipart Over the Max Parameters limit test")
@Test
public void exceedMultiPartParamsMaxLimit() {
// The file itself it's one parameter to add also
var request = getApp().given().multiPart(FILE, Paths.get("src", "test", "resources", "file.txt").toFile());
// We test the over the max limit of parameters defined by Quarkus that is 1000.
final int PARAMETERS_TO_ADD = 999;
for (int i = 0; i < PARAMETERS_TO_ADD; i++) {
request = request.multiPart("param" + i, "value" + i);
}
// we add the parameter TEXT with formParam so the total parameters will be 1000 + 1 so we are sending 1001
request.formParam(TEXT, TEXT);
request
.post(ROOT_PATH + MULTIPART_FORM_PATH)
.then()
.statusCode(SC_INTERNAL_SERVER_ERROR);
}

@DisplayName("Jakarta REST RouterFilter and Vert.x Web Routes integration")
@Test
public void multipleResponseFilter() {
Expand Down

0 comments on commit 19de745

Please sign in to comment.