-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test coverage of 'resteasy.gzip.max-input' property
add test with bigger bytes
- Loading branch information
1 parent
80e05e7
commit b61386f
Showing
4 changed files
with
138 additions
and
0 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
http/rest-client/src/main/java/io/quarkus/ts/http/restclient/GzipClientService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package io.quarkus.ts.http.restclient; | ||
|
||
import jakarta.ws.rs.POST; | ||
import jakarta.ws.rs.Path; | ||
|
||
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient; | ||
import org.jboss.resteasy.annotations.GZIP; | ||
|
||
@RegisterRestClient(configKey = "my-client") | ||
public interface GzipClientService { | ||
@POST | ||
@Path("/gzip") | ||
String gzip(@GZIP byte[] message); | ||
} |
22 changes: 22 additions & 0 deletions
22
http/rest-client/src/main/java/io/quarkus/ts/http/restclient/GzipResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package io.quarkus.ts.http.restclient; | ||
|
||
import jakarta.inject.Inject; | ||
import jakarta.ws.rs.POST; | ||
import jakarta.ws.rs.Path; | ||
|
||
import org.eclipse.microprofile.rest.client.inject.RestClient; | ||
import org.jboss.resteasy.annotations.GZIP; | ||
|
||
@Path("/gzip") | ||
public class GzipResource { | ||
|
||
@Inject | ||
@RestClient | ||
GzipClientService gzipClient; | ||
|
||
@POST | ||
public String gzip(@GZIP byte[] message) { | ||
return gzipClient.gzip(message); | ||
} | ||
|
||
} |
97 changes: 97 additions & 0 deletions
97
http/rest-client/src/test/java/io/quarkus/ts/http/restclient/GzipMaxInputIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package io.quarkus.ts.http.restclient; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
import java.util.zip.GZIPOutputStream; | ||
|
||
import jakarta.ws.rs.core.MediaType; | ||
|
||
import org.apache.http.HttpStatus; | ||
import org.junit.jupiter.api.Disabled; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import io.quarkus.test.bootstrap.RestService; | ||
import io.quarkus.test.scenarios.QuarkusScenario; | ||
import io.quarkus.test.services.QuarkusApplication; | ||
import io.restassured.response.Response; | ||
|
||
@QuarkusScenario | ||
public class GzipMaxInputIT { | ||
|
||
final byte[] gzip_bellow_max_input_1K = new byte[1000]; | ||
final byte[] gzip_max_input_10M = new byte[10000000]; | ||
|
||
final byte[] gzip_max_input_100M = new byte[100000000]; | ||
|
||
@QuarkusApplication(classes = { GzipResource.class, GzipClientService.class }, properties = "gzip.properties") | ||
static RestService app = new RestService(); | ||
|
||
/** | ||
* | ||
* According "All configurations options" guide the property 'quarkus.resteasy.gzip.max-input' refers to | ||
* | ||
* Maximum deflated file bytes size | ||
* | ||
* If the limit is exceeded, Resteasy will return Response with status 413("Request Entity Too Large") | ||
* | ||
*/ | ||
|
||
@Test | ||
void testGzipOverTheMaxLimit() throws IOException { | ||
|
||
byte[] compressedData = generateCompressedData(gzip_max_input_100M); | ||
|
||
Response response = app.given() | ||
.contentType(MediaType.APPLICATION_OCTET_STREAM) | ||
.header("Content-Encoding", "gzip") | ||
.body(compressedData) | ||
.when() | ||
.post("/gzip") | ||
.then() | ||
.extract().response(); | ||
assertEquals(HttpStatus.SC_REQUEST_TOO_LONG, response.statusCode()); | ||
} | ||
|
||
@Test | ||
void testGzipBigBytesOverLimit() throws IOException { | ||
|
||
byte[] compressedData = generateCompressedData(gzip_max_input_10M); | ||
|
||
Response response = app.given() | ||
.contentType(MediaType.APPLICATION_OCTET_STREAM) | ||
.header("Content-Encoding", "gzip") | ||
.body(compressedData) | ||
.when() | ||
.post("/gzip") | ||
.then() | ||
.extract().response(); | ||
assertEquals(HttpStatus.SC_REQUEST_TOO_LONG, response.statusCode()); | ||
} | ||
|
||
@Disabled ("Because https://github.com/quarkusio/quarkus/issues/40806") | ||
@Test | ||
void testGzipBelowMaxLimit() throws IOException { | ||
byte[] compressedData = generateCompressedData(gzip_bellow_max_input_1K); | ||
|
||
Response response = app.given() | ||
.contentType(MediaType.APPLICATION_OCTET_STREAM) | ||
.header("Content-Encoding", "gzip") | ||
.body(compressedData) | ||
.when() | ||
.post("/gzip") | ||
.then().log().all() | ||
.extract().response(); | ||
assertEquals(HttpStatus.SC_OK, response.statusCode()); | ||
} | ||
|
||
private byte[] generateCompressedData(byte[] data) throws IOException { | ||
ByteArrayOutputStream baos = new ByteArrayOutputStream(); | ||
GZIPOutputStream gzipOut = new GZIPOutputStream(baos); | ||
gzipOut.write(data); | ||
gzipOut.close(); | ||
return baos.toByteArray(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#Gzip | ||
quarkus.resteasy.gzip.enabled=true | ||
quarkus.resteasy.gzip.max-input=1k | ||
quarkus.http.compress-media-types=application/octet-stream | ||
quarkus.rest-client.my-client.url=http://${quarkus.http.host}:${quarkus.http.port} |