File tree Expand file tree Collapse file tree 9 files changed +27
-28
lines changed
UserSettingsPage/SecurityPage Expand file tree Collapse file tree 9 files changed +27
-28
lines changed Original file line number Diff line number Diff line change @@ -1109,8 +1109,6 @@ func TestUpdateUserPassword(t *testing.T) {
1109
1109
require .Equal (t , database .AuditActionWrite , auditor .AuditLogs ()[numLogs - 1 ].Action )
1110
1110
})
1111
1111
1112
- // FIXME: Re-enable the tests once real logic changed
1113
- // Currently there's no check in code to validate that users have to put the old password
1114
1112
t .Run ("MemberCantUpdateOwnPasswordWithoutOldPassword" , func (t * testing.T ) {
1115
1113
t .Parallel ()
1116
1114
client := coderdtest .New (t , nil )
Original file line number Diff line number Diff line change @@ -1322,11 +1322,11 @@ class ApiMethods {
1322
1322
await this . axios . put ( `/api/v2/users/${ userId } /password` , updatePassword ) ;
1323
1323
} ;
1324
1324
1325
- validateUserPassword = async ( password : string ) : Promise < boolean > => {
1325
+ validateUserPassword = async ( password : string ) : Promise < TypesGen . ValidateUserPasswordResponse > => {
1326
1326
const response = await this . axios . post ( "/api/v2/users/validate-password" , {
1327
1327
password,
1328
1328
} ) ;
1329
- return response . data . valid ;
1329
+ return response . data ;
1330
1330
} ;
1331
1331
1332
1332
getRoles = async ( ) : Promise < Array < TypesGen . AssignableRoles > > => {
Original file line number Diff line number Diff line change @@ -64,7 +64,7 @@ export interface CreateUserFormProps {
64
64
onSubmit : ( user : TypesGen . CreateUserRequestWithOrgs ) => void ;
65
65
onCancel : ( ) => void ;
66
66
onPasswordChange : ( password : string ) => void ;
67
- passwordIsValid : boolean ;
67
+ passwordValidator : TypesGen . ValidateUserPasswordResponse ;
68
68
error ?: unknown ;
69
69
isLoading : boolean ;
70
70
authMethods ?: TypesGen . AuthMethods ;
@@ -91,7 +91,7 @@ export const CreateUserForm: FC<
91
91
onSubmit,
92
92
onCancel,
93
93
onPasswordChange,
94
- passwordIsValid ,
94
+ passwordValidator ,
95
95
error,
96
96
isLoading,
97
97
authMethods,
@@ -206,15 +206,15 @@ export const CreateUserForm: FC<
206
206
( form . values . login_type !== "password" &&
207
207
"No password required for this login type" ) ||
208
208
( form . values . password !== "" &&
209
- ! passwordIsValid &&
210
- "password is not strong enough." ) ,
209
+ ! passwordValidator . valid &&
210
+ passwordValidator . details ) ,
211
211
} ) }
212
212
autoComplete = "current-password"
213
213
fullWidth
214
214
id = "password"
215
215
data-testid = "password-input"
216
216
disabled = { form . values . login_type !== "password" }
217
- error = { ! ! ( form . values . password !== "" && ! passwordIsValid ) }
217
+ error = { ! ! ( form . values . password !== "" && ! passwordValidator . valid ) }
218
218
label = { Language . passwordLabel }
219
219
type = "password"
220
220
/>
Original file line number Diff line number Diff line change @@ -20,12 +20,12 @@ export const CreateUserPage: FC = () => {
20
20
const authMethodsQuery = useQuery ( authMethods ( ) ) ;
21
21
const validatePasswordMutation = useMutation ( validatePassword ( ) ) ;
22
22
23
- const [ passwordIsValid , setPasswordIsValid ] = useState ( false ) ;
23
+ const [ passwordValidator , setPasswordValidator ] = useState ( { valid : false , details : "" } ) ;
24
24
25
25
const validateUserPassword = async ( password : string ) => {
26
26
validatePasswordMutation . mutate ( password , {
27
27
onSuccess : ( data ) => {
28
- setPasswordIsValid ( data ) ;
28
+ setPasswordValidator ( { valid : data . valid , details : data . details } )
29
29
} ,
30
30
} ) ;
31
31
} ;
@@ -53,7 +53,7 @@ export const CreateUserPage: FC = () => {
53
53
navigate ( ".." , { relative : "path" } ) ;
54
54
} }
55
55
onPasswordChange = { debouncedValidateUserPassword }
56
- passwordIsValid = { passwordIsValid }
56
+ passwordValidator = { passwordValidator }
57
57
isLoading = { createUserMutation . isLoading }
58
58
/>
59
59
</ Margins >
Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ export const SetupPage: FC = () => {
29
29
const buildInfoQuery = useQuery ( buildInfo ( metadata [ "build-info" ] ) ) ;
30
30
const navigate = useNavigate ( ) ;
31
31
32
- const [ passwordIsValid , setPasswordIsValid ] = useState ( false ) ;
32
+ const [ passwordValidator , setPasswordValidator ] = useState ( { valid : false , details : "" } ) ;
33
33
34
34
useEffect ( ( ) => {
35
35
if ( ! buildInfoQuery . data ) {
@@ -43,7 +43,7 @@ export const SetupPage: FC = () => {
43
43
const validateUserPassword = async ( password : string ) => {
44
44
validatePasswordMutation . mutate ( password , {
45
45
onSuccess : ( data ) => {
46
- setPasswordIsValid ( data ) ;
46
+ setPasswordValidator ( { valid : data . valid , details : data . details } )
47
47
} ,
48
48
} ) ;
49
49
} ;
@@ -74,7 +74,7 @@ export const SetupPage: FC = () => {
74
74
</ Helmet >
75
75
< SetupPageView
76
76
onPasswordChange = { debouncedValidateUserPassword }
77
- passwordIsValid = { passwordIsValid }
77
+ passwordValidator = { passwordValidator }
78
78
isLoading = { isSigningIn || createFirstUserMutation . isLoading }
79
79
error = { createFirstUserMutation . error }
80
80
onSubmit = { async ( firstUser ) => {
Original file line number Diff line number Diff line change @@ -84,15 +84,15 @@ const numberOfDevelopersOptions = [
84
84
export interface SetupPageViewProps {
85
85
onSubmit : ( firstUser : TypesGen . CreateFirstUserRequest ) => void ;
86
86
onPasswordChange ?: ( password : string ) => void ;
87
- passwordIsValid ?: boolean ;
87
+ passwordValidator : TypesGen . ValidateUserPasswordResponse ;
88
88
error ?: unknown ;
89
89
isLoading ?: boolean ;
90
90
}
91
91
92
92
export const SetupPageView : FC < SetupPageViewProps > = ( {
93
93
onSubmit,
94
94
onPasswordChange,
95
- passwordIsValid = true ,
95
+ passwordValidator ,
96
96
error,
97
97
isLoading,
98
98
} ) => {
@@ -183,9 +183,9 @@ export const SetupPageView: FC<SetupPageViewProps> = ({
183
183
id = "password"
184
184
label = { Language . passwordLabel }
185
185
type = "password"
186
- error = { ! ! ( form . values . password !== "" && ! passwordIsValid ) }
186
+ error = { ! ! ( form . values . password !== "" && ! passwordValidator . valid ) }
187
187
helperText = {
188
- ! passwordIsValid ? "Password is not strong enough." : ""
188
+ ! passwordValidator . valid ? passwordValidator . details : ""
189
189
}
190
190
/>
191
191
< label
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ import type { FC } from "react";
8
8
import { useEffect } from "react" ;
9
9
import { getFormHelpers } from "utils/formUtils" ;
10
10
import * as Yup from "yup" ;
11
+ import type * as TypesGen from "api/typesGenerated" ;
11
12
12
13
interface SecurityFormValues {
13
14
old_password : string ;
@@ -42,7 +43,7 @@ export interface SecurityFormProps {
42
43
disabled : boolean ;
43
44
isLoading : boolean ;
44
45
onPasswordChange : ( password : string ) => void ;
45
- passwordIsValid : boolean ;
46
+ passwordValidator : TypesGen . ValidateUserPasswordResponse ;
46
47
onSubmit : ( values : SecurityFormValues ) => void ;
47
48
error ?: unknown ;
48
49
}
@@ -51,7 +52,7 @@ export const SecurityForm: FC<SecurityFormProps> = ({
51
52
disabled,
52
53
isLoading,
53
54
onPasswordChange,
54
- passwordIsValid ,
55
+ passwordValidator ,
55
56
onSubmit,
56
57
error,
57
58
} ) => {
@@ -96,10 +97,10 @@ export const SecurityForm: FC<SecurityFormProps> = ({
96
97
autoComplete = "password"
97
98
fullWidth
98
99
label = { Language . newPasswordLabel }
99
- error = { ! ! ( form . values . password !== "" && ! passwordIsValid ) }
100
+ error = { ! ! ( form . values . password !== "" && ! passwordValidator . valid ) }
100
101
helperText = {
101
- form . values . password !== "" && ! passwordIsValid
102
- ? "Password is not strong enough."
102
+ form . values . password !== "" && ! passwordValidator . valid
103
+ ? passwordValidator . details
103
104
: ""
104
105
}
105
106
type = "password"
Original file line number Diff line number Diff line change @@ -29,12 +29,12 @@ export const SecurityPage: FC = () => {
29
29
} ) ;
30
30
const singleSignOnSection = useSingleSignOnSection ( ) ;
31
31
32
- const [ passwordIsValid , setPasswordIsValid ] = useState ( false ) ;
32
+ const [ passwordValidator , setPasswordValidator ] = useState ( { valid : false , details : "" } ) ;
33
33
34
34
const validateUserPassword = async ( password : string ) => {
35
35
validatePasswordMutation . mutate ( password , {
36
36
onSuccess : ( data ) => {
37
- setPasswordIsValid ( data ) ;
37
+ setPasswordValidator ( { valid : data . valid , details : data . details } )
38
38
} ,
39
39
} ) ;
40
40
} ;
@@ -56,7 +56,7 @@ export const SecurityPage: FC = () => {
56
56
error : updatePasswordMutation . error ,
57
57
isLoading : updatePasswordMutation . isLoading ,
58
58
onPasswordChange : debouncedValidateUserPassword ,
59
- passwordIsValid : passwordIsValid ,
59
+ passwordValidator : passwordValidator ,
60
60
onSubmit : async ( data ) => {
61
61
await updatePasswordMutation . mutateAsync ( {
62
62
userId : me . id ,
Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ const defaultArgs: ComponentProps<typeof SecurityPageView> = {
16
16
isLoading : false ,
17
17
onSubmit : action ( "onSubmit" ) ,
18
18
onPasswordChange : ( password : string ) => { } ,
19
- passwordIsValid : false ,
19
+ passwordValidator : { valid : false , details : "" } ,
20
20
} ,
21
21
} ,
22
22
oidc : {
You can’t perform that action at this time.
0 commit comments