@@ -22,6 +22,14 @@ describe("Validation", function() {
22
22
message : [
23
23
" - configuration.public should be a string."
24
24
]
25
+ } , {
26
+ name : "invalid `allowedHosts` configuration" ,
27
+ config : { allowedHosts : 1 } ,
28
+ message : [
29
+ " - configuration.allowedHosts should be an array:" ,
30
+ " [string]" ,
31
+ " Specifies which hosts are allowed to access the dev server."
32
+ ]
25
33
} , {
26
34
name : "invalid `contentBase` configuration" ,
27
35
config : { contentBase : [ 0 ] } ,
@@ -40,7 +48,7 @@ describe("Validation", function() {
40
48
config : { asdf : true } ,
41
49
message : [
42
50
" - configuration has an unknown property 'asdf'. These properties are valid:" ,
43
- " object { hot?, hotOnly?, lazy?, host?, filename?, publicPath?, port?, socket?, " +
51
+ " object { hot?, hotOnly?, lazy?, host?, allowedHosts?, filename?, publicPath?, port?, socket?, " +
44
52
"watchOptions?, headers?, clientLogLevel?, overlay?, key?, cert?, ca?, pfx?, pfxPassphrase?, " +
45
53
"inline?, disableHostCheck?, public?, https?, contentBase?, watchContentBase?, open?, features?, " +
46
54
"compress?, proxy?, historyApiFallback?, staticOptions?, setup?, stats?, reporter?, " +
@@ -115,5 +123,43 @@ describe("Validation", function() {
115
123
throw new Error ( "Validation didn't fail" ) ;
116
124
}
117
125
} ) ;
126
+
127
+ describe ( "allowedHosts" , function ( ) {
128
+ it ( "should allow hosts in allowedHosts" , function ( ) {
129
+ const testHosts = [
130
+ "test.host" ,
131
+ "test2.host" ,
132
+ "test3.host"
133
+ ] ;
134
+ const options = { allowedHosts : testHosts } ;
135
+ const server = new Server ( compiler , options ) ;
136
+
137
+ testHosts . forEach ( function ( testHost ) {
138
+ const headers = { host : testHost } ;
139
+ if ( ! server . checkHost ( headers ) ) {
140
+ throw new Error ( "Validation didn't fail" ) ;
141
+ }
142
+ } ) ;
143
+ } ) ;
144
+ it ( "should allow hosts that pass a wildcard in allowedHosts" , function ( ) {
145
+ const options = { allowedHosts : [ ".example.com" ] } ;
146
+ const server = new Server ( compiler , options ) ;
147
+ const testHosts = [
148
+ "www.example.com" ,
149
+ "subdomain.example.com" ,
150
+ "example.com" ,
151
+ "subsubcomain.subdomain.example.com" ,
152
+ "example.com:80" ,
153
+ "subdomain.example.com:80"
154
+ ] ;
155
+
156
+ testHosts . forEach ( function ( testHost ) {
157
+ const headers = { host : testHost } ;
158
+ if ( ! server . checkHost ( headers ) ) {
159
+ throw new Error ( "Validation didn't fail" ) ;
160
+ }
161
+ } ) ;
162
+ } ) ;
163
+ } ) ;
118
164
} )
119
165
} ) ;
0 commit comments