forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't assume that multipart part without filename is always text
Fixes: quarkusio#38703
- Loading branch information
Showing
4 changed files
with
93 additions
and
10 deletions.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
...o/quarkus/resteasy/reactive/server/test/multipart/MultipartBinaryWithoutFilenameTest.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,67 @@ | ||
package io.quarkus.resteasy.reactive.server.test.multipart; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.util.function.Supplier; | ||
|
||
import jakarta.ws.rs.POST; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.core.MediaType; | ||
|
||
import org.jboss.resteasy.reactive.PartType; | ||
import org.jboss.resteasy.reactive.RestForm; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class MultipartBinaryWithoutFilenameTest { | ||
|
||
@RegisterExtension | ||
static QuarkusUnitTest test = new QuarkusUnitTest() | ||
.setArchiveProducer(new Supplier<>() { | ||
@Override | ||
public JavaArchive get() { | ||
return ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(MultipartDataInputTest.Resource.class, MultipartDataInputTest.Item.class, | ||
MultipartDataInputTest.Result.class); | ||
} | ||
}); | ||
private final File IMAGE_FILE = new File("./src/test/resources/image.png"); | ||
|
||
@Test | ||
public void test() throws IOException { | ||
byte[] bytes = given() | ||
.contentType("multipart/form-data") | ||
.multiPart("bytes", IMAGE_FILE, "application/png") | ||
.when() | ||
.post("/test") | ||
.then() | ||
.statusCode(200) | ||
.extract().body().asByteArray(); | ||
|
||
assertThat(bytes).isEqualTo(Files.readAllBytes(IMAGE_FILE.toPath())); | ||
} | ||
|
||
@Path("/test") | ||
public static class Resource { | ||
|
||
@POST | ||
public byte[] testMultipart(Input input) { | ||
return input.bytes; | ||
} | ||
} | ||
|
||
public static class Input { | ||
@RestForm("bytes") | ||
@PartType(MediaType.APPLICATION_OCTET_STREAM) | ||
public byte[] bytes; | ||
|
||
} | ||
} |
Binary file added
BIN
+5.25 MB
...easy-reactive/quarkus-resteasy-reactive/deployment/src/test/resources/image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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