@@ -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
@@ -75,7 +88,7 @@ describe('server createHandlers', () => {
7588 } ) ;
7689 } ) ;
7790
78- it ( 'works without security' , async ( ) => {
91+ it ( 'works without security plugin in kibana ' , async ( ) => {
7992 // create server without security plugin
8093 const mockServerClone = {
8194 ...mockServer ,
@@ -98,5 +111,41 @@ describe('server createHandlers', () => {
98111 expect ( endpoint ) . to . equal ( 'endpoint' ) ;
99112 expect ( payload ) . to . equal ( 'payload' ) ;
100113 } ) ;
114+
115+ it ( 'works without security available' , async ( ) => {
116+ // create server with security unavailable (i.e. when user is on a basic license)
117+ isSecurityAvailable = false ;
118+
119+ // this shouldn't do anything
120+ securityMode = 'fail' ;
121+
122+ // make sure the method still works
123+ handlers = createHandlers ( mockRequest , mockServer ) ;
124+ const [ request , endpoint , payload ] = await handlers . elasticsearchClient (
125+ 'endpoint' ,
126+ 'payload'
127+ ) ;
128+ expect ( request ) . to . equal ( mockRequest ) ;
129+ expect ( endpoint ) . to . equal ( 'endpoint' ) ;
130+ expect ( payload ) . to . equal ( 'payload' ) ;
131+ } ) ;
132+
133+ it ( 'works with security disabled in elasticsearch' , async ( ) => {
134+ // create server with security disabled
135+ isSecurityEnabled = false ;
136+
137+ // this shouldn't do anything
138+ securityMode = 'fail' ;
139+
140+ // make sure the method still works
141+ handlers = createHandlers ( mockRequest , mockServer ) ;
142+ const [ request , endpoint , payload ] = await handlers . elasticsearchClient (
143+ 'endpoint' ,
144+ 'payload'
145+ ) ;
146+ expect ( request ) . to . equal ( mockRequest ) ;
147+ expect ( endpoint ) . to . equal ( 'endpoint' ) ;
148+ expect ( payload ) . to . equal ( 'payload' ) ;
149+ } ) ;
101150 } ) ;
102151} ) ;
0 commit comments