Skip to content

Node.js based forum software built for the modern web

test(activitypub): stub webfinger requests to avoid 10s DNS timeouts

Julian Lamc5673a2146f2
diff --git a/test/activitypub/sendWorker.js b/test/activitypub/sendWorker.js
index ff1e9da85c..8d13f526e9 100644
--- a/test/activitypub/sendWorker.js
+++ b/test/activitypub/sendWorker.js
@@ -26,14 +26,17 @@ describe('sendWorker', () => {
describe('send task', () => {
it('should emit a result on failed send', async () => {
+ // Use a private IP so the SSRF check rejects it immediately — a
+ // non-resolving hostname (.invalid/.example) triggers a real DNS lookup
+ // that times out at ~10s in CI containers.
const result = await pool.exec('send', [{
id: 'test-task-1',
- uri: 'https://nonexistent.invalid/test',
+ uri: 'http://10.0.0.1/test',
payload: JSON.stringify({ type: 'Create' }),
digest: 'SHA-256=invalid',
key: '-----BEGIN PRIVATE KEY-----\nINVALID\n-----END PRIVATE KEY-----',
keyId: 'https://example.org/actor#key',
- }], { timeout: 10000 });
+ }], { timeout: 5000 });
assert.strictEqual(result.success, false);
});
diff --git a/test/activitypub/split-domain.js b/test/activitypub/split-domain.js
index 65c6631c15..c2319f6629 100644
--- a/test/activitypub/split-domain.js
+++ b/test/activitypub/split-domain.js
@@ -11,6 +11,27 @@ const activitypub = require('../../src/activitypub');
const Helpers = module.exports;
+let originalGet;
+// Stub request.get so tests never perform real DNS/network lookups against
+// non-resolving .example domains (which time out at ~10s in CI containers).
+Helpers.stubRequest = () => {
+ if (originalGet) {
+ return;
+ }
+ originalGet = request.get;
+ request.get = async () => ({
+ body: {},
+ response: { statusCode: 404, headers: { 'content-type': 'application/jrd+json' } },
+ });
+};
+
+Helpers.restoreRequest = () => {
+ if (originalGet) {
+ request.get = originalGet;
+ originalGet = null;
+ }
+};
+
Helpers.genSplitDomain = () => {
const username = `user_${utils.generateUUID().replace(/-/g, '').slice(0, 8)}`;
const domainA = `forum-${utils.generateUUID().replace(/-/g, '').slice(0, 6)}.example`;
@@ -76,7 +97,12 @@ Helpers.reset = () => {
// ============================================================================
describe('helpers.query strictness', () => {
- beforeEach(Helpers.reset);
+ beforeEach(() => {
+ Helpers.reset();
+ Helpers.stubRequest();
+ });
+
+ afterEach(Helpers.restoreRequest);
it('strict query of same-domain subject returns payload with splitDomain: false', async () => {
const { domainA, username, actorUri } = Helpers.genSplitDomain();
@@ -116,7 +142,12 @@ describe('helpers.query strictness', () => {
// ============================================================================
describe('verifyActorWebfinger', () => {
- beforeEach(Helpers.reset);
+ beforeEach(() => {
+ Helpers.reset();
+ Helpers.stubRequest();
+ });
+
+ afterEach(Helpers.restoreRequest);
it('returns split-domain verdict for fully verified actor', async () => {
const { domainA, domainB, username, actorUri } = Helpers.genSplitDomain();
@@ -246,7 +277,12 @@ describe('verifyActorWebfinger', () => {
// ============================================================================
describe('Actors.assert - hostname mismatch', () => {
- beforeEach(Helpers.reset);
+ beforeEach(() => {
+ Helpers.reset();
+ Helpers.stubRequest();
+ });
+
+ afterEach(Helpers.restoreRequest);
it('rejects when queried hostname differs from actor.id hostname (gh#13352)', async () => {
const username = 'alice';