@@ -13,6 +13,7 @@ import { userSettingsSelector } from 'uiSrc/slices/user/user-settings'
13
13
import { addInfiniteNotification } from 'uiSrc/slices/app/notifications'
14
14
import { INFINITE_MESSAGES } from 'uiSrc/components/notifications/components'
15
15
import { Pages } from 'uiSrc/constants'
16
+ import { ADD_NEW , ADD_NEW_CA_CERT } from 'uiSrc/pages/home/constants'
16
17
import { UrlHandlingActions } from 'uiSrc/slices/interfaces/urlHandling'
17
18
import GlobalUrlHandler from './GlobalUrlHandler'
18
19
@@ -131,7 +132,10 @@ describe('GlobalUrlHandler', () => {
131
132
password : 'password' ,
132
133
port : 6379 ,
133
134
tls : false ,
134
- username : undefined
135
+ username : undefined ,
136
+ caCert : undefined ,
137
+ clientCert : undefined ,
138
+ verifyServerCert : false ,
135
139
}
136
140
} ) ,
137
141
]
@@ -141,15 +145,15 @@ describe('GlobalUrlHandler', () => {
141
145
expect ( pushMock ) . toBeCalledWith ( Pages . home )
142
146
} )
143
147
144
- it ( 'should call proper actions only after consents popup is accepted and open form to add db' , async ( ) => {
148
+ it ( 'should call proper actions only after consents popup is accepted and open form to add db with caCert ' , async ( ) => {
145
149
const pushMock = jest . fn ( )
146
150
reactRouterDom . useHistory = jest . fn ( ) . mockReturnValueOnce ( { push : pushMock } ) ;
147
151
( userSettingsSelector as jest . Mock ) . mockReturnValueOnce ( {
148
152
config : { } ,
149
153
isShowConsents : false
150
154
} )
151
155
152
- const url = `${ fromUrl } &requiredTls =true` ;
156
+ const url = `${ fromUrl } &requiredCaCert =true` ;
153
157
154
158
( appRedirectionSelector as jest . Mock ) . mockReturnValueOnce ( {
155
159
fromUrl : url
@@ -177,6 +181,104 @@ describe('GlobalUrlHandler', () => {
177
181
password : 'password' ,
178
182
port : 6379 ,
179
183
tls : true ,
184
+ verifyServerCert : true ,
185
+ caCert : { id : ADD_NEW_CA_CERT } ,
186
+ username : 'default' ,
187
+ }
188
+ } )
189
+ ]
190
+
191
+ expect ( store . getActions ( ) . slice ( 0 , expectedActions . length ) ) . toEqual ( expectedActions )
192
+ expect ( pushMock ) . toBeCalledWith ( Pages . home )
193
+ } )
194
+
195
+ it ( 'should call proper actions only after consents popup is accepted and open form to add db with client cert' , async ( ) => {
196
+ const pushMock = jest . fn ( )
197
+ reactRouterDom . useHistory = jest . fn ( ) . mockReturnValueOnce ( { push : pushMock } ) ;
198
+ ( userSettingsSelector as jest . Mock ) . mockReturnValueOnce ( {
199
+ config : { } ,
200
+ isShowConsents : false
201
+ } )
202
+
203
+ const url = `${ fromUrl } &requiredClientCert=true` ;
204
+
205
+ ( appRedirectionSelector as jest . Mock ) . mockReturnValueOnce ( {
206
+ fromUrl : url
207
+ } )
208
+
209
+ await act ( ( ) => {
210
+ render ( < GlobalUrlHandler /> )
211
+ } )
212
+
213
+ const actionUrl = new URL ( url )
214
+ const fromParams = new URLSearchParams ( actionUrl . search )
215
+ // @ts -ignore
216
+ const urlProperties = Object . fromEntries ( fromParams ) || { }
217
+ urlProperties . cloudId = urlProperties . cloudBdbId
218
+ delete urlProperties . cloudBdbId
219
+
220
+ const expectedActions = [
221
+ setUrlProperties ( urlProperties ) ,
222
+ setFromUrl ( null ) ,
223
+ setUrlDbConnection ( {
224
+ action : UrlHandlingActions . Connect ,
225
+ dbConnection : {
226
+ host : 'localhost' ,
227
+ name : 'My Name' ,
228
+ password : 'password' ,
229
+ port : 6379 ,
230
+ tls : true ,
231
+ caCert : undefined ,
232
+ clientCert : { id : ADD_NEW } ,
233
+ verifyServerCert : false ,
234
+ username : 'default' ,
235
+ }
236
+ } )
237
+ ]
238
+
239
+ expect ( store . getActions ( ) . slice ( 0 , expectedActions . length ) ) . toEqual ( expectedActions )
240
+ expect ( pushMock ) . toBeCalledWith ( Pages . home )
241
+ } )
242
+
243
+ it ( 'should call proper actions only after consents popup is accepted and open form to add db with tls certs' , async ( ) => {
244
+ const pushMock = jest . fn ( )
245
+ reactRouterDom . useHistory = jest . fn ( ) . mockReturnValueOnce ( { push : pushMock } ) ;
246
+ ( userSettingsSelector as jest . Mock ) . mockReturnValueOnce ( {
247
+ config : { } ,
248
+ isShowConsents : false
249
+ } )
250
+
251
+ const url = `${ fromUrl } &requiredCaCert=true&requiredClientCert=true` ;
252
+
253
+ ( appRedirectionSelector as jest . Mock ) . mockReturnValueOnce ( {
254
+ fromUrl : url
255
+ } )
256
+
257
+ await act ( ( ) => {
258
+ render ( < GlobalUrlHandler /> )
259
+ } )
260
+
261
+ const actionUrl = new URL ( url )
262
+ const fromParams = new URLSearchParams ( actionUrl . search )
263
+ // @ts -ignore
264
+ const urlProperties = Object . fromEntries ( fromParams ) || { }
265
+ urlProperties . cloudId = urlProperties . cloudBdbId
266
+ delete urlProperties . cloudBdbId
267
+
268
+ const expectedActions = [
269
+ setUrlProperties ( urlProperties ) ,
270
+ setFromUrl ( null ) ,
271
+ setUrlDbConnection ( {
272
+ action : UrlHandlingActions . Connect ,
273
+ dbConnection : {
274
+ host : 'localhost' ,
275
+ name : 'My Name' ,
276
+ password : 'password' ,
277
+ port : 6379 ,
278
+ tls : true ,
279
+ caCert : { id : ADD_NEW_CA_CERT } ,
280
+ clientCert : { id : ADD_NEW } ,
281
+ verifyServerCert : true ,
180
282
username : 'default' ,
181
283
}
182
284
} )
0 commit comments