aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2019-01-30 12:34:04 +0300
committerGravatar Vitaly Takmazov2019-01-30 12:34:04 +0300
commit053300c67d2fe274f2f562712d8586e81700c085 (patch)
tree9d04c085cdd00c9731791e8f6400027de9e4c52c /src
parent362d1362797d1736505084f96d34dd287fb22945 (diff)
Corrected flow for federated user deletion
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/juick/server/api/activity/Profile.java17
-rw-r--r--src/test/java/com/juick/server/tests/ServerTests.java14
-rw-r--r--src/test/resources/delete_user.json1
3 files changed, 25 insertions, 7 deletions
diff --git a/src/main/java/com/juick/server/api/activity/Profile.java b/src/main/java/com/juick/server/api/activity/Profile.java
index 84a3de33..b1d325f9 100644
--- a/src/main/java/com/juick/server/api/activity/Profile.java
+++ b/src/main/java/com/juick/server/api/activity/Profile.java
@@ -284,13 +284,6 @@ public class Profile {
return new ResponseEntity<>(HttpStatus.OK);
}
}
- if (activity instanceof Delete) {
- if (activity.getObject() instanceof String) {
- // Delete user
- applicationEventPublisher.publishEvent(new DeleteUserEvent(this, (String)activity.getObject()));
- return new ResponseEntity<>(HttpStatus.OK);
- }
- }
if (activity instanceof Create) {
if (activity.getObject() instanceof Map) {
Map<String, Object> note = (Map<String, Object>) activity.getObject();
@@ -361,6 +354,16 @@ public class Profile {
logger.warn("Unknown activity: {}", jsonMapper.writeValueAsString(activity));
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
}
+ if (activity instanceof Delete) {
+ if (activity.getObject() instanceof String) {
+ // Delete gone user
+ if (activity.getActor().equals(activity.getObject())) {
+ if (signatureManager.getContext(URI.create(activity.getActor())).isEmpty()) {
+ return new ResponseEntity<>(HttpStatus.ACCEPTED);
+ }
+ }
+ }
+ }
return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
}
@PostMapping(value = "/u/", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
diff --git a/src/test/java/com/juick/server/tests/ServerTests.java b/src/test/java/com/juick/server/tests/ServerTests.java
index f1087d8c..7fe39d0d 100644
--- a/src/test/java/com/juick/server/tests/ServerTests.java
+++ b/src/test/java/com/juick/server/tests/ServerTests.java
@@ -117,6 +117,7 @@ import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.StreamSupport;
+import static com.juick.server.api.activity.model.Context.ACTIVITY_MEDIA_TYPE;
import static junit.framework.TestCase.assertTrue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
@@ -124,6 +125,7 @@ import static org.junit.Assert.*;
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.httpBasic;
import static org.springframework.test.web.client.ExpectedCount.times;
import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo;
+import static org.springframework.test.web.client.response.MockRestResponseCreators.withStatus;
import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
@@ -1885,4 +1887,16 @@ public class ServerTests {
tst = jsonMapper.readValue(result.getResponse().getContentAsString(), User.class);
assertThat(tst.getReaders().size(), is(1));
}
+ @Test
+ public void federatedUserDeletionFlow() throws Exception {
+ String deleteJsonStr = IOUtils.toString(new ClassPathResource("delete_user.json").getURI(), StandardCharsets.UTF_8);
+ Delete delete = jsonMapper.readValue(deleteJsonStr, Delete.class);
+ restServiceServer = MockRestServiceServer.bindTo(apClient).build();
+ restServiceServer.expect(times(1), requestTo((String)delete.getObject()))
+ .andRespond(withStatus(HttpStatus.GONE));
+ mockMvc.perform(post("/api/inbox")
+ .contentType(ACTIVITY_MEDIA_TYPE)
+ .content(deleteJsonStr))
+ .andExpect(status().isAccepted());
+ }
}
diff --git a/src/test/resources/delete_user.json b/src/test/resources/delete_user.json
new file mode 100644
index 00000000..b68db011
--- /dev/null
+++ b/src/test/resources/delete_user.json
@@ -0,0 +1 @@
+{"@context":["https://www.w3.org/ns/activitystreams","https://w3id.org/security/v1",{"manuallyApprovesFollowers":"as:manuallyApprovesFollowers","sensitive":"as:sensitive","movedTo":{"@id":"as:movedTo","@type":"@id"},"alsoKnownAs":{"@id":"as:alsoKnownAs","@type":"@id"},"Hashtag":"as:Hashtag","ostatus":"http://ostatus.org#","atomUri":"ostatus:atomUri","inReplyToAtomUri":"ostatus:inReplyToAtomUri","conversation":"ostatus:conversation","toot":"http://joinmastodon.org/ns#","Emoji":"toot:Emoji","focalPoint":{"@container":"@list","@id":"toot:focalPoint"},"featured":{"@id":"toot:featured","@type":"@id"},"schema":"http://schema.org#","PropertyValue":"schema:PropertyValue","value":"schema:value"}],"id":"https://example.com/users/deleted#delete","type":"Delete","actor":"https://example.com/users/deleted","to":["https://www.w3.org/ns/activitystreams#Public"],"object":"https://example.com/users/deleted","signature":{"type":"RsaSignature2017","creator":"https://mastodon.social/users/andoniserra#main-key","created":"2019-01-29T14:50:13Z","signatureValue":"svq8NDQeXb0widXDL1jygye+a536L4GFPTT+8euXgdHhzij6y5dIpT+s0I0ZheAIfHEe+k3N5XysQMvJ4Jmh8douWZ14DkZNai5luk4Ftg5v/RynYAY65UgsldTf9XUvAbSiRGAK4s2b8qE3zsQihEHRIUrzb2bgvhKUkr8FuuuNDDDSS9i9bxnzQp8DSVivqdW2zJYm3ARtW7sWKSXoSaiP2KxIfRPC6UdDDSFbRr3zHckxRjsPnfWr8VvhjxggzVYcp4ZIJDqJj0qoy1lyRIRTWaDJwZIjFX7JjE5OVoKBt++IcY6IARpTGVxV4GXeeFMB7/y1tMaZoold6VlqyQ=="}} \ No newline at end of file