From 389e29881724b90daa466247aef1b8a164511bb9 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Sat, 21 Aug 2021 03:49:12 +0300 Subject: ActivityPub: add Application as an actor type --- src/test/java/com/juick/server/tests/ServerTests.java | 18 ++++++++++++++---- src/test/resources/flag.json | 2 +- src/test/resources/snapshots/activity/testapp.json | 13 +++++++++++++ 3 files changed, 28 insertions(+), 5 deletions(-) create mode 100644 src/test/resources/snapshots/activity/testapp.json (limited to 'src/test') diff --git a/src/test/java/com/juick/server/tests/ServerTests.java b/src/test/java/com/juick/server/tests/ServerTests.java index 5b98c41a..e25f0b0d 100644 --- a/src/test/java/com/juick/server/tests/ServerTests.java +++ b/src/test/java/com/juick/server/tests/ServerTests.java @@ -39,6 +39,7 @@ import com.juick.www.api.Users; import com.juick.www.api.activity.Profile; import com.juick.www.api.activity.model.Context; import com.juick.www.api.activity.model.activities.*; +import com.juick.www.api.activity.model.objects.Application; import com.juick.www.api.activity.model.objects.Note; import com.juick.www.api.activity.model.objects.Person; import com.juick.www.api.webfinger.model.Account; @@ -222,6 +223,8 @@ public class ServerTests { @Value("classpath:snapshots/activity/testuser.json") private Resource testuserResponse; + @Value("classpath:snapshots/activity/testapp.json") + private Resource testappResponse; @Value("classpath:snapshots/activity/testfollow.json") private Resource testfollowRequest; @Value("classpath:snapshots/email/subscription.html") @@ -1869,14 +1872,19 @@ public class ServerTests { User meUser = jsonMapper.readValue(me.getResponse().getContentAsString(), User.class); assertThat(meUser, is(ugnich)); String testuserResponseString = IOUtils.toString(testuserResponse.getInputStream(), StandardCharsets.UTF_8); + String testappResponseString = IOUtils.toString(testappResponse.getInputStream(), StandardCharsets.UTF_8); ClientHttpRequestFactory originalRequestFactory = apClient.getRequestFactory(); URI testuserUri = URI.create("https://example.com/u/testuser"); URI testuserkeyUri = URI.create("https://example.com/u/testuser#main-key"); + URI testAppUri = URI.create("https://example.com/actor"); + URI testAppkeyUri = URI.create("https://example.com/actor#main-key"); MockRestServiceServer restServiceServer = MockRestServiceServer.createServer(apClient); - restServiceServer.expect(times(5), requestTo(testuserUri)) + restServiceServer.expect(times(4), requestTo(testuserUri)) .andRespond(withSuccess(testuserResponseString, MediaType.APPLICATION_JSON)); - restServiceServer.expect(times(5), requestTo(testuserkeyUri)) + restServiceServer.expect(times(4), requestTo(testuserkeyUri)) .andRespond(withSuccess(testuserResponseString, MediaType.APPLICATION_JSON)); + restServiceServer.expect(times(2), requestTo(testAppUri)) + .andRespond(withSuccess(testappResponseString, MediaType.APPLICATION_JSON)); Person testuser = (Person) signatureManager.getContext(testuserUri).get(); assertThat(testuser.getPublicKey().getPublicKeyPem(), is(testKeystoreManager.getPublicKeyPem())); Instant now2 = Instant.now(); @@ -1897,13 +1905,15 @@ 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 + // test flagging as application 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, + Application testapp = (Application) signatureManager.getContext(testAppUri).get(); + assertThat(testapp.getPublicKey().getPublicKeyPem(), is(testKeystoreManager.getPublicKeyPem())); + testSignatureString = signatureManager.addSignature(testapp, "localhost", "POST", inboxUri, testRequestDate, digestHeader, testKeystoreManager); mockMvc.perform(post(inboxUri).header("Host", testHost).header("Date", testRequestDate) .header("Signature", testSignatureString) diff --git a/src/test/resources/flag.json b/src/test/resources/flag.json index eae0d15f..c3363f01 100644 --- a/src/test/resources/flag.json +++ b/src/test/resources/flag.json @@ -1 +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 +{"@context":"https://www.w3.org/ns/activitystreams","id":"https://localhost/32ac2d3e-c75c-46c1-b0a7-d9fac0986b9a","type":"Flag","actor":"https://example.com/actor","content":"","object":["https://juick.com/u/rtfmpls","https://juick.com/n/2998271-0"]} \ No newline at end of file diff --git a/src/test/resources/snapshots/activity/testapp.json b/src/test/resources/snapshots/activity/testapp.json new file mode 100644 index 00000000..d1c2289e --- /dev/null +++ b/src/test/resources/snapshots/activity/testapp.json @@ -0,0 +1,13 @@ +{ + "@context": [ + "https://www.w3.org/ns/activitystreams", + "https://w3id.org/security/v1" + ], + "id": "https://example.com/actor", + "type": "Application", + "publicKey": { + "id": "https://example.com/actor#main-key", + "owner": "https://example.com/actor", + "publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAiHKRdKFFeT4P/MVlNbxC\nbbgXOkEdeQzvJB/wAJgSYbUwm9SzNFzttePQXk3/MWoK2awWUInZTduVHsWt8zU7\nO3d9PAW6YH6L1oDkjgMLAb9aUWV2ClQWMwsn88WKK9Rb1WOmd8BrXjPfmeFK2ypQ\n9eg8aKpH36WAXiiaTDfBupBZ0Ki2+E87BrWxpbUeDC1dkV+zbl8BMm7X0rp+reoC\nYUWMcjQMzhMmQOXUd4zwJIDPZDMdF4beq/y6WPSUTVgjs4kPDS1HT60ATnsUqyPE\n6tuGxG4j0msb4TTre87PKxMU5YPOxSiqNL0O/3u9/2shVPpjDa/uy9W+VaeBHbFm\nSQIDAQAB\n-----END PUBLIC KEY-----\n" + } +} -- cgit v1.2.3