diff options
author | Vitaly Takmazov | 2021-08-22 10:57:02 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2021-08-22 10:57:02 +0300 |
commit | d918967281652ead0130c5dbef663e82003d4393 (patch) | |
tree | b4bdd09ee9a2f86e0aae7ee6cdf21672a2f0fd31 /src/test/java/com/juick/server/tests | |
parent | 1d395b762746948c4ba9897c0ff1e5be0aaaf6db (diff) |
ActivityPub: handle user deletion for suspended users
Diffstat (limited to 'src/test/java/com/juick/server/tests')
-rw-r--r-- | src/test/java/com/juick/server/tests/ServerTests.java | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/src/test/java/com/juick/server/tests/ServerTests.java b/src/test/java/com/juick/server/tests/ServerTests.java index 2f60f5be..db1449f2 100644 --- a/src/test/java/com/juick/server/tests/ServerTests.java +++ b/src/test/java/com/juick/server/tests/ServerTests.java @@ -48,6 +48,7 @@ import com.juick.www.api.webfinger.model.Account; import com.juick.www.api.xnodeinfo2.model.NodeInfo; import com.juick.www.WebApp; import com.juick.service.*; +import com.juick.service.activities.DeleteUserEvent; import com.juick.service.activities.UpdateEvent; import com.juick.service.component.SystemEvent; import com.juick.test.util.MockUtils; @@ -229,6 +230,10 @@ public class ServerTests { private Resource testappResponse; @Value("classpath:snapshots/activity/testfollow.json") private Resource testfollowRequest; + @Value("classpath:snapshots/activity/testdelete.json") + private Resource testDeleteRequest; + @Value("classpath:snapshots/activity/test_suspended_user.json") + private Resource testSuspendedUserResponse; @Value("classpath:snapshots/email/subscription.html") private Resource testSubscriptionHtmlEmail; @Value("classpath:snapshots/email/private.html") @@ -2077,7 +2082,7 @@ public class ServerTests { } @Test - public void federatedUserDeletionFlow() throws Exception { + public void federatedUserDeletionFlowWhenItIsGone() throws Exception { String deleteJsonStr = IOUtils.toString(new ClassPathResource("delete_user.json").getURI(), StandardCharsets.UTF_8); Delete delete = jsonMapper.readValue(deleteJsonStr, Delete.class); @@ -2096,6 +2101,39 @@ public class ServerTests { apClient.setRequestFactory(originalRequestFactory); } + @MockBean + private MockDeleteListener deleteListener; + @Captor + protected ArgumentCaptor<DeleteUserEvent> deleteEventCaptor; + + @Test + public void federatedUserDeletionFlowWhenItIsSuspended() throws Exception { + String deleteJsonStr = IOUtils.toString(testDeleteRequest.getInputStream(), StandardCharsets.UTF_8); + Delete delete = jsonMapper.readValue(deleteJsonStr, Delete.class); + ClientHttpRequestFactory originalRequestFactory = apClient.getRequestFactory(); + MockRestServiceServer restServiceServer = MockRestServiceServer.createServer(apClient); + restServiceServer.expect(times(2), requestTo(delete.getObject().getId())) + .andRespond(withSuccess(IOUtils.toString(testSuspendedUserResponse.getInputStream(), StandardCharsets.UTF_8), MediaType.APPLICATION_JSON)); + Person testuser = (Person) signatureManager.getContext(URI.create(delete.getObject().getId())).get(); + Instant now = Instant.now(); + String testRequestDate = DateFormattersHolder.getHttpDateFormatter().format(now); + String inboxUri = "/api/inbox"; + byte[] digest = MessageDigest.getInstance("SHA-256").digest(deleteJsonStr.getBytes()); + String digestHeader = "SHA-256=" + new String(Base64.encodeBase64(digest)); + String testSignatureString = signatureManager.addSignature(testuser, "localhost", "POST", inboxUri, + testRequestDate, digestHeader, testKeystoreManager); + mockMvc.perform(post(inboxUri).contentType(ACTIVITY_MEDIA_TYPE).content(deleteJsonStr) + .header("Host", "localhost") + .header("Date", testRequestDate) + .header("Digest", digestHeader) + .header("Signature", testSignatureString)) + .andExpect(status().isAccepted()); + apClient.setRequestFactory(originalRequestFactory); + Mockito.verify(deleteListener, Mockito.times(1)).onApplicationEvent(deleteEventCaptor.capture()); + DeleteUserEvent receivedEvent = deleteEventCaptor.getValue(); + assertThat(receivedEvent.getUserUri(), is(testuser.getId())); + } + @Test @Order(2) public void handleIncorrectCertificates() throws Exception { |