From 291f4498320b2325093fb92cc9fbd9b4cb815782 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Mon, 9 Sep 2024 19:46:47 +0300 Subject: Handle post errors --- .../java/com/juick/server/tests/ServerTests.java | 21 +++++++++++++++++++++ src/test/resources/sample1.dng | Bin 0 -> 6372698 bytes 2 files changed, 21 insertions(+) create mode 100644 src/test/resources/sample1.dng (limited to 'src/test') diff --git a/src/test/java/com/juick/server/tests/ServerTests.java b/src/test/java/com/juick/server/tests/ServerTests.java index 418526c7..e0abe136 100644 --- a/src/test/java/com/juick/server/tests/ServerTests.java +++ b/src/test/java/com/juick/server/tests/ServerTests.java @@ -2749,4 +2749,25 @@ public class ServerTests { var replies = message.getReplies(); assertThat(replies.size(), is(1)); } + @Test + @Transactional + public void unsupportedMediaShouldBeHandledCorrectly() throws Exception { + ClassPathResource newMedia = new ClassPathResource("sample1.dng"); + byte[] newMediaData = IOUtils.toByteArray(newMedia.getInputStream()); + var response = mockMvc.perform(MockMvcRequestBuilders.multipart("/api/post") + .file(new MockMultipartFile("attach", "sample1.dng", "image/dng", newMediaData)) + .param("body", "test") + .with(httpBasic(freefdName, freefdPassword))).andExpect(status().isBadRequest()).andReturn(); + var result = jsonMapper.readValue(response.getResponse().getContentAsString(), CommandResult.class); + assertThat(result.getText(), is("Wrong file type: tif")); + var r = commandsManager.processCommand(freefd, "tst", emptyUri); + response = mockMvc.perform(MockMvcRequestBuilders.multipart("/api/comment") + .file(new MockMultipartFile("attach", "sample1.dng", "image/dng", newMediaData)) + .param("body", "test") + .param("mid", String.valueOf(r.getNewMessage().get().getMid())) + .with(httpBasic(freefdName, freefdPassword))).andExpect(status().isBadRequest()).andReturn(); + result = jsonMapper.readValue(response.getResponse().getContentAsString(), CommandResult.class); + assertThat(result.getText(), is("Wrong file type: tif")); + + } } diff --git a/src/test/resources/sample1.dng b/src/test/resources/sample1.dng new file mode 100644 index 00000000..e732e009 Binary files /dev/null and b/src/test/resources/sample1.dng differ -- cgit v1.2.3