Skip to content

Commit

Permalink
Add test coverage of 'resteasy.gzip.max-input' property
Browse files Browse the repository at this point in the history
add test with bigger bytes
  • Loading branch information
jcarranzan committed May 27, 2024
1 parent 80e05e7 commit b61386f
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 0 deletions.
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);
}
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);
}

}
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();
}

}
5 changes: 5 additions & 0 deletions http/rest-client/src/test/resources/gzip.properties
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}

0 comments on commit b61386f

Please sign in to comment.