mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-11 02:12:21 -05:00
Fixed whistelisted domains in Playwright tests and network connectivity
no issue - Nock doesn't support multiple calls to enableNetConnect -> only the last one counts. This fixes that issue. - Some tests interacted directly with nock instead of using the mockManager to restore everything.
This commit is contained in:
parent
df9df4be80
commit
3d89dbb775
7 changed files with 24 additions and 23 deletions
|
@ -25,8 +25,7 @@ describe('Oembed API', function () {
|
|||
});
|
||||
|
||||
afterEach(function () {
|
||||
sinon.restore();
|
||||
nock.cleanAll();
|
||||
mockManager.restore();
|
||||
});
|
||||
|
||||
it('can fetch an embed', async function () {
|
||||
|
|
|
@ -40,8 +40,6 @@ describe('Posts API', function () {
|
|||
|
||||
afterEach(function () {
|
||||
mockManager.restore();
|
||||
sinon.restore();
|
||||
nock.cleanAll();
|
||||
});
|
||||
|
||||
it('Can retrieve all posts', async function () {
|
||||
|
|
|
@ -123,7 +123,7 @@ describe('Members API', function () {
|
|||
});
|
||||
|
||||
afterEach(function () {
|
||||
nock.cleanAll();
|
||||
mockManager.restore();
|
||||
});
|
||||
|
||||
// Helper methods to update the customer and subscription
|
||||
|
|
|
@ -10,6 +10,7 @@ const MailgunClient = require('@tryghost/mailgun-client/lib/mailgun-client');
|
|||
const sinon = require('sinon');
|
||||
const ObjectID = require('bson-objectid').default;
|
||||
const nock = require('nock');
|
||||
const {allowStripe} = require('../../utils/e2e-framework-mock-manager');
|
||||
|
||||
const startWebhookServer = () => {
|
||||
const command = `stripe listen --forward-to ${config.getSiteUrl()}members/webhooks/stripe/ ${process.env.CI ? `--api-key ${process.env.STRIPE_SECRET_KEY}` : ''}`.trim();
|
||||
|
@ -66,11 +67,6 @@ const stubMailgun = () => {
|
|||
});
|
||||
};
|
||||
|
||||
const allowStripeNetwork = () => {
|
||||
// Allow Stripe
|
||||
nock.enableNetConnect('stripe.com');
|
||||
};
|
||||
|
||||
/**
|
||||
* Setup the environment
|
||||
*/
|
||||
|
@ -94,7 +90,7 @@ const setup = async (playwrightConfig) => {
|
|||
});
|
||||
|
||||
// StartGhost automatically disables network, so we need to re-enable it for Stripe
|
||||
allowStripeNetwork();
|
||||
allowStripe();
|
||||
}
|
||||
|
||||
const {baseURL, storageState} = playwrightConfig.projects[0].use;
|
||||
|
|
|
@ -23,7 +23,6 @@ describe('Mentions Service', function () {
|
|||
agent = await agentProvider.getAdminAPIAgent();
|
||||
await fixtureManager.init('users');
|
||||
await agent.loginAsAdmin();
|
||||
nock.disableNetConnect(); // make sure we don't actually send mentions
|
||||
});
|
||||
|
||||
beforeEach(async function () {
|
||||
|
@ -48,12 +47,6 @@ describe('Mentions Service', function () {
|
|||
|
||||
afterEach(async function () {
|
||||
mockManager.restore();
|
||||
nock.cleanAll();
|
||||
});
|
||||
|
||||
after(function () {
|
||||
nock.enableNetConnect();
|
||||
nock.cleanAll();
|
||||
});
|
||||
|
||||
describe('Sending Service', function () {
|
||||
|
|
|
@ -20,10 +20,6 @@ describe('TwitterOEmbedProvider', function () {
|
|||
mockManager.restore();
|
||||
});
|
||||
|
||||
after(async function () {
|
||||
nock.enableNetConnect();
|
||||
});
|
||||
|
||||
it('Can support requests for Tweet URLs', async function () {
|
||||
const provider = new TwitterOEmbedProvider();
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ const settingsCache = require('../../core/shared/settings-cache');
|
|||
const dnsPromises = require('dns').promises;
|
||||
|
||||
let fakedLabsFlags = {};
|
||||
let allowedNetworkDomains = [];
|
||||
const originalLabsIsSet = labs.isSet;
|
||||
|
||||
/**
|
||||
|
@ -47,7 +48,23 @@ const disableNetwork = () => {
|
|||
}
|
||||
|
||||
// Allow localhost
|
||||
nock.enableNetConnect('127.0.0.1');
|
||||
// Multiple enableNetConnect with different hosts overwrite each other, so we need to add one and use the allowedNetworkDomains variable
|
||||
nock.enableNetConnect((host) => {
|
||||
if (host.includes('127.0.0.1')) {
|
||||
return true;
|
||||
}
|
||||
for (const h of allowedNetworkDomains) {
|
||||
if (host.includes(h)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
});
|
||||
};
|
||||
|
||||
const allowStripe = () => {
|
||||
disableNetwork();
|
||||
allowedNetworkDomains.push('stripe.com');
|
||||
};
|
||||
|
||||
const mockStripe = () => {
|
||||
|
@ -237,6 +254,7 @@ const restore = () => {
|
|||
fakedLabsFlags = {};
|
||||
fakedSettings = {};
|
||||
emailCount = 0;
|
||||
allowedNetworkDomains = [];
|
||||
nock.cleanAll();
|
||||
nock.enableNetConnect();
|
||||
|
||||
|
@ -256,6 +274,7 @@ module.exports = {
|
|||
disableStripe,
|
||||
mockStripe,
|
||||
mockSlack,
|
||||
allowStripe,
|
||||
mockMailgun,
|
||||
mockLabsEnabled,
|
||||
mockLabsDisabled,
|
||||
|
|
Loading…
Add table
Reference in a new issue