Skip to content

Commit

Permalink
upload protected with pac4j auth error fix #361
Browse files Browse the repository at this point in the history
  • Loading branch information
jknack committed Apr 20, 2016
1 parent 6bbc0b4 commit 4e0d6d0
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
36 changes: 36 additions & 0 deletions coverage-report/src/test/java/org/jooby/issues/Issue361.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.jooby.issues;

import org.jooby.Upload;
import org.jooby.pac4j.Auth;
import org.jooby.test.ServerFeature;
import org.junit.Test;

public class Issue361 extends ServerFeature {

{
use(new Auth().form());

get("/", () -> "OK");

post("/api/protected/upload", req -> {
Upload file = req.file("myfile");
return file.name();
});
}

@Test
public void shouldPac4jAuthContextShouldNotFailWithFileUploads() throws Exception {
request()
.get("/auth?username=test&password=test")
.expect("OK");

request()
.post("/api/protected/upload")
.multipart()
.add("username", "test")
.add("password", "test")
.file("myfile", "<xml></xml>".getBytes(), "application/xml", "pom.xml")
.expect(200);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@ private Multimap<String, String> decodeParams() throws IOException {
switch (field.getHttpDataType()) {
case FileUpload:
files.put(name, new NettyUpload((FileUpload) field, tmpdir));
// excludes upload from param names.
break;
default:
params.put(name, field.getString());
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,12 @@ public String path() {
public List<String> paramNames() {
ImmutableList.Builder<String> builder = ImmutableList.<String> builder();
builder.addAll(exchange.getQueryParameters().keySet());
form.forEach(builder::add);
form.forEach(v -> {
// excludes upload from param names.
if (!form.getFirst(v).isFile()) {
builder.add(v);
}
});
return builder.build();
}

Expand Down

0 comments on commit 4e0d6d0

Please sign in to comment.