Skip to content

Commit 71267be

Browse files
authored
Merge pull request #3046 from RedisInsight/fe/bugfix/RI-5414
#RI-5414 - add hostname to redis parsing url
2 parents b111cfe + b4143b3 commit 71267be

File tree

3 files changed

+19
-16
lines changed

3 files changed

+19
-16
lines changed

redisinsight/ui/src/pages/home/utils/form.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ export const autoFillFormDetails = (
226226

227227
case InstanceType.Standalone: {
228228
return ({
229-
name: details.host || initialValues.name || 'localhost:6379',
229+
name: details.hostname || initialValues.name || 'localhost:6379',
230230
host: details.host || initialValues.host || 'localhost',
231231
port: `${details.port || initialValues.port || 9443}`,
232232
username: details.username || '',

redisinsight/ui/src/utils/parseRedisUrl.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ interface ParsedRedisUrl {
1414
password: string
1515
host: string
1616
port: Maybe<number>
17+
hostname: Maybe<string>
1718
dbNumber: Maybe<number>
1819
}
1920

@@ -29,6 +30,7 @@ const parseRedisUrl = (urlString: string = ''): Nullable<ParsedRedisUrl> => {
2930
password: '',
3031
host,
3132
port: port ? parseInt(port, 10) : undefined,
33+
hostname: port ? `${host}:${port}` : host,
3234
dbNumber: undefined
3335
}
3436
}
@@ -50,6 +52,7 @@ const parseRedisUrl = (urlString: string = ''): Nullable<ParsedRedisUrl> => {
5052
password: password || '',
5153
host,
5254
port: port ? parseInt(port, 10) : undefined,
55+
hostname: port ? `${host}:${port}` : host,
5356
dbNumber: dbNumber ? parseInt(dbNumber, 10) : undefined
5457
}
5558
}

redisinsight/ui/src/utils/tests/parseRedisUrl.spec.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,21 @@ const defaultRedisParams = {
1111
const parseRedisUrlTests: Array<[string, any]> = [
1212
['http://user:pass@localhost:6380', null],
1313
['localhost', null],
14-
['localhost:6379', { ...defaultRedisParams, host: 'localhost', port: 6379 }],
15-
['redis://localhost', { ...defaultRedisParams, host: 'localhost' }],
16-
['redis://:@localhost:6380', { ...defaultRedisParams, host: 'localhost', port: 6380 }],
17-
['redis://user:pass/@localhost:6380', { ...defaultRedisParams, host: 'localhost', port: 6380, username: 'user', password: 'pass/' }],
18-
['redis://user:pa@ss@localhost:6380', { ...defaultRedisParams, host: 'localhost', port: 6380, username: 'user', password: 'pa@ss' }],
19-
['redis://us@er:pa@ss@localhost:6380', { ...defaultRedisParams, host: 'localhost', port: 6380, username: 'us@er', password: 'pa@ss' }],
20-
['redis://us@er:pa@:ss@localhost:6380', { ...defaultRedisParams, host: 'localhost', port: 6380, username: 'us@er', password: 'pa@:ss' }],
21-
['redis://localhost:6380', { ...defaultRedisParams, host: 'localhost', port: 6380 }],
22-
['redis://@localhost:6380', { ...defaultRedisParams, host: 'localhost', port: 6380 }],
23-
['redis://user@localhost:6380', { ...defaultRedisParams, username: 'user', host: 'localhost', port: 6380 }],
24-
['redis://:pass@localhost:6380', { ...defaultRedisParams, password: 'pass', host: 'localhost', port: 6380 }],
25-
['redis://user:pass@localhost:6380', { ...defaultRedisParams, username: 'user', password: 'pass', host: 'localhost', port: 6380 }],
26-
['rediss://user:pa%712ss@localhost:6380', { ...defaultRedisParams, protocol: 'rediss', username: 'user', password: 'pa%712ss', host: 'localhost', port: 6380 }],
27-
['rediss://d&@&21^$:pa%@7:12:[email protected]:6380', { ...defaultRedisParams, protocol: 'rediss', username: 'd&@&21^$', password: 'pa%@7:12:ss', host: 'local-host-123.net.com', port: 6380 }],
28-
['rediss://user:pa%712ss@localhost:6380/2', { protocol: 'rediss', username: 'user', password: 'pa%712ss', host: 'localhost', port: 6380, dbNumber: 2 }],
14+
['localhost:6379', { ...defaultRedisParams, host: 'localhost', port: 6379, hostname: 'localhost:6379' }],
15+
['redis://localhost', { ...defaultRedisParams, host: 'localhost', hostname: 'localhost' }],
16+
['redis://:@localhost:6380', { ...defaultRedisParams, host: 'localhost', port: 6380, hostname: 'localhost:6380' }],
17+
['redis://user:pass/@localhost:6380', { ...defaultRedisParams, host: 'localhost', port: 6380, hostname: 'localhost:6380', username: 'user', password: 'pass/' }],
18+
['redis://user:pa@ss@localhost:6380', { ...defaultRedisParams, host: 'localhost', port: 6380, hostname: 'localhost:6380', username: 'user', password: 'pa@ss' }],
19+
['redis://us@er:pa@ss@localhost:6380', { ...defaultRedisParams, host: 'localhost', port: 6380, hostname: 'localhost:6380', username: 'us@er', password: 'pa@ss' }],
20+
['redis://us@er:pa@:ss@localhost:6380', { ...defaultRedisParams, host: 'localhost', port: 6380, hostname: 'localhost:6380', username: 'us@er', password: 'pa@:ss' }],
21+
['redis://localhost:6380', { ...defaultRedisParams, host: 'localhost', port: 6380, hostname: 'localhost:6380', }],
22+
['redis://@localhost:6380', { ...defaultRedisParams, host: 'localhost', port: 6380, hostname: 'localhost:6380', }],
23+
['redis://user@localhost:6380', { ...defaultRedisParams, username: 'user', host: 'localhost', port: 6380, hostname: 'localhost:6380', }],
24+
['redis://:pass@localhost:6380', { ...defaultRedisParams, password: 'pass', host: 'localhost', port: 6380, hostname: 'localhost:6380', }],
25+
['redis://user:pass@localhost:6380', { ...defaultRedisParams, username: 'user', password: 'pass', host: 'localhost', port: 6380, hostname: 'localhost:6380', }],
26+
['rediss://user:pa%712ss@localhost:6380', { ...defaultRedisParams, protocol: 'rediss', username: 'user', password: 'pa%712ss', host: 'localhost', port: 6380, hostname: 'localhost:6380', }],
27+
['rediss://d&@&21^$:pa%@7:12:[email protected]:6380', { ...defaultRedisParams, protocol: 'rediss', username: 'd&@&21^$', password: 'pa%@7:12:ss', host: 'local-host-123.net.com', port: 6380, hostname: 'local-host-123.net.com:6380', }],
28+
['rediss://user:pa%712ss@localhost:6380/2', { protocol: 'rediss', username: 'user', password: 'pa%712ss', host: 'localhost', port: 6380, hostname: 'localhost:6380', dbNumber: 2 }],
2929
]
3030

3131
describe('parseRedisUrl', () => {

0 commit comments

Comments
 (0)