From 6bd8371f8629bba8edaeb10e2648a5cf0177cd2b Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Fri, 20 Aug 2021 12:20:03 +0300 Subject: ActivityPub: Handle Flag activity --- .../java/com/juick/server/tests/ServerTests.java | 23 ++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'src/test/java') diff --git a/src/test/java/com/juick/server/tests/ServerTests.java b/src/test/java/com/juick/server/tests/ServerTests.java index f8e0f6a8..5b98c41a 100644 --- a/src/test/java/com/juick/server/tests/ServerTests.java +++ b/src/test/java/com/juick/server/tests/ServerTests.java @@ -250,6 +250,8 @@ public class ServerTests { private Resource invisiblePixel; @Value("classpath:sape.xml") private Resource sapeOutput; + @Value("classpath:flag.json") + private Resource flagPayload; @Inject AppleClientSecretGenerator clientSecretGenerator; @Inject @@ -1871,9 +1873,9 @@ public class ServerTests { URI testuserUri = URI.create("https://example.com/u/testuser"); URI testuserkeyUri = URI.create("https://example.com/u/testuser#main-key"); MockRestServiceServer restServiceServer = MockRestServiceServer.createServer(apClient); - restServiceServer.expect(times(4), requestTo(testuserUri)) + restServiceServer.expect(times(5), requestTo(testuserUri)) .andRespond(withSuccess(testuserResponseString, MediaType.APPLICATION_JSON)); - restServiceServer.expect(times(4), requestTo(testuserkeyUri)) + restServiceServer.expect(times(5), requestTo(testuserkeyUri)) .andRespond(withSuccess(testuserResponseString, MediaType.APPLICATION_JSON)); Person testuser = (Person) signatureManager.getContext(testuserUri).get(); assertThat(testuser.getPublicKey().getPublicKeyPem(), is(testKeystoreManager.getPublicKeyPem())); @@ -1881,8 +1883,8 @@ public class ServerTests { String testRequestDate = DateFormattersHolder.getHttpDateFormatter().format(now2); String inboxUri = "/api/inbox"; var payload = IOUtils.toByteArray(testfollowRequest.getInputStream()); - final byte[] digest = MessageDigest.getInstance("SHA-256").digest(payload); // (1) - final String digestHeader = "SHA-256=" + new String(Base64.encodeBase64(digest)); + byte[] digest = MessageDigest.getInstance("SHA-256").digest(payload); // (1) + String digestHeader = "SHA-256=" + new String(Base64.encodeBase64(digest)); String testSignatureString = signatureManager.addSignature(testuser, testHost, "POST", inboxUri, testRequestDate, digestHeader, testKeystoreManager); mockMvc.perform(post(inboxUri).header("Host", testHost).header("Date", testRequestDate) @@ -1895,6 +1897,19 @@ public class ServerTests { mockMvc.perform(post(inboxUri).header("Host", testHost).header("Date", testRequestDate) .header("Signature", testSignatureString).contentType(Context.LD_JSON_MEDIA_TYPE).content(payload)) .andExpect(status().isUnauthorized()); + // test flagging + payload = IOUtils.toByteArray(flagPayload.getInputStream()); + digest = MessageDigest.getInstance("SHA-256").digest(payload); // (1) + digestHeader = "SHA-256=" + new String(Base64.encodeBase64(digest)); + now2 = Instant.now(); + testRequestDate = DateFormattersHolder.getHttpDateFormatter().format(now2); + testSignatureString = signatureManager.addSignature(testuser, "localhost", "POST", inboxUri, testRequestDate, + digestHeader, testKeystoreManager); + mockMvc.perform(post(inboxUri).header("Host", testHost).header("Date", testRequestDate) + .header("Signature", testSignatureString) + .header("Digest", digestHeader) + .contentType(Context.LD_JSON_MEDIA_TYPE).content(payload)) + .andExpect(status().isAccepted()); apClient.setRequestFactory(originalRequestFactory); } -- cgit v1.2.3