aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/com/juick/server/tests/ServerTests.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/com/juick/server/tests/ServerTests.java')
-rw-r--r--src/test/java/com/juick/server/tests/ServerTests.java115
1 files changed, 62 insertions, 53 deletions
diff --git a/src/test/java/com/juick/server/tests/ServerTests.java b/src/test/java/com/juick/server/tests/ServerTests.java
index a942323c..84034428 100644
--- a/src/test/java/com/juick/server/tests/ServerTests.java
+++ b/src/test/java/com/juick/server/tests/ServerTests.java
@@ -30,6 +30,10 @@ import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.github.scribejava.apis.AppleClientSecretGenerator;
import com.jayway.jsonpath.JsonPath;
import com.juick.*;
+import com.juick.data.MessagesRepository;
+import com.juick.data.UsersRepository;
+import com.juick.data.entities.MessageEntity;
+import com.juick.data.entities.ReplyEntity;
import com.juick.model.Tag;
import com.juick.model.*;
import com.juick.server.MockNotificationListener;
@@ -196,6 +200,10 @@ public class ServerTests {
@Inject
private ProfileUriBuilder profileUriBuilder;
@Inject
+ private MessagesRepository messagesRepository;
+ @Inject
+ private UsersRepository usersRepository;
+ @Inject
private WebApp webApp;
@Value("${ap_base_uri:http://localhost:8080/}")
private String baseUri;
@@ -280,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;
@@ -905,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));
@@ -1522,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();
@@ -1635,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()));
@@ -2084,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");
@@ -2116,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"));
}
@@ -2315,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));
@@ -2717,4 +2683,47 @@ public class ServerTests {
var truncated = StringUtils.abbreviate(text, "…", 47);
assertThat(truncated, is(expected));
}
+ @Test
+ @Transactional
+ public void jpaMessageTests() {
+ var user = usersRepository.findByName(ugnichName);
+ var message = new MessageEntity();
+ message.setUser(user);
+ message.setText("Hello, JPA!");
+ message.setTimestamp(Instant.now());
+ message = messagesRepository.save(message);
+ var msg = messagesService.getMessage(message.getId());
+ assertThat(msg.get().getText(), is(notNullValue()));
+ assertThat(msg.get().getText(), is (message.getText()));
+ }
+ @Test
+ @Transactional
+ public void jpaReplyTests() {
+ var mid = messagesService.createMessage(ugnich.getUid(), "new message", null, Set.of());
+ var rid = messagesService.createReply(mid, 0, ugnich, "reply 1", null);
+ var message = messagesRepository.getReferenceById(mid);
+ 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"));
+
+ }
}