mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 11:05:54 +01:00 
			
		
		
		
	Merge branch 'master' into develop
This commit is contained in:
		| @@ -36,7 +36,7 @@ inbox.create = async (req) => { | |||||||
| 	const { object } = req.body; | 	const { object } = req.body; | ||||||
|  |  | ||||||
| 	// Alternative logic for non-public objects | 	// Alternative logic for non-public objects | ||||||
| 	const isPublic = [...object.to, ...object.cc].includes(activitypub._constants.publicAddress); | 	const isPublic = [...(object.to || []), ...(object.cc || [])].includes(activitypub._constants.publicAddress); | ||||||
| 	if (!isPublic) { | 	if (!isPublic) { | ||||||
| 		return await activitypub.notes.assertPrivate(object); | 		return await activitypub.notes.assertPrivate(object); | ||||||
| 	} | 	} | ||||||
|   | |||||||
| @@ -234,7 +234,7 @@ Notes.assertPrivate = async (object) => { | |||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	const localUids = []; | 	const localUids = []; | ||||||
| 	const recipients = new Set([...object.to, ...object.cc]); | 	const recipients = new Set([...(object.to || []), ...(object.cc || [])]); | ||||||
| 	await Promise.all(Array.from(recipients).map(async (value) => { | 	await Promise.all(Array.from(recipients).map(async (value) => { | ||||||
| 		const { type, id } = await activitypub.helpers.resolveLocalId(value); | 		const { type, id } = await activitypub.helpers.resolveLocalId(value); | ||||||
| 		if (type === 'user') { | 		if (type === 'user') { | ||||||
|   | |||||||
| @@ -1,42 +1,30 @@ | |||||||
| '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(); | ||||||
| 		}); | 		}); | ||||||
|  |  | ||||||
|  | 		describe('Public objects', () => { | ||||||
| 			it('should pull a remote root-level object by its id and create a new topic', async () => { | 			it('should pull a remote root-level object by its id and create a new topic', async () => { | ||||||
| 			const uuid = utils.generateUUID(); | 				const { id } = helpers.mocks.note(); | ||||||
| 			const id = `${baseUrl}/resource/${uuid}`; |  | ||||||
| 			activitypub._cache.set(`0;${id}`, { |  | ||||||
| 				'@context': 'https://www.w3.org/ns/activitystreams', |  | ||||||
| 				id, |  | ||||||
| 				url: id, |  | ||||||
| 				type: 'Note', |  | ||||||
| 				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 }); | 				const { tid, count } = await activitypub.notes.assert(0, id, { skipChecks: true }); | ||||||
| 				assert.strictEqual(count, 1); | 				assert.strictEqual(count, 1); | ||||||
|  |  | ||||||
| @@ -45,21 +33,7 @@ describe('Notes', () => { | |||||||
| 			}); | 			}); | ||||||
|  |  | ||||||
| 			it('should assert if the cc property is missing', async () => { | 			it('should assert if the cc property is missing', async () => { | ||||||
| 			const uuid = utils.generateUUID(); | 				const { id } = helpers.mocks.note({ cc: 'remove' }); | ||||||
| 			const id = `${baseUrl}/resource/${uuid}`; |  | ||||||
| 			activitypub._cache.set(`0;${id}`, { |  | ||||||
| 				'@context': 'https://www.w3.org/ns/activitystreams', |  | ||||||
| 				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 }); | 				const { tid, count } = await activitypub.notes.assert(0, id, { skipChecks: true }); | ||||||
| 				assert.strictEqual(count, 1); | 				assert.strictEqual(count, 1); | ||||||
|  |  | ||||||
| @@ -68,6 +42,40 @@ describe('Notes', () => { | |||||||
| 			}); | 			}); | ||||||
| 		}); | 		}); | ||||||
|  |  | ||||||
|  | 		describe('Private objects', () => { | ||||||
|  | 			let recipientUid; | ||||||
|  |  | ||||||
|  | 			before(async () => { | ||||||
|  | 				recipientUid = await user.create({ username: utils.generateUUID().slice(0, 8) }); | ||||||
|  | 			}); | ||||||
|  |  | ||||||
|  | 			it('should NOT create a new topic or post when asserting a private note', async () => { | ||||||
|  | 				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 posts.exists(id); | ||||||
|  | 				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)); | ||||||
|  | 			}); | ||||||
|  | 		}); | ||||||
|  | 	}); | ||||||
|  |  | ||||||
| 	describe('Inbox Synchronization', () => { | 	describe('Inbox Synchronization', () => { | ||||||
| 		let cid; | 		let cid; | ||||||
| 		let uid; | 		let uid; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user