forked from jooby-project/jooby
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIssue1815.java
More file actions
41 lines (34 loc) · 1.19 KB
/
Copy pathIssue1815.java
File metadata and controls
41 lines (34 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package io.jooby;
import io.jooby.junit.ServerTest;
import io.jooby.junit.ServerTestRunner;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import java.nio.file.Path;
import java.nio.file.Paths;
import static okhttp3.RequestBody.create;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class Issue1815 {
@ServerTest
public void shouldNotThrowClassCastExceptionOnFileUploadWithCsrfHandler(ServerTestRunner runner) {
runner.define(app -> {
app.before(new CsrfHandler());
app.post("/1815", ctx -> ctx.multipart("file"));
}).ready(http -> {
http.post("/1815", new MultipartBody.Builder()
.setType(MultipartBody.FORM)
.addFormDataPart("file", "fileupload.js",
create(userdir("src", "test", "resources", "files", "fileupload.js").toFile(),
MediaType.parse("application/javascript")))
.build(), rsp -> {
assertEquals(StatusCode.FORBIDDEN_CODE, rsp.code());
});
});
}
private static Path userdir(String... segments) {
Path path = Paths.get(System.getProperty("user.dir"));
for (String segment : segments) {
path = path.resolve(segment);
}
return path;
}
}