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:
parent
693db59f73
commit
a3064d95cb
1 changed files with 22 additions and 2 deletions
|
@ -1,14 +1,34 @@
|
||||||
const MentionDiscoveryService = require('../lib/MentionDiscoveryService');
|
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 externalRequest = require('../../core/core/server/lib/request-external.js');
|
||||||
|
const dnsPromises = require('dns').promises;
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const nock = require('nock');
|
const nock = require('nock');
|
||||||
|
|
||||||
describe('MentionDiscoveryService', function () {
|
describe('MentionDiscoveryService', function () {
|
||||||
const service = new MentionDiscoveryService({externalRequest});
|
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 () {
|
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)
|
nock(url.href)
|
||||||
.get('/')
|
.get('/')
|
||||||
.reply(404);
|
.reply(404);
|
||||||
|
|
Loading…
Add table
Reference in a new issue