Skip to content

Commit 487554b

Browse files
#RI-5229 - add deeplink tls support
1 parent 6a510a3 commit 487554b

File tree

3 files changed

+116
-7
lines changed

3 files changed

+116
-7
lines changed

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

Lines changed: 105 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { userSettingsSelector } from 'uiSrc/slices/user/user-settings'
1313
import { addInfiniteNotification } from 'uiSrc/slices/app/notifications'
1414
import { INFINITE_MESSAGES } from 'uiSrc/components/notifications/components'
1515
import { Pages } from 'uiSrc/constants'
16+
import { ADD_NEW, ADD_NEW_CA_CERT } from 'uiSrc/pages/home/constants'
1617
import { UrlHandlingActions } from 'uiSrc/slices/interfaces/urlHandling'
1718
import GlobalUrlHandler from './GlobalUrlHandler'
1819

@@ -131,7 +132,10 @@ describe('GlobalUrlHandler', () => {
131132
password: 'password',
132133
port: 6379,
133134
tls: false,
134-
username: undefined
135+
username: undefined,
136+
caCert: undefined,
137+
clientCert: undefined,
138+
verifyServerCert: false,
135139
}
136140
}),
137141
]
@@ -141,15 +145,15 @@ describe('GlobalUrlHandler', () => {
141145
expect(pushMock).toBeCalledWith(Pages.home)
142146
})
143147

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 () => {
145149
const pushMock = jest.fn()
146150
reactRouterDom.useHistory = jest.fn().mockReturnValueOnce({ push: pushMock });
147151
(userSettingsSelector as jest.Mock).mockReturnValueOnce({
148152
config: {},
149153
isShowConsents: false
150154
})
151155

152-
const url = `${fromUrl}&requiredTls=true`;
156+
const url = `${fromUrl}&requiredCaCert=true`;
153157

154158
(appRedirectionSelector as jest.Mock).mockReturnValueOnce({
155159
fromUrl: url
@@ -177,6 +181,104 @@ describe('GlobalUrlHandler', () => {
177181
password: 'password',
178182
port: 6379,
179183
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,
180282
username: 'default',
181283
}
182284
})

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { useEffect } from 'react'
44
import { ConnectionString } from 'connection-string'
55
import { isNull, isNumber, every, values, pick } from 'lodash'
66
import { Pages, REDIS_URI_SCHEMES } from 'uiSrc/constants'
7+
import { ADD_NEW_CA_CERT, ADD_NEW } from 'uiSrc/pages/home/constants'
78
import {
89
appRedirectionSelector,
910
setFromUrl,
@@ -87,8 +88,9 @@ const GlobalUrlHandler = () => {
8788
const {
8889
redisUrl,
8990
databaseAlias,
90-
requiredTls,
9191
redirect,
92+
requiredCaCert,
93+
requiredClientCert,
9294
} = properties
9395

9496
const cloudDetails = transformQueryParamsObject(
@@ -107,7 +109,7 @@ const GlobalUrlHandler = () => {
107109
host: url.hostname,
108110
port: url.port,
109111
username: url.user,
110-
password: url.password
112+
password: url.password,
111113
}
112114

113115
const isAllObligatoryProvided = every(values(obligatoryForAutoConnectFields), (value) => value || isNumber(value))
@@ -117,7 +119,7 @@ const GlobalUrlHandler = () => {
117119
name: databaseAlias || url.host,
118120
} as any
119121

120-
if (isAllObligatoryProvided && requiredTls !== 'true') {
122+
if (isAllObligatoryProvided && (requiredCaCert !== 'true' && requiredClientCert !== 'true')) {
121123
if (cloudDetails?.cloudId) {
122124
db.cloudDetails = cloudDetails
123125
}
@@ -131,7 +133,11 @@ const GlobalUrlHandler = () => {
131133
action: UrlHandlingActions.Connect,
132134
dbConnection: {
133135
...db,
134-
tls: requiredTls === 'true',
136+
// set tls with new cert option
137+
tls: requiredCaCert === 'true' || requiredClientCert === 'true',
138+
verifyServerCert: requiredCaCert === 'true',
139+
caCert: requiredCaCert === 'true' ? { id: ADD_NEW_CA_CERT } : undefined,
140+
clientCert: requiredClientCert === 'true' ? { id: ADD_NEW } : undefined,
135141
}
136142
}))
137143

redisinsight/ui/src/pages/home/components/manual-connection/manual-connection-form/ManualConnectionForm.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ const ManualConnectionForm = (props: Props) => {
137137
initialValues: formFields,
138138
validate,
139139
enableReinitialize: true,
140+
validateOnMount: true,
140141
onSubmit: (values: any) => {
141142
onSubmit(values)
142143
},

0 commit comments

Comments
 (0)