0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-20 22:42:53 -05:00

completely blocked external requests in Webmentions tests (#16186)

no issue
-had timeout issues in test suite
-tests were still doing dns lookup via external request
This commit is contained in:
Steve Larson 2023-01-25 10:43:57 -06:00 committed by GitHub
parent 693db59f73
commit a3064d95cb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,14 +1,34 @@
const MentionDiscoveryService = require('../lib/MentionDiscoveryService');
// non-standard to use externalRequest here, but this is required for the overrides in the libary, which we want to test for security reasons in combination with the package
const sinon = require('sinon');
// non-standard to use externalRequest here, but this is required for the overrides in the library, which we want to test for security reasons in combination with the package
const externalRequest = require('../../core/core/server/lib/request-external.js');
const dnsPromises = require('dns').promises;
const assert = require('assert');
const nock = require('nock');
describe('MentionDiscoveryService', function () {
const service = new MentionDiscoveryService({externalRequest});
beforeEach(function () {
nock.disableNetConnect();
// externalRequest does dns lookup; stub to make sure we don't fail with fake domain names
sinon.stub(dnsPromises, 'lookup').callsFake(function () {
return Promise.resolve({address: '123.123.123.123'});
});
});
afterEach(function () {
sinon.restore();
nock.cleanAll();
});
after(function () {
nock.cleanAll();
nock.enableNetConnect();
});
it('Returns null from a bad URL', async function () {
const url = new URL('http://www.fake.com/');
const url = new URL('http://www.notarealsite.com/');
nock(url.href)
.get('/')
.reply(404);