diff options
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 f8e0f6a82..5b98c41aa 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 000000000..eae0d15f8 --- /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 |