@@ -22,6 +22,14 @@ describe("Validation", function() {
2222 message : [
2323 " - configuration.public should be a string."
2424 ]
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+ ]
2533 } , {
2634 name : "invalid `contentBase` configuration" ,
2735 config : { contentBase : [ 0 ] } ,
@@ -40,7 +48,7 @@ describe("Validation", function() {
4048 config : { asdf : true } ,
4149 message : [
4250 " - 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?, " +
4452 "watchOptions?, headers?, clientLogLevel?, overlay?, key?, cert?, ca?, pfx?, pfxPassphrase?, " +
4553 "inline?, disableHostCheck?, public?, https?, contentBase?, watchContentBase?, open?, features?, " +
4654 "compress?, proxy?, historyApiFallback?, staticOptions?, setup?, stats?, reporter?, " +
@@ -115,5 +123,43 @@ describe("Validation", function() {
115123 throw new Error ( "Validation didn't fail" ) ;
116124 }
117125 } ) ;
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+ } ) ;
118164 } )
119165} ) ;
0 commit comments