@@ -8,6 +8,8 @@ import expect from 'expect.js';
88import { createHandlers } from '../create_handlers' ;
99
1010let securityMode = 'pass' ;
11+ let isSecurityAvailable = true ;
12+ let isSecurityEnabled = true ;
1113const authError = new Error ( 'auth error' ) ;
1214
1315const mockRequest = {
@@ -27,6 +29,15 @@ const mockServer = {
2729 callWithRequest : ( ...args ) => Promise . resolve ( args ) ,
2830 } ) ,
2931 } ,
32+ // TODO: remove this when we use the method exposed by security https://github.com/elastic/kibana/pull/24616
33+ xpack_main : {
34+ info : {
35+ feature : ( ) => ( {
36+ isAvailable : ( ) => isSecurityAvailable ,
37+ isEnabled : ( ) => isSecurityEnabled ,
38+ } ) ,
39+ } ,
40+ } ,
3041 } ,
3142 config : ( ) => ( {
3243 has : ( ) => false ,
@@ -42,6 +53,8 @@ describe('server createHandlers', () => {
4253
4354 beforeEach ( ( ) => {
4455 securityMode = 'pass' ;
56+ isSecurityEnabled = true ;
57+ isSecurityAvailable = true ;
4558 handlers = createHandlers ( mockRequest , mockServer ) ;
4659 } ) ;
4760
@@ -76,7 +89,7 @@ describe('server createHandlers', () => {
7689 } ) ;
7790 } ) ;
7891
79- it ( 'works without security' , async ( ) => {
92+ it ( 'works without security plugin in kibana ' , async ( ) => {
8093 // create server without security plugin
8194 const mockServerClone = {
8295 ...mockServer ,
@@ -99,5 +112,41 @@ describe('server createHandlers', () => {
99112 expect ( endpoint ) . to . equal ( 'endpoint' ) ;
100113 expect ( payload ) . to . equal ( 'payload' ) ;
101114 } ) ;
115+
116+ it ( 'works without security available' , async ( ) => {
117+ // create server with security unavailable (i.e. when user is on a basic license)
118+ isSecurityAvailable = false ;
119+
120+ // this shouldn't do anything
121+ securityMode = 'fail' ;
122+
123+ // make sure the method still works
124+ handlers = createHandlers ( mockRequest , mockServer ) ;
125+ const [ request , endpoint , payload ] = await handlers . elasticsearchClient (
126+ 'endpoint' ,
127+ 'payload'
128+ ) ;
129+ expect ( request ) . to . equal ( mockRequest ) ;
130+ expect ( endpoint ) . to . equal ( 'endpoint' ) ;
131+ expect ( payload ) . to . equal ( 'payload' ) ;
132+ } ) ;
133+
134+ it ( 'works with security disabled in elasticsearch' , async ( ) => {
135+ // create server with security disabled
136+ isSecurityEnabled = false ;
137+
138+ // this shouldn't do anything
139+ securityMode = 'fail' ;
140+
141+ // make sure the method still works
142+ handlers = createHandlers ( mockRequest , mockServer ) ;
143+ const [ request , endpoint , payload ] = await handlers . elasticsearchClient (
144+ 'endpoint' ,
145+ 'payload'
146+ ) ;
147+ expect ( request ) . to . equal ( mockRequest ) ;
148+ expect ( endpoint ) . to . equal ( 'endpoint' ) ;
149+ expect ( payload ) . to . equal ( 'payload' ) ;
150+ } ) ;
102151 } ) ;
103152} ) ;
0 commit comments