@@ -23,13 +23,17 @@ import {
23
23
import { SecurityPluginConfigType } from '..' ;
24
24
import { SecuritySessionCookie } from '../session/security_cookie' ;
25
25
import { getAuthenticationHandler } from './auth_handler_factory' ;
26
+ import { AuthType } from '../../common' ;
27
+
28
+ const mockBasicAuthType = AuthType . BASIC ;
29
+ const mockSAMLAuthType = AuthType . SAML ;
26
30
27
31
jest . mock ( './types' , ( ) => {
28
32
return {
29
33
BasicAuthentication : jest . fn ( ) . mockImplementation ( ( ) => {
30
34
return {
31
35
authHandler : ( ) => { } ,
32
- type : 'basicauth' ,
36
+ type : mockBasicAuthType ,
33
37
init : ( ) => { } ,
34
38
} ;
35
39
} ) ,
@@ -57,14 +61,14 @@ jest.mock('./types', () => {
57
61
SamlAuthentication : jest . fn ( ) . mockImplementation ( ( ) => {
58
62
return {
59
63
authHandler : ( ) => { } ,
60
- type : 'saml' ,
64
+ type : mockSAMLAuthType ,
61
65
init : ( ) => { } ,
62
66
} ;
63
67
} ) ,
64
68
MultipleAuthentication : jest . fn ( ) . mockImplementation ( ( ) => {
65
69
return {
66
70
authHandler : ( ) => { } ,
67
- type : [ 'openid' , 'saml' , 'basiauth' ] ,
71
+ type : [ 'openid' , mockSAMLAuthType , mockBasicAuthType ] ,
68
72
init : ( ) => { } ,
69
73
} ;
70
74
} ) ,
@@ -83,54 +87,54 @@ describe('test authentication factory', () => {
83
87
84
88
test ( 'get basic auth: string array' , async ( ) => {
85
89
const auth = await getAuthenticationHandler (
86
- [ 'basicauth' ] ,
90
+ [ AuthType . BASIC ] ,
87
91
router ,
88
92
config ,
89
93
core ,
90
94
esClient ,
91
95
sessionStorageFactory ,
92
96
logger
93
97
) ;
94
- expect ( auth . type ) . toEqual ( 'basicauth' ) ;
98
+ expect ( auth . type ) . toEqual ( AuthType . BASIC ) ;
95
99
} ) ;
96
100
97
101
test ( 'get basic auth: string' , async ( ) => {
98
102
const auth = await getAuthenticationHandler (
99
- 'basicauth' ,
103
+ AuthType . BASIC ,
100
104
router ,
101
105
config ,
102
106
core ,
103
107
esClient ,
104
108
sessionStorageFactory ,
105
109
logger
106
110
) ;
107
- expect ( auth . type ) . toEqual ( 'basicauth' ) ;
111
+ expect ( auth . type ) . toEqual ( AuthType . BASIC ) ;
108
112
} ) ;
109
113
110
- test ( 'get basic auth with empty auth type: string array ' , async ( ) => {
114
+ test ( 'get basic auth with empty auth type: string' , async ( ) => {
111
115
const auth = await getAuthenticationHandler (
112
- [ '' ] ,
116
+ '' ,
113
117
router ,
114
118
config ,
115
119
core ,
116
120
esClient ,
117
121
sessionStorageFactory ,
118
122
logger
119
123
) ;
120
- expect ( auth . type ) . toEqual ( 'basicauth' ) ;
124
+ expect ( auth . type ) . toEqual ( AuthType . BASIC ) ;
121
125
} ) ;
122
126
123
- test ( 'get basic auth with empty auth type: string' , async ( ) => {
127
+ test ( 'get basic auth with empty auth type: string array ' , async ( ) => {
124
128
const auth = await getAuthenticationHandler (
125
- '' ,
129
+ [ '' ] ,
126
130
router ,
127
131
config ,
128
132
core ,
129
133
esClient ,
130
134
sessionStorageFactory ,
131
135
logger
132
136
) ;
133
- expect ( auth . type ) . toEqual ( 'basicauth' ) ;
137
+ expect ( auth . type ) . toEqual ( AuthType . BASIC ) ;
134
138
} ) ;
135
139
136
140
test ( 'get jwt auth: string array' , async ( ) => {
@@ -213,28 +217,28 @@ describe('test authentication factory', () => {
213
217
214
218
test ( 'get saml auth: string array' , async ( ) => {
215
219
const auth = await getAuthenticationHandler (
216
- [ 'saml' ] ,
220
+ [ AuthType . SAML ] ,
217
221
router ,
218
222
config ,
219
223
core ,
220
224
esClient ,
221
225
sessionStorageFactory ,
222
226
logger
223
227
) ;
224
- expect ( auth . type ) . toEqual ( 'saml' ) ;
228
+ expect ( auth . type ) . toEqual ( AuthType . SAML ) ;
225
229
} ) ;
226
230
227
231
test ( 'get saml auth: string' , async ( ) => {
228
232
const auth = await getAuthenticationHandler (
229
- 'saml' ,
233
+ AuthType . SAML ,
230
234
router ,
231
235
config ,
232
236
core ,
233
237
esClient ,
234
238
sessionStorageFactory ,
235
239
logger
236
240
) ;
237
- expect ( auth . type ) . toEqual ( 'saml' ) ;
241
+ expect ( auth . type ) . toEqual ( AuthType . SAML ) ;
238
242
} ) ;
239
243
240
244
test ( 'multiple_auth_enabled is on, get multi auth' , async ( ) => {
@@ -244,15 +248,15 @@ describe('test authentication factory', () => {
244
248
} ,
245
249
} ;
246
250
const auth = await getAuthenticationHandler (
247
- [ 'openid' , 'saml' , 'basiauth' ] ,
251
+ [ 'openid' , AuthType . SAML , AuthType . BASIC ] ,
248
252
router ,
249
253
config ,
250
254
core ,
251
255
esClient ,
252
256
sessionStorageFactory ,
253
257
logger
254
258
) ;
255
- expect ( auth . type ) . toEqual ( [ 'openid' , 'saml' , 'basiauth' ] ) ;
259
+ expect ( auth . type ) . toEqual ( [ 'openid' , AuthType . SAML , AuthType . BASIC ] ) ;
256
260
} ) ;
257
261
258
262
test ( 'multiple_auth_enabled is off, get multi auth' , async ( ) => {
@@ -263,7 +267,7 @@ describe('test authentication factory', () => {
263
267
} ;
264
268
try {
265
269
await getAuthenticationHandler (
266
- [ 'openid' , 'saml' , 'basiauth' ] ,
270
+ [ 'openid' , AuthType . SAML , AuthType . BASIC ] ,
267
271
router ,
268
272
config ,
269
273
core ,
0 commit comments