1919
2020import uuid from 'uuid' ;
2121import { config , HttpConfig } from '.' ;
22- import { Env } from '../config' ;
23- import { getEnvOptions } from '../config/__mocks__/env' ;
2422
2523const validHostnames = [ 'www.example.com' , '8.8.8.8' , '::1' , 'localhost' ] ;
2624const invalidHostname = 'asdf$%^' ;
2725
26+ jest . mock ( 'os' , ( ) => ( {
27+ ...jest . requireActual ( 'os' ) ,
28+ hostname : ( ) => 'kibana-hostname' ,
29+ } ) ) ;
30+
2831test ( 'has defaults for config' , ( ) => {
2932 const httpSchema = config . schema ;
3033 const obj = { } ;
@@ -86,6 +89,24 @@ test('accepts only valid uuids for server.uuid', () => {
8689 ) ;
8790} ) ;
8891
92+ test ( 'uses os.hostname() as default for server.name' , ( ) => {
93+ const httpSchema = config . schema ;
94+ const validated = httpSchema . validate ( { } ) ;
95+ expect ( validated . name ) . toEqual ( 'kibana-hostname' ) ;
96+ } ) ;
97+
98+ test ( 'throws if xsrf.whitelist element does not start with a slash' , ( ) => {
99+ const httpSchema = config . schema ;
100+ const obj = {
101+ xsrf : {
102+ whitelist : [ '/valid-path' , 'invalid-path' ] ,
103+ } ,
104+ } ;
105+ expect ( ( ) => httpSchema . validate ( obj ) ) . toThrowErrorMatchingInlineSnapshot (
106+ `"[xsrf.whitelist.1]: must start with a slash"`
107+ ) ;
108+ } ) ;
109+
89110describe ( 'with TLS' , ( ) => {
90111 test ( 'throws if TLS is enabled but `key` is not specified' , ( ) => {
91112 const httpSchema = config . schema ;
@@ -265,8 +286,7 @@ describe('with TLS', () => {
265286 clientAuthentication : 'none' ,
266287 } ,
267288 } ) ,
268- { } as any ,
269- Env . createDefault ( getEnvOptions ( ) )
289+ { } as any
270290 ) ;
271291
272292 expect ( httpConfig . ssl . requestCert ) . toBe ( false ) ;
@@ -283,8 +303,7 @@ describe('with TLS', () => {
283303 clientAuthentication : 'optional' ,
284304 } ,
285305 } ) ,
286- { } as any ,
287- Env . createDefault ( getEnvOptions ( ) )
306+ { } as any
288307 ) ;
289308
290309 expect ( httpConfig . ssl . requestCert ) . toBe ( true ) ;
@@ -301,8 +320,7 @@ describe('with TLS', () => {
301320 clientAuthentication : 'required' ,
302321 } ,
303322 } ) ,
304- { } as any ,
305- Env . createDefault ( getEnvOptions ( ) )
323+ { } as any
306324 ) ;
307325
308326 expect ( httpConfig . ssl . requestCert ) . toBe ( true ) ;
0 commit comments