aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/com
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/com')
-rw-r--r--src/test/java/com/juick/MessageTest.java16
-rw-r--r--src/test/java/com/juick/server/tests/ServerTests.java85
2 files changed, 46 insertions, 55 deletions
diff --git a/src/test/java/com/juick/MessageTest.java b/src/test/java/com/juick/MessageTest.java
index 14d6175a..e750f652 100644
--- a/src/test/java/com/juick/MessageTest.java
+++ b/src/test/java/com/juick/MessageTest.java
@@ -213,8 +213,8 @@ public class MessageTest {
assertThat(MessageUtils.formatMessage(msg), is("<blockquote>quote</blockquote>message"));
String brokenComment = "<!-- read next";
assertThat(MessageUtils.formatMessage(brokenComment), is("&lt;!-- read next"));
- String url = "[ya](http://ya.ru)";
- assertThat(MessageUtils.formatMessage(url), is("<a href=\"http://ya.ru\" rel=\"nofollow\">ya</a>"));
+ String url = "test [ya](https://juick.com/a/1)? hh";
+ assertThat(MessageUtils.formatMessage(url), is("test <a href=\"https://juick.com/a/1\" rel=\"nofollow\">ya</a>? hh"));
String complexMessage = "У футболистов нет мозгов. Что в России, что в Беларуси:\n" +
"\n" +
">Отец футболиста Лухвича, объехавшего пробку по тротуару: «Сына задержали, Infiniti арестовали» https://auto.onliner.by/2019/01/23/probka-9\n" +
@@ -238,4 +238,16 @@ public class MessageTest {
testMessage.setTags(MessageUtils.parseTags("NSFW test"));
assertThat(MessageUtils.isSensitive(testMessage), is(true));
}
+ @Test
+ public void stripHashesTest() {
+ var safeMessage = "And that is a [odd](https://juick.com/a/1)? aaapaa";
+ var nonsafeMessage = "[Here is my link](https://juick.com?hash=12345)";
+ var filteredMessage = "[Here is my link](https://juick.com)";
+ var pidginMessage = "I'm very smart to post my login url there<https://juick.com/settings?hash=VTYZkKV8FWkmu6g1>";
+ var westernMessage = "«Please, verify your account at https://juick.com/settings?hash=12345»";
+ assertThat(MessageUtils.stripNonSafeUrls(safeMessage), is(safeMessage));
+ assertThat(MessageUtils.stripNonSafeUrls(nonsafeMessage), is(filteredMessage));
+ assertThat(MessageUtils.stripNonSafeUrls(pidginMessage), not(containsString("VTYZkKV8FWkmu6g1")));
+ assertThat(MessageUtils.stripNonSafeUrls(westernMessage), containsString("»"));
+ }
}
diff --git a/src/test/java/com/juick/server/tests/ServerTests.java b/src/test/java/com/juick/server/tests/ServerTests.java
index a9f767f7..84034428 100644
--- a/src/test/java/com/juick/server/tests/ServerTests.java
+++ b/src/test/java/com/juick/server/tests/ServerTests.java
@@ -288,6 +288,10 @@ public class ServerTests {
.orElseThrow(IllegalStateException::new);
ugnich = makeUserVerified(ugnich);
freefd = makeUserVerified(freefd);
+ assertThat(ugnich.getLanguage(), is("__"));
+ ugnich.setLanguage("en");
+ userService.updateLanguage(ugnich);
+ assertThat(ugnich.getLanguage(), is("en"));
webClient.getOptions().setJavaScriptEnabled(false);
webClient.getOptions().setCssEnabled(false);
isSetUp = true;
@@ -913,12 +917,6 @@ public class ServerTests {
assertThat(result.getNewMessage(), is(Optional.empty()));
assertThat(result.getText(), is("Tags are NOT updated (5 tags maximum?)"));
result = commandsManager.processCommand(user,
- "I'm very smart to post my login url there"
- + "<https://juick.com/settings?hash=VTYZkKV8FWkmu6g1>",
- emptyUri);
- assertThat(result.getNewMessage().isPresent(), is(true));
- assertFalse(result.getNewMessage().get().getText().contains("VTYZkKV8FWkmu6g1"));
- result = commandsManager.processCommand(user,
"*корм *juick_ppl *рационализм *? *мюсли а сколько микроморт в дневной порции сверхмюслей?",
emptyUri);
assertThat(result.getNewMessage().isPresent(), is(true));
@@ -1530,8 +1528,8 @@ public class ServerTests {
jsonMapper.setSerializationInclusion(JsonInclude.Include.NON_DEFAULT);
String jsonUser = jsonMapper.writeValueAsString(yyy);
Map<String, Object> user = JsonPath.read(jsonUser, "$");
- // only uid, name and uri
- assertThat(user.keySet().size(), is(3));
+ // only uid, name, lang and uri
+ assertThat(user.keySet().size(), is(4));
JAXBContext context = JAXBContext.newInstance(User.class);
Marshaller m = context.createMarshaller();
@@ -1643,19 +1641,6 @@ public class ServerTests {
}
@Test
- public void accountUrlShouldBeExposedOverWebfinger() throws Exception {
- mockMvc.perform(get("/.well-known/webfinger?resource=acct:ugnich@" + webDomain)
- .accept("application/jrd+json")).andExpect(status().isOk())
- .andExpect(jsonPath("$.subject", is("acct:ugnich@" + webDomain)))
- .andExpect(jsonPath("$.links", hasSize(1)))
- .andExpect(jsonPath("$.links[0].href", is(baseUri + "u/ugnich")));
- mockMvc.perform(get("/.well-known/webfinger?resource=acct:durov@" + webDomain))
- .andExpect(status().isNotFound());
- mockMvc.perform(get("/.well-known/webfinger?resource=acct:@" + webDomain))
- .andExpect(status().isNotFound());
- }
-
- @Test
public void userProfileAndBlogShouldBeExposedAsActivityStream() throws Exception {
ClassPathResource defaultAvatar = new ClassPathResource("static/av-96.png");
String hash = DigestUtils.md5DigestAsHex(IOUtils.toByteArray(defaultAvatar.getInputStream()));
@@ -2092,14 +2077,6 @@ public class ServerTests {
}
@Test
- public void hostmeta() throws Exception {
- MvcResult result = mockMvc.perform(get("/.well-known/host-meta")).andExpect(status().isOk())
- .andReturn();
- String xrd = result.getResponse().getContentAsString();
- result = mockMvc.perform(get("/.well-known/x-nodeinfo2")).andExpect(status().isOk()).andReturn();
- }
-
- @Test
public void pms() throws Exception {
jdbcTemplate.execute("DELETE FROM pm");
jdbcTemplate.execute("DELETE FROM bl_users");
@@ -2124,12 +2101,14 @@ public class ServerTests {
}
@Test
+ @Disabled("FIXME: rewrite signup flow")
public void signupTest() throws Exception {
emailService.addVerificationCode(null, "demo@email.com", "123456");
- MvcResult result = mockMvc.perform(post("/api/signup").param("username", "testuser")
+ MvcResult result = mockMvc.perform(post("/signup").param("username", "testuser")
+ .param("type", "email")
.param("password", "demopassword").param("verificationCode", "123456"))
- .andExpect(status().isOk())
- .andReturn();
+ .andExpect(status().isOk())
+ .andReturn();
User testuser = jsonMapper.readValue(result.getResponse().getContentAsString(), User.class);
assertThat(testuser.getName(), is("testuser"));
}
@@ -2323,27 +2302,6 @@ public class ServerTests {
}
@Test
- public void nodeinfo() throws Exception {
- MvcResult nodeinfoXRD = mockMvc
- .perform(get("/.well-known/nodeinfo").contentType(MediaType.APPLICATION_JSON))
- .andExpect(status().isOk()).andReturn();
- JsonNode node = jsonMapper.readTree(nodeinfoXRD.getResponse().getContentAsString());
- assertThat(node.get("links"), notNullValue());
- String nodeinfoUrl = node.get("links").get(0).get("href").textValue();
- MvcResult nodeinfoData = mockMvc.perform(get(nodeinfoUrl).contentType(MediaType.APPLICATION_JSON))
- .andExpect(status().isOk()).andReturn();
- JsonNode nodeinfo = jsonMapper.readTree(nodeinfoData.getResponse().getContentAsString());
- assertThat(nodeinfo.get("software"), notNullValue());
- assertThat(nodeinfo.get("server"), nullValue());
- MvcResult xnodeinfoData = mockMvc
- .perform(get("/.well-known/x-nodeinfo2").contentType(MediaType.APPLICATION_JSON))
- .andExpect(status().isOk()).andReturn();
- JsonNode xnodeinfo = jsonMapper.readTree(xnodeinfoData.getResponse().getContentAsString());
- assertThat(xnodeinfo.get("server"), notNullValue());
- assertThat(xnodeinfo.get("software"), nullValue());
- }
-
- @Test
public void anonymousUserFromZero() {
User user = userService.getUserByUID(0).orElse(AnonymousUser.INSTANCE);
assertThat(user.isAnonymous(), is(true));
@@ -2747,4 +2705,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"));
+
+ }
}