test: log outgoing AP messages for local test runner

This commit is contained in:
Julian Lam
2025-02-28 13:56:33 -05:00
parent 73aaa990fb
commit 6e872b5fe4
2 changed files with 17 additions and 0 deletions

View File

@@ -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: {

View File

@@ -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;