aboutsummaryrefslogtreecommitdiff
path: root/juick-server/src/test
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-11-03 13:14:15 +0300
committerGravatar Vitaly Takmazov2018-11-03 13:14:15 +0300
commit2a64e080a395170875d62d3bebaf4dce3815bb13 (patch)
treee9c34caf2a694899ea67ab13d6bb2e0c20bee20d /juick-server/src/test
parent5cf3c20ed4463c6f35d51fc4e10366fe2b850f29 (diff)
ActivityPub: mentions with @user@server.tld
Diffstat (limited to 'juick-server/src/test')
-rw-r--r--juick-server/src/test/java/com/juick/server/tests/ServerTests.java23
-rw-r--r--juick-server/src/test/resources/webfinger.json36
2 files changed, 48 insertions, 11 deletions
diff --git a/juick-server/src/test/java/com/juick/server/tests/ServerTests.java b/juick-server/src/test/java/com/juick/server/tests/ServerTests.java
index d3654e90..86daff1f 100644
--- a/juick-server/src/test/java/com/juick/server/tests/ServerTests.java
+++ b/juick-server/src/test/java/com/juick/server/tests/ServerTests.java
@@ -18,7 +18,6 @@
package com.juick.server.tests;
import com.fasterxml.jackson.annotation.JsonInclude;
-import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.gargoylesoftware.htmlunit.CookieManager;
@@ -38,9 +37,9 @@ import com.juick.server.api.activity.model.activities.Create;
import com.juick.server.api.activity.model.activities.Delete;
import com.juick.server.api.activity.model.activities.Follow;
import com.juick.server.api.activity.model.activities.Undo;
-import com.juick.server.api.activity.model.objects.Mention;
import com.juick.server.api.activity.model.objects.Note;
import com.juick.server.api.activity.model.objects.Person;
+import com.juick.server.api.webfinger.model.Account;
import com.juick.server.util.HttpUtils;
import com.juick.server.util.ImageUtils;
import com.juick.server.xmpp.helpers.XMPPStatus;
@@ -68,17 +67,16 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate;
+import org.springframework.core.io.ClassPathResource;
import org.springframework.http.*;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult;
-import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.FileSystemUtils;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
-import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;
import org.w3c.dom.Document;
@@ -1432,6 +1430,8 @@ public class ServerTests {
.andExpect(jsonPath("$.links[0].href", is("http://localhost:8080/u/ugnich")));
mockMvc.perform(get("/.well-known/webfinger?resource=acct:durov@localhost"))
.andExpect(status().isNotFound());
+ Person ugnich = (Person) signatureManager.discoverPerson("ugnich@juick.com").get();
+ assertThat(ugnich.getName(), is(ugnichName));
}
@Test
public void userProfileAndBlogShouldBeExposedAsActivityStream() throws Exception {
@@ -1445,7 +1445,7 @@ public class ServerTests {
String.format("message %d", i), null, null))
.collect(Collectors.toCollection(ArrayDeque::new)).descendingIterator());
List<Integer> midsPage = mids.stream().limit(20).collect(Collectors.toList());
- mockMvc.perform(get("/u/ugnich/blog").accept(Context.ACTIVITY_JSON_MEDIA_TYPE))
+ mockMvc.perform(get("/u/ugnich/blog").accept(Context.ACTIVITYSTREAMS_PROFILE_MEDIA_TYPE))
.andExpect(status().isOk())
.andExpect(jsonPath("$.orderedItems", hasSize(20)))
.andExpect(jsonPath("$.next", is("http://localhost:8080/u/ugnich/blog?before=" + midsPage.get(midsPage.size() - 1))));
@@ -1699,19 +1699,19 @@ public class ServerTests {
}
@Test
public void ActivityDeserialization() throws IOException {
- String followJsonStr = IOUtils.toString(URI.create("classpath:follow.json"), StandardCharsets.UTF_8);
+ String followJsonStr = IOUtils.toString(new ClassPathResource("follow.json").getURI(), StandardCharsets.UTF_8);
Follow follow = (Follow)jsonMapper.readValue(followJsonStr, Context.class);
- String personJsonStr = IOUtils.toString(URI.create("classpath:person.json"), StandardCharsets.UTF_8);
+ String personJsonStr = IOUtils.toString(new ClassPathResource("person.json").getURI(), StandardCharsets.UTF_8);
Person person = (Person)jsonMapper.readValue(personJsonStr, Context.class);
- String undoJsonStr = IOUtils.toString(URI.create("classpath:undo.json"), StandardCharsets.UTF_8);
+ String undoJsonStr = IOUtils.toString(new ClassPathResource("undo.json").getURI(), StandardCharsets.UTF_8);
Undo undo = jsonMapper.readValue(undoJsonStr, Undo.class);
String undoFollower = (String)((Map)undo.getObject()).get("object");
- String createJsonStr = IOUtils.toString(URI.create("classpath:create.json"), StandardCharsets.UTF_8);
+ String createJsonStr = IOUtils.toString(new ClassPathResource("create.json").getURI(), StandardCharsets.UTF_8);
Create create = jsonMapper.readValue(createJsonStr, Create.class);
Map<String, Object> note = (Map<String, Object>) create.getObject();
Map<String, Object> attachmentObj = (Map<String, Object> )((List<Object>) note.get("attachment")).get(0);
String attachment = attachmentObj != null ? (String)attachmentObj.get("url") : StringUtils.EMPTY;
- String deleteJsonStr = IOUtils.toString(URI.create("classpath:delete.json"), StandardCharsets.UTF_8);
+ String deleteJsonStr = IOUtils.toString(new ClassPathResource("delete.json").getURI(), StandardCharsets.UTF_8);
Delete delete = jsonMapper.readValue(deleteJsonStr, Delete.class);
int mid = messagesService.createMessage(ugnich.getUid(), "YO", "", null);
User extUser = new User();
@@ -1725,8 +1725,9 @@ public class ServerTests {
Message replyToExt = messagesService.getReply(mid, rid2);
Note replyNote = activityPubManager.makeNote(replyToExt);
assertThat(replyNote.getInReplyTo(), equalTo(extMessageUri));
- String noteStr = IOUtils.toString(URI.create("classpath:mention.json"), StandardCharsets.UTF_8);
+ String noteStr = IOUtils.toString(new ClassPathResource("mention.json").getURI(), StandardCharsets.UTF_8);
Note create2 = jsonMapper.readValue(noteStr, Note.class);
+ jsonMapper.readValue(IOUtils.toString(new ClassPathResource("webfinger.json").getURI(), StandardCharsets.UTF_8), Account.class);
}
@Test
public void activitySerialization() throws Exception {
diff --git a/juick-server/src/test/resources/webfinger.json b/juick-server/src/test/resources/webfinger.json
new file mode 100644
index 00000000..55f9e4f3
--- /dev/null
+++ b/juick-server/src/test/resources/webfinger.json
@@ -0,0 +1,36 @@
+{
+ "subject": "acct:Gargron@mastodon.social",
+ "aliases": [
+ "https://mastodon.social/@Gargron",
+ "https://mastodon.social/users/Gargron"
+ ],
+ "links": [
+ {
+ "rel": "http://webfinger.net/rel/profile-page",
+ "type": "text/html",
+ "href": "https://mastodon.social/@Gargron"
+ },
+ {
+ "rel": "http://schemas.google.com/g/2010#updates-from",
+ "type": "application/atom+xml",
+ "href": "https://mastodon.social/users/Gargron.atom"
+ },
+ {
+ "rel": "self",
+ "type": "application/activity+json",
+ "href": "https://mastodon.social/users/Gargron"
+ },
+ {
+ "rel": "salmon",
+ "href": "https://mastodon.social/api/salmon/1"
+ },
+ {
+ "rel": "magic-public-key",
+ "href": "data:application/magic-public-key,RSA.vXc4vkECU2_CeuSo1wtnFoim94Ne1jBMYxTZ9wm2YTdJq1oiZKif06I2fOqDzY_4q_S9uccrE9Bkajv1dnkOVm31QjWlhVpSKynVxEWjVBO5Ienue8gND0xvHIuXf87o61poqjEoepvsQFElA5ymovljWGSA_jpj7ozygUZhCXtaS2W5AD5tnBQUpcO0lhItYPYTjnmzcc4y2NbJV8hz2s2G8qKv8fyimE23gY1XrPJg-cRF-g4PqFXujjlJ7MihD9oqtLGxbu7o1cifTn3xBfIdPythWu5b4cujNsB3m3awJjVmx-MHQ9SugkSIYXV0Ina77cTNS0M2PYiH1PFRTw==.AQAB"
+ },
+ {
+ "rel": "http://ostatus.org/schema/1.0/subscribe",
+ "template": "https://mastodon.social/authorize_interaction?uri={uri}"
+ }
+ ]
+}