aboutsummaryrefslogtreecommitdiff
path: root/src
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
parentbab10770a77f5f756a58c4ca6f19dd51e1b492ee (diff)
ActivityPub: Handle Flag activity
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/juick/www/api/activity/Profile.java6
-rw-r--r--src/main/java/com/juick/www/api/activity/model/Context.java1
-rw-r--r--src/main/java/com/juick/www/api/activity/model/activities/Flag.java24
-rw-r--r--src/test/java/com/juick/server/tests/ServerTests.java23
-rw-r--r--src/test/resources/flag.json1
5 files changed, 51 insertions, 4 deletions
diff --git a/src/main/java/com/juick/www/api/activity/Profile.java b/src/main/java/com/juick/www/api/activity/Profile.java
index e261c2e8..72cc849e 100644
--- a/src/main/java/com/juick/www/api/activity/Profile.java
+++ b/src/main/java/com/juick/www/api/activity/Profile.java
@@ -30,6 +30,7 @@ import com.juick.www.api.activity.model.Context;
import com.juick.www.api.activity.model.activities.Announce;
import com.juick.www.api.activity.model.activities.Create;
import com.juick.www.api.activity.model.activities.Delete;
+import com.juick.www.api.activity.model.activities.Flag;
import com.juick.www.api.activity.model.activities.Follow;
import com.juick.www.api.activity.model.activities.Like;
import com.juick.www.api.activity.model.activities.Undo;
@@ -401,6 +402,11 @@ public class Profile {
applicationEventPublisher.publishEvent(new AnnounceEvent(this, activity.getActor(), messageUri));
return new ResponseEntity<>(CommandResult.fromString("Like/announce request accepted"), HttpStatus.OK);
}
+ if (activity instanceof Flag) {
+ URI actor = URI.create(activity.getActor());
+ logger.info("{} flag some objects: {}", actor, activity.getObject());
+ return new ResponseEntity<>(CommandResult.fromString("Report accepted"), HttpStatus.ACCEPTED);
+ }
logger.warn("Unknown activity: {}", jsonMapper.writeValueAsString(activity));
return new ResponseEntity<>(CommandResult.fromString("Unknown activity"), HttpStatus.NOT_IMPLEMENTED);
}
diff --git a/src/main/java/com/juick/www/api/activity/model/Context.java b/src/main/java/com/juick/www/api/activity/model/Context.java
index e75f2440..5d945749 100644
--- a/src/main/java/com/juick/www/api/activity/model/Context.java
+++ b/src/main/java/com/juick/www/api/activity/model/Context.java
@@ -35,6 +35,7 @@ import java.util.List;
@JsonSubTypes.Type(value = Create.class, name = "Create"),
@JsonSubTypes.Type(value = Update.class, name = "Update"),
@JsonSubTypes.Type(value = Delete.class, name = "Delete"),
+ @JsonSubTypes.Type(value = Flag.class, name = "Flag"),
@JsonSubTypes.Type(value = Follow.class, name = "Follow"),
@JsonSubTypes.Type(value = Accept.class, name = "Accept"),
@JsonSubTypes.Type(value = Undo.class, name = "Undo"),
diff --git a/src/main/java/com/juick/www/api/activity/model/activities/Flag.java b/src/main/java/com/juick/www/api/activity/model/activities/Flag.java
new file mode 100644
index 00000000..2c61d344
--- /dev/null
+++ b/src/main/java/com/juick/www/api/activity/model/activities/Flag.java
@@ -0,0 +1,24 @@
+/*
+ * Copyright (C) 2008-2021, Juick
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package com.juick.www.api.activity.model.activities;
+
+import com.juick.www.api.activity.model.Activity;
+
+public class Flag extends Activity {
+
+}
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