aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/com/juick/server
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2021-08-20 12:20:03 +0300
committerGravatar Vitaly Takmazov2021-08-20 12:20:03 +0300
commit6bd8371f8629bba8edaeb10e2648a5cf0177cd2b (patch)
treee2b9dc3d47bd2e1b922f0a481127c2373487d63c /src/test/java/com/juick/server
parentbab10770a77f5f756a58c4ca6f19dd51e1b492ee (diff)
ActivityPub: Handle Flag activity
Diffstat (limited to 'src/test/java/com/juick/server')
-rw-r--r--src/test/java/com/juick/server/tests/ServerTests.java23
1 files changed, 19 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);
}