6
6
import { SavedObjectsClientContract } from '../../../../core/server' ;
7
7
import { loggingSystemMock , savedObjectsClientMock } from '../../../../core/server/mocks' ;
8
8
import { DATA_SOURCE_SAVED_OBJECT_TYPE } from '../../common' ;
9
- import { AuthType , DataSourceAttributes } from '../../common/data_sources' ;
9
+ import { AuthType , DataSourceAttributes , SigV4Content } from '../../common/data_sources' ;
10
10
import { DataSourcePluginConfigType } from '../../config' ;
11
11
import { cryptographyServiceSetupMock } from '../cryptography_service.mocks' ;
12
12
import { CryptographyServiceSetup } from '../cryptography_service' ;
@@ -27,6 +27,7 @@ describe('configureLegacyClient', () => {
27
27
let clientPoolSetup : OpenSearchClientPoolSetup ;
28
28
let configOptions : ConfigOptions ;
29
29
let dataSourceAttr : DataSourceAttributes ;
30
+ let sigV4AuthContent : SigV4Content ;
30
31
31
32
let mockOpenSearchClientInstance : {
32
33
close : jest . Mock ;
@@ -71,6 +72,12 @@ describe('configureLegacyClient', () => {
71
72
} ,
72
73
} as DataSourceAttributes ;
73
74
75
+ sigV4AuthContent = {
76
+ region : 'us-east-1' ,
77
+ accessKey : 'accessKey' ,
78
+ secretKey : 'secretKey' ,
79
+ } ;
80
+
74
81
clientPoolSetup = {
75
82
getClientFromPool : jest . fn ( ) ,
76
83
addClientToPool : jest . fn ( ) ,
@@ -157,6 +164,42 @@ describe('configureLegacyClient', () => {
157
164
expect ( mockResult ) . toBeDefined ( ) ;
158
165
} ) ;
159
166
167
+ test ( 'configure client with auth.type == sigv4 and service param, should call new Client() with service param' , async ( ) => {
168
+ savedObjectsMock . get . mockReset ( ) . mockResolvedValueOnce ( {
169
+ id : DATA_SOURCE_ID ,
170
+ type : DATA_SOURCE_SAVED_OBJECT_TYPE ,
171
+ attributes : {
172
+ ...dataSourceAttr ,
173
+ auth : {
174
+ type : AuthType . SigV4 ,
175
+ credentials : { ...sigV4AuthContent , service : 'aoss' } ,
176
+ } ,
177
+ } ,
178
+ references : [ ] ,
179
+ } ) ;
180
+
181
+ parseClientOptionsMock . mockReturnValue ( configOptions ) ;
182
+
183
+ jest . spyOn ( cryptographyMock , 'decodeAndDecrypt' ) . mockResolvedValue ( {
184
+ decryptedText : 'accessKey' ,
185
+ encryptionContext : { endpoint : 'http://localhost' } ,
186
+ } ) ;
187
+
188
+ await configureLegacyClient (
189
+ dataSourceClientParams ,
190
+ callApiParams ,
191
+ clientPoolSetup ,
192
+ config ,
193
+ logger
194
+ ) ;
195
+
196
+ expect ( parseClientOptionsMock ) . toHaveBeenCalled ( ) ;
197
+ expect ( ClientMock ) . toHaveBeenCalledTimes ( 1 ) ;
198
+ expect ( ClientMock ) . toHaveBeenCalledWith ( expect . objectContaining ( { service : 'aoss' } ) ) ;
199
+
200
+ expect ( savedObjectsMock . get ) . toHaveBeenCalledTimes ( 1 ) ;
201
+ } ) ;
202
+
160
203
test ( 'configure client with auth.type == username_password and password contaminated' , async ( ) => {
161
204
const decodeAndDecryptSpy = jest
162
205
. spyOn ( cryptographyMock , 'decodeAndDecrypt' )
0 commit comments