Skip to content

Commit 19841d3

Browse files
#RI-5229 - resolve comments
1 parent 487554b commit 19841d3

File tree

2 files changed

+59
-3
lines changed

2 files changed

+59
-3
lines changed

redisinsight/ui/src/components/global-url-handler/GlobalUrlHandler.spec.tsx

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,4 +287,52 @@ describe('GlobalUrlHandler', () => {
287287
expect(store.getActions().slice(0, expectedActions.length)).toEqual(expectedActions)
288288
expect(pushMock).toBeCalledWith(Pages.home)
289289
})
290+
291+
it('should call proper actions only after consents popup is accepted and open form to add db with tls', async () => {
292+
const pushMock = jest.fn()
293+
reactRouterDom.useHistory = jest.fn().mockReturnValueOnce({ push: pushMock });
294+
(userSettingsSelector as jest.Mock).mockReturnValueOnce({
295+
config: {},
296+
isShowConsents: false
297+
})
298+
299+
const url = `${fromUrl}&requiredTls=true`;
300+
301+
(appRedirectionSelector as jest.Mock).mockReturnValueOnce({
302+
fromUrl: url
303+
})
304+
305+
await act(() => {
306+
render(<GlobalUrlHandler />)
307+
})
308+
309+
const actionUrl = new URL(url)
310+
const fromParams = new URLSearchParams(actionUrl.search)
311+
// @ts-ignore
312+
const urlProperties = Object.fromEntries(fromParams) || {}
313+
urlProperties.cloudId = urlProperties.cloudBdbId
314+
delete urlProperties.cloudBdbId
315+
316+
const expectedActions = [
317+
setUrlProperties(urlProperties),
318+
setFromUrl(null),
319+
setUrlDbConnection({
320+
action: UrlHandlingActions.Connect,
321+
dbConnection: {
322+
host: 'localhost',
323+
name: 'My Name',
324+
password: 'password',
325+
port: 6379,
326+
tls: true,
327+
caCert: undefined,
328+
clientCert: undefined,
329+
verifyServerCert: false,
330+
username: 'default',
331+
}
332+
})
333+
]
334+
335+
expect(store.getActions().slice(0, expectedActions.length)).toEqual(expectedActions)
336+
expect(pushMock).toBeCalledWith(Pages.home)
337+
})
290338
})

redisinsight/ui/src/components/global-url-handler/GlobalUrlHandler.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { useHistory, useLocation } from 'react-router-dom'
22
import { useDispatch, useSelector } from 'react-redux'
33
import { useEffect } from 'react'
44
import { ConnectionString } from 'connection-string'
5-
import { isNull, isNumber, every, values, pick } from 'lodash'
5+
import { isNull, isNumber, every, values, pick, some } from 'lodash'
66
import { Pages, REDIS_URI_SCHEMES } from 'uiSrc/constants'
77
import { ADD_NEW_CA_CERT, ADD_NEW } from 'uiSrc/pages/home/constants'
88
import {
@@ -89,6 +89,7 @@ const GlobalUrlHandler = () => {
8989
redisUrl,
9090
databaseAlias,
9191
redirect,
92+
requiredTls,
9293
requiredCaCert,
9394
requiredClientCert,
9495
} = properties
@@ -112,14 +113,21 @@ const GlobalUrlHandler = () => {
112113
password: url.password,
113114
}
114115

116+
const tlsFields = {
117+
requiredTls,
118+
requiredCaCert,
119+
requiredClientCert,
120+
}
121+
115122
const isAllObligatoryProvided = every(values(obligatoryForAutoConnectFields), (value) => value || isNumber(value))
123+
const isTlsProvided = some(values(tlsFields), (value) => value === 'true')
116124

117125
const db = {
118126
...obligatoryForAutoConnectFields,
119127
name: databaseAlias || url.host,
120128
} as any
121129

122-
if (isAllObligatoryProvided && (requiredCaCert !== 'true' && requiredClientCert !== 'true')) {
130+
if (isAllObligatoryProvided && !isTlsProvided) {
123131
if (cloudDetails?.cloudId) {
124132
db.cloudDetails = cloudDetails
125133
}
@@ -134,7 +142,7 @@ const GlobalUrlHandler = () => {
134142
dbConnection: {
135143
...db,
136144
// set tls with new cert option
137-
tls: requiredCaCert === 'true' || requiredClientCert === 'true',
145+
tls: isTlsProvided,
138146
verifyServerCert: requiredCaCert === 'true',
139147
caCert: requiredCaCert === 'true' ? { id: ADD_NEW_CA_CERT } : undefined,
140148
clientCert: requiredClientCert === 'true' ? { id: ADD_NEW } : undefined,

0 commit comments

Comments
 (0)