@@ -42,6 +42,64 @@ describe(`Test connection ${URL}`, () => {
42
42
} ,
43
43
} ;
44
44
45
+ const dataSourceAttrMissingCredentialForNoAuth = {
46
+ endpoint : 'https://test.com' ,
47
+ auth : {
48
+ type : AuthType . NoAuth ,
49
+ credentials : { } ,
50
+ } ,
51
+ } ;
52
+
53
+ const dataSourceAttrMissingCredentialForBasicAuth = {
54
+ endpoint : 'https://test.com' ,
55
+ auth : {
56
+ type : AuthType . UsernamePasswordType ,
57
+ credentials : { } ,
58
+ } ,
59
+ } ;
60
+
61
+ const dataSourceAttrMissingCredentialForSigV4Auth = {
62
+ endpoint : 'https://test.com' ,
63
+ auth : {
64
+ type : AuthType . SigV4 ,
65
+ credentials : { } ,
66
+ } ,
67
+ } ;
68
+
69
+ const dataSourceAttrPartialCredentialForSigV4Auth = {
70
+ endpoint : 'https://test.com' ,
71
+ auth : {
72
+ type : AuthType . SigV4 ,
73
+ credentials : {
74
+ accessKey : 'testKey' ,
75
+ service : 'service' ,
76
+ } ,
77
+ } ,
78
+ } ;
79
+
80
+ const dataSourceAttrPartialCredentialForBasicAuth = {
81
+ endpoint : 'https://test.com' ,
82
+ auth : {
83
+ type : AuthType . UsernamePasswordType ,
84
+ credentials : {
85
+ username : 'testName' ,
86
+ } ,
87
+ } ,
88
+ } ;
89
+
90
+ const dataSourceAttrForSigV4Auth = {
91
+ endpoint : 'https://test.com' ,
92
+ auth : {
93
+ type : AuthType . SigV4 ,
94
+ credentials : {
95
+ accessKey : 'testKey' ,
96
+ service : 'es' ,
97
+ secretKey : 'testSecret' ,
98
+ region : 'testRegion' ,
99
+ } ,
100
+ } ,
101
+ } ;
102
+
45
103
beforeEach ( async ( ) => {
46
104
( { server, httpSetup, handlerContext } = await setupServer ( ) ) ;
47
105
customApiSchemaRegistryPromise = Promise . resolve ( customApiSchemaRegistry ) ;
@@ -91,4 +149,70 @@ describe(`Test connection ${URL}`, () => {
91
149
} )
92
150
) ;
93
151
} ) ;
152
+
153
+ it ( 'no credential with no auth should succeed' , async ( ) => {
154
+ const result = await supertest ( httpSetup . server . listener )
155
+ . post ( URL )
156
+ . send ( {
157
+ id : 'testId' ,
158
+ dataSourceAttr : dataSourceAttrMissingCredentialForNoAuth ,
159
+ } )
160
+ . expect ( 200 ) ;
161
+ expect ( result . body ) . toEqual ( { success : true } ) ;
162
+ } ) ;
163
+
164
+ it ( 'no credential with basic auth should fail' , async ( ) => {
165
+ const result = await supertest ( httpSetup . server . listener )
166
+ . post ( URL )
167
+ . send ( {
168
+ id : 'testId' ,
169
+ dataSourceAttr : dataSourceAttrMissingCredentialForBasicAuth ,
170
+ } )
171
+ . expect ( 400 ) ;
172
+ expect ( result . body . error ) . toEqual ( 'Bad Request' ) ;
173
+ } ) ;
174
+
175
+ it ( 'no credential with sigv4 auth should fail' , async ( ) => {
176
+ const result = await supertest ( httpSetup . server . listener )
177
+ . post ( URL )
178
+ . send ( {
179
+ id : 'testId' ,
180
+ dataSourceAttr : dataSourceAttrMissingCredentialForSigV4Auth ,
181
+ } )
182
+ . expect ( 400 ) ;
183
+ expect ( result . body . error ) . toEqual ( 'Bad Request' ) ;
184
+ } ) ;
185
+
186
+ it ( 'partial credential with sigv4 auth should fail' , async ( ) => {
187
+ const result = await supertest ( httpSetup . server . listener )
188
+ . post ( URL )
189
+ . send ( {
190
+ id : 'testId' ,
191
+ dataSourceAttr : dataSourceAttrPartialCredentialForSigV4Auth ,
192
+ } )
193
+ . expect ( 400 ) ;
194
+ expect ( result . body . error ) . toEqual ( 'Bad Request' ) ;
195
+ } ) ;
196
+
197
+ it ( 'partial credential with basic auth should fail' , async ( ) => {
198
+ const result = await supertest ( httpSetup . server . listener )
199
+ . post ( URL )
200
+ . send ( {
201
+ id : 'testId' ,
202
+ dataSourceAttr : dataSourceAttrPartialCredentialForBasicAuth ,
203
+ } )
204
+ . expect ( 400 ) ;
205
+ expect ( result . body . error ) . toEqual ( 'Bad Request' ) ;
206
+ } ) ;
207
+
208
+ it ( 'full credential with sigV4 auth should success' , async ( ) => {
209
+ const result = await supertest ( httpSetup . server . listener )
210
+ . post ( URL )
211
+ . send ( {
212
+ id : 'testId' ,
213
+ dataSourceAttr : dataSourceAttrForSigV4Auth ,
214
+ } )
215
+ . expect ( 200 ) ;
216
+ expect ( result . body ) . toEqual ( { success : true } ) ;
217
+ } ) ;
94
218
} ) ;
0 commit comments