Skip to content

Commit a20867a

Browse files
committed
test: fix
1 parent 8bd1948 commit a20867a

File tree

2 files changed

+72
-52
lines changed

2 files changed

+72
-52
lines changed

test/server/Server.test.js

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -301,25 +301,6 @@ describe('Server', () => {
301301
});
302302
});
303303

304-
it('should always allow any host if options.allowedHosts is enabled', () => {
305-
const options = {
306-
client: {
307-
webSocketURL: 'ws://test.host:80',
308-
},
309-
allowedHosts: true,
310-
};
311-
312-
const headers = {
313-
host: 'bad.host',
314-
};
315-
316-
server = createServer(compiler, options);
317-
318-
if (!server.checkHost(headers)) {
319-
throw new Error("Validation didn't fail");
320-
}
321-
});
322-
323304
it('should allow any valid options.client.webSocketURL when host is localhost', () => {
324305
const options = {
325306
client: {
@@ -429,39 +410,6 @@ describe('Server', () => {
429410
throw new Error("Validation didn't fail");
430411
}
431412
});
432-
433-
describe('allowedHosts', () => {
434-
it('should allow hosts in allowedHosts', () => {
435-
const tests = ['test.host', 'test2.host', 'test3.host'];
436-
const options = { allowedHosts: tests };
437-
server = createServer(compiler, options);
438-
tests.forEach((test) => {
439-
const headers = { host: test };
440-
if (!server.checkHost(headers)) {
441-
throw new Error("Validation didn't fail");
442-
}
443-
});
444-
});
445-
446-
it('should allow hosts that pass a wildcard in allowedHosts', () => {
447-
const options = { allowedHosts: ['.example.com'] };
448-
server = createServer(compiler, options);
449-
const tests = [
450-
'www.example.com',
451-
'subdomain.example.com',
452-
'example.com',
453-
'subsubcomain.subdomain.example.com',
454-
'example.com:80',
455-
'subdomain.example.com:80',
456-
];
457-
tests.forEach((test) => {
458-
const headers = { host: test };
459-
if (!server.checkHost(headers)) {
460-
throw new Error("Validation didn't fail");
461-
}
462-
});
463-
});
464-
});
465413
});
466414

467415
describe('Invalidate Callback', () => {
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
'use strict';
2+
3+
const webpack = require('webpack');
4+
const Server = require('../../lib/Server');
5+
const config = require('../fixtures/simple-config/webpack.config');
6+
7+
const createServer = (compiler, options) => new Server(options, compiler);
8+
9+
describe('allowedHosts', () => {
10+
let compiler;
11+
let server;
12+
13+
beforeEach(() => {
14+
compiler = webpack(config);
15+
});
16+
17+
afterEach((done) => {
18+
server.close(() => {
19+
done();
20+
});
21+
});
22+
23+
it('should always allow any host if options.allowedHosts is enabled', () => {
24+
const options = {
25+
client: {
26+
webSocketURL: 'ws://test.host:80',
27+
},
28+
allowedHosts: true,
29+
};
30+
31+
const headers = {
32+
host: 'bad.host',
33+
};
34+
35+
server = createServer(compiler, options);
36+
37+
if (!server.checkHost(headers)) {
38+
throw new Error("Validation didn't fail");
39+
}
40+
});
41+
42+
it('should allow hosts in allowedHosts', () => {
43+
const tests = ['test.host', 'test2.host', 'test3.host'];
44+
const options = { allowedHosts: tests };
45+
server = createServer(compiler, options);
46+
tests.forEach((test) => {
47+
const headers = { host: test };
48+
if (!server.checkHost(headers)) {
49+
throw new Error("Validation didn't fail");
50+
}
51+
});
52+
});
53+
54+
it('should allow hosts that pass a wildcard in allowedHosts', () => {
55+
const options = { allowedHosts: ['.example.com'] };
56+
server = createServer(compiler, options);
57+
const tests = [
58+
'www.example.com',
59+
'subdomain.example.com',
60+
'example.com',
61+
'subsubcomain.subdomain.example.com',
62+
'example.com:80',
63+
'subdomain.example.com:80',
64+
];
65+
tests.forEach((test) => {
66+
const headers = { host: test };
67+
if (!server.checkHost(headers)) {
68+
throw new Error("Validation didn't fail");
69+
}
70+
});
71+
});
72+
});

0 commit comments

Comments
 (0)