Skip to content

Node.js based forum software built for the modern web

test: log outgoing AP messages for local test runner

Julian Lam6e872b5fe411
diff --git a/src/activitypub/index.js b/src/activitypub/index.js
index 8472a552ac..3dd5aad134 100644
--- a/src/activitypub/index.js
+++ b/src/activitypub/index.js
@@ -48,6 +48,7 @@ ActivityPub._constants = Object.freeze({
},
});
ActivityPub._cache = requestCache;
+ActivityPub._sent = new Map(); // used only in local tests
ActivityPub.helpers = require('./helpers');
ActivityPub.inbox = require('./inbox');
@@ -335,7 +336,12 @@ pubsub.on(`activitypub-retry-queue:lruCache:del`, (keys) => {
async function sendMessage(uri, id, type, payload, attempts = 1) {
const keyData = await ActivityPub.getPrivateKey(type, id);
const headers = await ActivityPub.sign(keyData, uri, payload);
+
ActivityPub.helpers.log(`[activitypub/send] ${uri}`);
+ if (process.env.CI === 'true') {
+ ActivityPub._sent.set(payload.id, payload);
+ }
+
try {
const { response, body } = await request.post(uri, {
headers: {
diff --git a/test/activitypub.js b/test/activitypub.js
index 57942ffe72..16642afa2c 100644
--- a/test/activitypub.js
+++ b/test/activitypub.js
@@ -21,6 +21,7 @@ const activitypub = require('../src/activitypub');
describe('ActivityPub integration', () => {
before(async () => {
meta.config.activitypubEnabled = 1;
+ meta.config.activitypubAllowLoopback = 1;
await install.giveWorldPrivileges();
});
@@ -28,6 +29,16 @@ describe('ActivityPub integration', () => {
delete meta.config.activitypubEnabled;
});
+ describe.only('Outgoing AP logging for test runner', () => {
+ it('should log an entry in ActivityPub._sent when .send is called', async () => {
+ const uuid = utils.generateUUID();
+ const uid = await user.create({ username: uuid });
+ await activitypub.send('uid', 0, [`https://localhost/uid/${uid}`], { id: `${nconf.get('url')}/activity/${uuid}`, foo: 'bar' });
+
+ assert(activitypub._sent.has(`https://localhost/activity/${uuid}`));
+ });
+ });
+
describe('Master toggle', () => {
before(async () => {
delete meta.config.activitypubEnabled;