From 59709a3cb20d87a0afe956f2caa26d924479aa00 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Wed, 3 Apr 2024 13:49:27 -0400 Subject: [PATCH] fix: tests, save actor URL into userRemote hash --- src/activitypub/mocks.js | 3 ++- src/activitypub/notes.js | 2 +- test/activitypub.js | 45 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 2 deletions(-) diff --git a/src/activitypub/mocks.js b/src/activitypub/mocks.js index a0519d1642..14a1017751 100644 --- a/src/activitypub/mocks.js +++ b/src/activitypub/mocks.js @@ -25,7 +25,7 @@ Mocks.profile = async (actors) => { const uid = actor.id; let { - preferredUsername, published, icon, image, + url, preferredUsername, published, icon, image, name, summary, followerCount, followingCount, postcount, inbox, endpoints, } = actor; @@ -59,6 +59,7 @@ Mocks.profile = async (actors) => { followerCount, followingCount, + url, inbox, sharedInbox: endpoints ? endpoints.sharedInbox : null, }; diff --git a/src/activitypub/notes.js b/src/activitypub/notes.js index 5604ecff3a..0a7af2e4f3 100644 --- a/src/activitypub/notes.js +++ b/src/activitypub/notes.js @@ -185,7 +185,7 @@ async function assertRelation(post) { // Local user is mentioned const { tag } = post._activitypub; let uids = []; - if (tag.length) { + if (tag && tag.length) { const slugs = tag.reduce((slugs, tag) => { if (tag.type === 'Mention') { const [slug, hostname] = tag.name.slice(1).split('@'); diff --git a/test/activitypub.js b/test/activitypub.js index 55aa288139..6270504785 100644 --- a/test/activitypub.js +++ b/test/activitypub.js @@ -477,6 +477,7 @@ describe('ActivityPub integration', () => { activitypub._cache.set(`0;${id}`, remoteNote); activitypub._cache.set(`0;https://example.org/user/foobar`, remoteUser); + await db.sortedSetAdd(`followersRemote:${remoteUser.id}`, Date.now(), 1); // fake a follow await controllers.activitypub.postInbox({ body: { type: 'Create', @@ -561,4 +562,48 @@ describe('ActivityPub integration', () => { }); }); }); + + describe('Actor asserton', () => { + let uid; + let actorUri; + + before(async () => { + uid = utils.generateUUID().slice(0, 8); + actorUri = `https://example.org/user/${uid}`; + activitypub._cache.set(`0;${actorUri}`, { + '@context': 'https://www.w3.org/ns/activitystreams', + id: actorUri, + url: actorUri, + + type: 'Person', + name: 'example', + preferredUsername: 'example', + + publicKey: { + id: `${actorUri}#key`, + owner: actorUri, + publicKeyPem: 'somekey', + }, + }); + }); + + it('should return true if successfully asserted', async () => { + const result = await activitypub.actors.assert([actorUri]); + assert(result); + }); + + it('should contain a representation of that remote user in the database', async () => { + const exists = await db.exists(`userRemote:${actorUri}`); + assert(exists); + + const userData = await user.getUserData(actorUri); + assert(userData); + assert.strictEqual(userData.uid, actorUri); + }); + + it('should save the actor\'s publicly accessible URL in the hash as well', async () => { + const url = await user.getUserField(actorUri, 'url'); + assert.strictEqual(url, actorUri); + }); + }); });