From cedf00d682ef0b62e291f9fec9946162bcdc098e Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Sat, 30 Oct 2021 05:08:45 +0300 Subject: Handle wrong RSS path correctly --- src/main/java/com/juick/www/rss/Feeds.java | 10 ++++++++++ src/test/java/com/juick/server/tests/ServerTests.java | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/juick/www/rss/Feeds.java b/src/main/java/com/juick/www/rss/Feeds.java index 4423b263..8111f2df 100644 --- a/src/main/java/com/juick/www/rss/Feeds.java +++ b/src/main/java/com/juick/www/rss/Feeds.java @@ -22,7 +22,12 @@ import com.juick.util.HttpNotFoundException; import com.juick.service.MessagesService; import com.juick.service.UserService; import com.juick.service.security.annotation.Visitor; + +import org.springframework.core.convert.ConversionFailedException; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestParam; @@ -79,4 +84,9 @@ public class Feeds { modelAndView.addObject("messages", messagesService.getLastReplies(hours)); return modelAndView; } + // wrong feed type + @ExceptionHandler(ConversionFailedException.class) + public ResponseEntity notFoundAction() { + return new ResponseEntity<>(HttpStatus.NOT_FOUND); + } } diff --git a/src/test/java/com/juick/server/tests/ServerTests.java b/src/test/java/com/juick/server/tests/ServerTests.java index 14517a60..5bb10ae9 100644 --- a/src/test/java/com/juick/server/tests/ServerTests.java +++ b/src/test/java/com/juick/server/tests/ServerTests.java @@ -2361,7 +2361,7 @@ public class ServerTests { + "q=0.8,application/signed-exchange;v=b3")) .andExpect(status().isOk()).andExpect(content().contentType("application/rss+xml;charset=UTF-8")); mockMvc.perform(get("/rss/ugnich/feed").accept(MediaType.TEXT_XML)).andExpect(status().isOk()); - mockMvc.perform(get("/rss/ugnich/diary").accept(MediaType.TEXT_XML)).andExpect(status().isBadRequest()); + mockMvc.perform(get("/rss/ugnich/diary").accept(MediaType.TEXT_XML)).andExpect(status().isNotFound()); } @Test -- cgit v1.2.3