Skip to content

Node.js based forum software built for the modern web

fix(activitypub): return 404 for soft-deleted topics

Julian Lamca48534ebd1e
diff --git a/src/controllers/activitypub/actors.js b/src/controllers/activitypub/actors.js
index 1d69f4a5a7..4a03ebb942 100644
--- a/src/controllers/activitypub/actors.js
+++ b/src/controllers/activitypub/actors.js
@@ -150,12 +150,16 @@ Actors.topic = async function (req, res, next) {
const page = parseInt(req.query.page, 10) || undefined;
const perPage = meta.config.postsPerPage;
- const { cid, title: name, mainPid, slug, timestamp } = await topics.getTopicFields(req.params.tid, ['cid', 'title', 'mainPid', 'slug', 'timestamp']);
+ const { cid, title: name, mainPid, slug, timestamp, deleted } = await topics.getTopicFields(req.params.tid, ['cid', 'title', 'mainPid', 'slug', 'timestamp', 'deleted']);
try {
if (timestamp > Date.now()) { // Scheduled topic, no response
return next();
}
+ if (deleted) { // Soft-deleted topic, no response
+ return res.sendStatus(404);
+ }
+
let collection;
let pids;
try {
diff --git a/test/activitypub/actors.js b/test/activitypub/actors.js
index 249f1ce60f..f72e1ad6ce 100644
--- a/test/activitypub/actors.js
+++ b/test/activitypub/actors.js
@@ -9,6 +9,7 @@ const install = require('../../src/install');
const categories = require('../../src/categories');
const user = require('../../src/user');
const topics = require('../../src/topics');
+const posts = require('../../src/posts');
const activitypub = require('../../src/activitypub');
const utils = require('../../src/utils');
const request = require('../../src/request');
@@ -714,6 +715,34 @@ describe('Controllers', () => {
assert.strictEqual(response.statusCode, 404);
});
});
+
+ describe('Soft deleted', () => {
+ let topicData;
+ let response;
+ let body;
+
+ before(async () => {
+ ({ topicData } = await topics.post({
+ uid,
+ cid,
+ title: 'Lorem "Lipsum" Ipsum',
+ content: 'Lorem ipsum dolor sit amet',
+ }));
+
+ await topics.delete(topicData.tid, uid);
+
+ ({ response, body } = await request.get(`${nconf.get('url')}/topic/${topicData.slug}`, {
+ headers: {
+ Accept: 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"',
+ },
+ }));
+ });
+
+ it('should respond with a 404 Not Found', async () => {
+ assert(response);
+ assert.strictEqual(response.statusCode, 404);
+ });
+ });
});
describe('Post Object endpoint', () => {