Skip to content

Commit f0776b5

Browse files
authored
Merge pull request #1596 from RedisInsight/fe/bugfix/RI-4022
#RI-4022 - fix ssh username validation, fix maxlength
2 parents 2807b8d + 52f350b commit f0776b5

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed

redisinsight/ui/src/pages/home/components/AddInstanceForm/InstanceForm/InstanceForm.spec.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,15 @@ describe('InstanceForm', () => {
749749
)
750750
})
751751

752+
expect(screen.getByTestId(BTN_SUBMIT)).toBeDisabled()
753+
754+
await act(() => {
755+
fireEvent.change(
756+
screen.getByTestId('sshUsername'),
757+
{ target: { value: 'username' } }
758+
)
759+
})
760+
752761
expect(screen.getByTestId(BTN_SUBMIT)).not.toBeDisabled()
753762
})
754763

@@ -783,6 +792,10 @@ describe('InstanceForm', () => {
783792
screen.getByTestId('sshHost'),
784793
{ target: { value: 'localhost' } }
785794
)
795+
fireEvent.change(
796+
screen.getByTestId('sshUsername'),
797+
{ target: { value: 'username' } }
798+
)
786799
})
787800

788801
expect(screen.getByTestId(BTN_SUBMIT)).toBeDisabled()
@@ -827,6 +840,11 @@ describe('InstanceForm', () => {
827840
{ target: { value: '1771' } }
828841
)
829842

843+
fireEvent.change(
844+
screen.getByTestId('sshUsername'),
845+
{ target: { value: 'username' } }
846+
)
847+
830848
fireEvent.change(
831849
screen.getByTestId('sshPassword'),
832850
{ target: { value: '123' } }
@@ -841,6 +859,7 @@ describe('InstanceForm', () => {
841859
expect.objectContaining({
842860
sshHost: 'localhost',
843861
sshPort: '1771',
862+
sshUsername: 'username',
844863
sshPassword: '123',
845864
})
846865
)
@@ -879,6 +898,11 @@ describe('InstanceForm', () => {
879898
{ target: { value: '1771' } }
880899
)
881900

901+
fireEvent.change(
902+
screen.getByTestId('sshUsername'),
903+
{ target: { value: 'username' } }
904+
)
905+
882906
fireEvent.change(
883907
screen.getByTestId('sshPrivateKey'),
884908
{ target: { value: '123444' } }
@@ -898,6 +922,7 @@ describe('InstanceForm', () => {
898922
expect.objectContaining({
899923
sshHost: 'localhost',
900924
sshPort: '1771',
925+
sshUsername: 'username',
901926
sshPrivateKey: '123444',
902927
sshPassphrase: '123444',
903928
})

redisinsight/ui/src/pages/home/components/AddInstanceForm/InstanceForm/InstanceForm.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,9 @@ const AddStandaloneForm = (props: Props) => {
262262
if (!values.sshPort) {
263263
errs.sshPort = fieldDisplayNames.sshPort
264264
}
265+
if (!values.sshUsername) {
266+
errs.sshUsername = fieldDisplayNames.sshUsername
267+
}
265268
if (values.sshPassType === SshPassType.PrivateKey && !values.sshPrivateKey) {
266269
errs.sshPrivateKey = fieldDisplayNames.sshPrivateKey
267270
}

redisinsight/ui/src/pages/home/components/AddInstanceForm/InstanceForm/constants.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,6 @@ export const fieldDisplayNames = {
2121
sentinelMasterName: 'Primary Group Name',
2222
sshHost: 'SSH Host',
2323
sshPort: 'SSH Port',
24-
sshPrivateKey: 'SSH Private Key'
24+
sshPrivateKey: 'SSH Private Key',
25+
sshUsername: 'SSH Username',
2526
}

redisinsight/ui/src/pages/home/components/AddInstanceForm/InstanceForm/form-components/SSHDetails.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ const SSHDetails = (props: Props) => {
121121
className={flexGroupClassName}
122122
>
123123
<EuiFlexItem className={cx(flexItemClassName)}>
124-
<EuiFormRow label="Username">
124+
<EuiFormRow label="Username*">
125125
<EuiFieldText
126126
name="sshUsername"
127127
id="sshUsername"
@@ -196,6 +196,7 @@ const SSHDetails = (props: Props) => {
196196
value={formik.values.sshPrivateKey ?? ''}
197197
onChange={formik.handleChange}
198198
fullWidth
199+
maxLength={50_000}
199200
placeholder="Enter SSH Private Key"
200201
data-testid="sshPrivateKey"
201202
/>

0 commit comments

Comments
 (0)