fix: tests for public and private note assertion, failing test for private note assertion with missing cc prop

This commit is contained in:
Julian Lam
2025-02-26 12:29:36 -05:00
parent 51872d5435
commit efb27ce0ac

View File

@@ -1,70 +1,78 @@
'use strict'; 'use strict';
const assert = require('assert'); const assert = require('assert');
const nconf = require('nconf');
const db = require('../../src/database'); const db = require('../../src/database');
const meta = require('../../src/meta'); const meta = require('../../src/meta');
const install = require('../../src/install'); const install = require('../../src/install');
const user = require('../../src/user'); const user = require('../../src/user');
const categories = require('../../src/categories'); const categories = require('../../src/categories');
const posts = require('../../src/posts');
const topics = require('../../src/topics'); const topics = require('../../src/topics');
const activitypub = require('../../src/activitypub'); const activitypub = require('../../src/activitypub');
const utils = require('../../src/utils'); const utils = require('../../src/utils');
const helpers = require('./helpers');
describe('Notes', () => { describe('Notes', () => {
describe('Assertion', () => { describe('Assertion', () => {
const baseUrl = 'https://example.org';
before(async () => { before(async () => {
meta.config.activitypubEnabled = 1; meta.config.activitypubEnabled = 1;
await install.giveWorldPrivileges(); await install.giveWorldPrivileges();
}); });
it('should pull a remote root-level object by its id and create a new topic', async () => { describe('Public objects', () => {
const uuid = utils.generateUUID(); it('should pull a remote root-level object by its id and create a new topic', async () => {
const id = `${baseUrl}/resource/${uuid}`; const { id } = helpers.mocks.note();
activitypub._cache.set(`0;${id}`, { const { tid, count } = await activitypub.notes.assert(0, id, { skipChecks: true });
'@context': 'https://www.w3.org/ns/activitystreams', assert.strictEqual(count, 1);
id,
url: id, const exists = await topics.exists(tid);
type: 'Note', assert(exists);
to: ['https://www.w3.org/ns/activitystreams#Public'],
cc: ['https://example.org/user/foobar/followers'],
inReplyTo: null,
attributedTo: 'https://example.org/user/foobar',
name: 'Foo Bar',
content: '<b>Baz quux</b>',
published: new Date().toISOString(),
}); });
const { tid, count } = await activitypub.notes.assert(0, id, { skipChecks: true }); it('should assert if the cc property is missing', async () => {
assert.strictEqual(count, 1); const { id } = helpers.mocks.note({ cc: 'remove' });
const { tid, count } = await activitypub.notes.assert(0, id, { skipChecks: true });
assert.strictEqual(count, 1);
const exists = await topics.exists(tid); const exists = await topics.exists(tid);
assert(exists); assert(exists);
});
}); });
it('should assert if the cc property is missing', async () => { describe('Private objects', () => {
const uuid = utils.generateUUID(); let recipientUid;
const id = `${baseUrl}/resource/${uuid}`;
activitypub._cache.set(`0;${id}`, { before(async () => {
'@context': 'https://www.w3.org/ns/activitystreams', recipientUid = await user.create({ username: utils.generateUUID().slice(0, 8) });
id,
url: id,
type: 'Note',
to: ['https://www.w3.org/ns/activitystreams#Public'],
inReplyTo: null,
attributedTo: 'https://example.org/user/foobar',
name: 'Foo Bar',
content: '<b>Baz quux</b>',
published: new Date().toISOString(),
}); });
const { tid, count } = await activitypub.notes.assert(0, id, { skipChecks: true }); it('should NOT create a new topic or post when asserting a private note', async () => {
assert.strictEqual(count, 1); const { id, note } = helpers.mocks.note({
to: [`${nconf.get('url')}/uid/${recipientUid}`],
cc: [],
});
const { activity } = helpers.mocks.create(note);
const { roomId } = await activitypub.inbox.create({ body: activity });
assert(roomId);
assert(utils.isNumber(roomId));
const exists = await topics.exists(tid); const exists = await posts.exists(id);
assert(exists); assert(!exists);
});
it('should still assert if the cc property is missing', async () => {
const { id, note } = helpers.mocks.note({
to: [`${nconf.get('url')}/uid/${recipientUid}`],
cc: 'remove',
});
const { activity } = helpers.mocks.create(note);
const { roomId } = await activitypub.inbox.create({ body: activity });
assert(roomId);
assert(utils.isNumber(roomId));
});
}); });
}); });