diff options
author | Vitaly Takmazov | 2021-08-20 12:20:03 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2021-08-20 12:20:03 +0300 |
commit | 6bd8371f8629bba8edaeb10e2648a5cf0177cd2b (patch) | |
tree | e2b9dc3d47bd2e1b922f0a481127c2373487d63c /src/test | |
parent | bab10770a77f5f756a58c4ca6f19dd51e1b492ee (diff) |
ActivityPub: Handle Flag activity
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/java/com/juick/server/tests/ServerTests.java | 23 | ||||
-rw-r--r-- | src/test/resources/flag.json | 1 |
2 files changed, 20 insertions, 4 deletions
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); } diff --git a/src/test/resources/flag.json b/src/test/resources/flag.json new file mode 100644 index 00000000..eae0d15f --- /dev/null +++ b/src/test/resources/flag.json @@ -0,0 +1 @@ +{"@context":"https://www.w3.org/ns/activitystreams","id":"https://localhost/32ac2d3e-c75c-46c1-b0a7-d9fac0986b9a","type":"Flag","actor":"https://example.com/u/testuser","content":"","object":["https://juick.com/u/rtfmpls","https://juick.com/n/2998271-0"]}
\ No newline at end of file |