From 0dcabe039a51a3a1aebd9a656a8dde2895b5e03a Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 1 Nov 2017 02:21:32 +0300 Subject: www: fix /comment multiparts with empty body --- .../src/main/java/com/juick/www/controllers/NewMessage.java | 9 +++------ juick-www/src/test/java/com/juick/www/WebAppTests.java | 10 +++++++++- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/juick-www/src/main/java/com/juick/www/controllers/NewMessage.java b/juick-www/src/main/java/com/juick/www/controllers/NewMessage.java index 2b411523..8f7c8059 100644 --- a/juick-www/src/main/java/com/juick/www/controllers/NewMessage.java +++ b/juick-www/src/main/java/com/juick/www/controllers/NewMessage.java @@ -195,15 +195,12 @@ public class NewMessage { @PostMapping("/comment") public String doPostComment( - @RequestParam(required = false, defaultValue = "0") Integer mid, + @RequestParam Integer mid, @RequestParam(required = false, defaultValue = "0") Integer rid, @RequestParam(required = false, defaultValue = StringUtils.EMPTY) String body, - @RequestParam(required = false) String img, + @RequestParam(required = false, defaultValue = StringUtils.EMPTY) String img, @RequestParam(required = false) MultipartFile attach) throws IOException { com.juick.User visitor = UserUtils.getCurrentUser(); - if (mid == 0) { - throw new HttpBadRequestException(); - } com.juick.Message msg = messagesService.getMessage(mid); if (msg == null) { throw new HttpNotFoundException(); @@ -217,7 +214,7 @@ public class NewMessage { } } - if ((StringUtils.isEmpty(body) || body.length() > 4096) && StringUtils.isEmpty(img)) { + if ((StringUtils.isEmpty(body) || body.length() > 4096) && StringUtils.isEmpty(img) && attach == null) { throw new HttpBadRequestException(); } body = body.replace("\r", StringUtils.EMPTY); diff --git a/juick-www/src/test/java/com/juick/www/WebAppTests.java b/juick-www/src/test/java/com/juick/www/WebAppTests.java index 48f465aa..ca1fc29a 100644 --- a/juick-www/src/test/java/com/juick/www/WebAppTests.java +++ b/juick-www/src/test/java/com/juick/www/WebAppTests.java @@ -248,6 +248,14 @@ public class WebAppTests { mockMvc.perform(post("/comment") .cookie(loginResult.getResponse().getCookies()) .param("mid", String.valueOf(mid)) - .param("body", "yo")).andExpect(redirectedUrl(String.format("/%s/%d#%d", ugnichName, mid, 1))); + .param("img", "http://static.juick.com/settings/facebook.png")).andExpect(status().isFound()); + mockMvc.perform(multipart("/comment") + .file(file) + .cookie(loginResult.getResponse().getCookies()) + .param("mid", String.valueOf(mid))).andExpect(status().isFound()); + mockMvc.perform(post("/comment") + .cookie(loginResult.getResponse().getCookies()) + .param("mid", String.valueOf(mid)) + .param("body", "yo")).andExpect(redirectedUrl(String.format("/%s/%d#%d", ugnichName, mid, 3))); } } -- cgit v1.2.3