Skip to content

Commit 48e44c6

Browse files
committed
Adding a warning when a developer users hostWhitelist
1 parent dcb6d03 commit 48e44c6

File tree

6 files changed

+68
-56
lines changed

6 files changed

+68
-56
lines changed

packages/ember-cli-fastboot/lib/broccoli/fastboot-config.js

+17-15
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
/* eslint-env node */
22
'use strict';
33

4-
const fs = require('fs');
5-
const fmt = require('util').format;
6-
const uniq = require('ember-cli-lodash-subset').uniq;
7-
const merge = require('ember-cli-lodash-subset').merge;
8-
const md5Hex = require('md5-hex');
9-
const path = require('path');
10-
const Plugin = require('broccoli-plugin');
11-
4+
const fs = require('fs');
5+
const fmt = require('util').format;
6+
const uniq = require('ember-cli-lodash-subset').uniq;
7+
const merge = require('ember-cli-lodash-subset').merge;
8+
const md5Hex = require('md5-hex');
9+
const path = require('path');
10+
const Plugin = require('broccoli-plugin');
1211
const stringify = require('json-stable-stringify');
1312

1413
const LATEST_SCHEMA_VERSION = 3;
@@ -50,7 +49,7 @@ module.exports = class FastBootConfig extends Plugin {
5049
this.buildConfig();
5150
this.buildDependencies();
5251
this.buildManifest();
53-
this.buildHostAllowlist();
52+
this.buildHostAllowList();
5453

5554
let outputPath = path.join(this.outputPath, 'package.json');
5655
this.writeFileIfContentChanged(outputPath, this.toJSONString());
@@ -160,9 +159,12 @@ module.exports = class FastBootConfig extends Plugin {
160159
this.manifest = this.updateFastBootManifest(manifest);
161160
}
162161

163-
buildHostAllowlist() {
162+
buildHostAllowList() {
164163
if (this.fastbootAppConfig) {
165-
this.hostAllowlist = this.fastbootAppConfig.hostAllowlist;
164+
if ('hostWhitelist' in this.fastbootAppConfig) {
165+
this.ui.writeLine('Please update your fastboot config to use `hostAllowList` of the deprecated `hostWhitelist`');
166+
}
167+
this.hostAllowList = this.fastbootAppConfig.hostAllowList || this.fastbootAppConfig.hostWhitelist
166168
}
167169
}
168170

@@ -173,19 +175,19 @@ module.exports = class FastBootConfig extends Plugin {
173175
moduleAllowlist: this.moduleAllowlist,
174176
schemaVersion: LATEST_SCHEMA_VERSION,
175177
manifest: this.manifest,
176-
hostAllowlist: this.normalizeHostAllowlist(),
178+
hostAllowList: this.normalizeHostAllowList(),
177179
config: this.fastbootConfig,
178180
appName: this.appName,
179181
}
180182
}, null, 2);
181183
}
182184

183-
normalizeHostAllowlist() {
184-
if (!this.hostAllowlist) {
185+
normalizeHostAllowList() {
186+
if (!this.hostAllowList) {
185187
return;
186188
}
187189

188-
return this.hostAllowlist.map(function(entry) {
190+
return this.hostAllowList.map(function(entry) {
189191
// Is a regex
190192
if (entry.source) {
191193
return '/' + entry.source + '/';

packages/ember-cli-fastboot/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
"body-parser": "^1.18.3",
4747
"broccoli-asset-rev": "^3.0.0",
4848
"broccoli-test-helper": "^1.5.0",
49-
"co": "4.6.0",
5049
"chai": "^4.1.2",
5150
"chai-fs": "^2.0.0",
5251
"chai-string": "^1.4.0",
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,59 @@
1+
/* eslint-env node */
12
'use strict';
23

3-
const expect = require('chai').use(require('chai-string')).expect;
4-
const RSVP = require('rsvp');
5-
const request = RSVP.denodeify(require('request'));
6-
7-
const AddonTestApp = require('ember-cli-addon-tests').AddonTestApp;
8-
9-
describe('FastBoot config', function() {
10-
this.timeout(400000);
4+
const expect = require('chai').expect;
5+
const helpers = require('broccoli-test-helper');
6+
const MockUI = require('console-ui/mock')
7+
const createBuilder = helpers.createBuilder;
8+
const createTempDir = helpers.createTempDir;
9+
const FastbootConfig = require('../lib/broccoli/fastboot-config');
10+
11+
12+
describe('FastbootConfig', function() {
13+
let input;
14+
let output;
15+
let subject;
16+
let project;
17+
18+
beforeEach(async function() {
19+
input = await createTempDir();
20+
project = {
21+
addons: [],
22+
pkg: {},
23+
};
24+
subject = new FastbootConfig(input.path(), {
25+
project,
26+
outputPaths: {
27+
app: { js: 'app.js' },
28+
vendor: { js: 'vendor.js' },
29+
},
30+
appConfig: {
31+
modulePrefix: 'app',
32+
},
33+
ui: new MockUI(),
34+
fastbootAppConfig: {
35+
hostWhitelist: ['example.com', 'subdomain.example.com']
36+
}
37+
});
38+
output = createBuilder(subject);
39+
});
1140

12-
let app;
41+
afterEach(async function() {
42+
await input.dispose();
43+
await output.dispose();
44+
});
1345

14-
before(function() {
15-
app = new AddonTestApp();
46+
it('it replace hostWhitelist with hostAllowList and warns user to update the config to hostAllowList', async function() {
47+
input.write({});
1648

17-
return app.create('fastboot-config', { emberVersion: 'latest'})
18-
.then(function() {
19-
return app.startServer({
20-
command: 'serve'
21-
});
22-
});
23-
});
49+
await output.build();
2450

25-
after(function() {
26-
return app.stopServer();
27-
});
51+
expect(
52+
output.read()
53+
).to.deep.equal({
54+
'package.json': `{"dependencies":{},"fastboot":{"appName":"app","config":{"app":{"modulePrefix":"app"}},"hostAllowList":["example.com","subdomain.example.com"],"manifest":{"appFiles":["app.js","app-fastboot.js"],"htmlFile":"index.html","vendorFiles":["vendor.js"]},"moduleAllowlist":[],"schemaVersion":3}}`
55+
});
2856

29-
it('provides sandbox globals', function() {
30-
return request({
31-
url: 'http://localhost:49741/',
32-
headers: {
33-
'Accept': 'text/html'
34-
}
35-
})
36-
.then(function(response) {
37-
expect(response.statusCode).to.equal(200);
38-
expect(response.headers['content-type']).to.equalIgnoreCase('text/html; charset=utf-8');
39-
expect(response.body).to.contain('<h1>My Global</h1>');
40-
});
57+
expect(output.builder.outputNode.ui.output).to.contain('Please update your fastboot config to use `hostAllowList` of the deprecated `hostWhitelist`');
4158
});
4259
});

packages/ember-cli-fastboot/test/new-package-json-test.js

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ const expect = require('chai').expect;
55
const helpers = require('broccoli-test-helper');
66
const createBuilder = helpers.createBuilder;
77
const createTempDir = helpers.createTempDir;
8-
const co = require('co');
98
const FastbootConfig = require('../lib/broccoli/fastboot-config');
109

1110
describe('FastbootConfig', function() {

test-packages/basic-app/config/environment.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ module.exports = function(environment) {
2323
},
2424

2525
fastboot: {
26-
hostWhitelist: [
26+
hostAllowList: [
2727
'example.com',
2828
'subdomain.example.com',
2929
'/localhost:\\d+/',

yarn.lock

-5
Original file line numberDiff line numberDiff line change
@@ -5577,11 +5577,6 @@ clone@^2.0.0, clone@^2.1.2:
55775577
resolved "https://registry.yarnpkg.com/clone/-/clone-2.1.2.tgz#1b7f4b9f591f1e8f83670401600345a02887435f"
55785578
integrity sha1-G39Ln1kfHo+DZwQBYANFoCiHQ18=
55795579

5580-
co@4.6.0:
5581-
version "4.6.0"
5582-
resolved "https://registry.yarnpkg.com/co/-/co-4.6.0.tgz#6ea6bdf3d853ae54ccb8e47bfa0bf3f9031fb184"
5583-
integrity sha1-bqa989hTrlTMuOR7+gvz+QMfsYQ=
5584-
55855580
code-point-at@^1.0.0:
55865581
version "1.1.0"
55875582
resolved "https://registry.yarnpkg.com/code-point-at/-/code-point-at-1.1.0.tgz#0d070b4d043a5bea33a2f1a40e2edb3d9a4ccf77"

0 commit comments

Comments
 (0)