@@ -1056,6 +1056,31 @@ func TestUpdateUserPassword(t *testing.T) {
1056
1056
require .NoError (t , err , "member should login successfully with the new password" )
1057
1057
})
1058
1058
1059
+ t .Run ("AuditorCantUpdateOtherUserPassword" , func (t * testing.T ) {
1060
+ t .Parallel ()
1061
+ client := coderdtest .New (t , nil )
1062
+ owner := coderdtest .CreateFirstUser (t , client )
1063
+
1064
+ auditor , _ := coderdtest .CreateAnotherUser (t , client , owner .OrganizationID , rbac .RoleAuditor ())
1065
+
1066
+ ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitLong )
1067
+ defer cancel ()
1068
+
1069
+ member , err := client .CreateUserWithOrgs (ctx , codersdk.CreateUserRequestWithOrgs {
1070
+ Email : "coder@coder.com" ,
1071
+ Username : "coder" ,
1072
+ Password : "SomeStrongPassword!" ,
1073
+ OrganizationIDs : []uuid.UUID {owner .OrganizationID },
1074
+ })
1075
+ require .NoError (t , err , "create member" )
1076
+
1077
+ err = auditor .UpdateUserPassword (ctx , member .ID .String (), codersdk.UpdateUserPasswordRequest {
1078
+ Password : "SomeNewStrongPassword!" ,
1079
+ })
1080
+ require .Error (t , err , "auditor should not be able to update member password" )
1081
+ require .ErrorContains (t , err , "unexpected status code 404: Resource not found or you do not have access to this resource" )
1082
+ })
1083
+
1059
1084
t .Run ("MemberCanUpdateOwnPassword" , func (t * testing.T ) {
1060
1085
t .Parallel ()
1061
1086
auditor := audit .NewMock ()
@@ -1097,6 +1122,7 @@ func TestUpdateUserPassword(t *testing.T) {
1097
1122
Password : "newpassword" ,
1098
1123
})
1099
1124
require .Error (t , err , "member should not be able to update own password without providing old password" )
1125
+ require .ErrorContains (t , err , "Old password is required." )
1100
1126
})
1101
1127
1102
1128
t .Run ("AuditorCantTellIfPasswordIncorrect" , func (t * testing.T ) {
@@ -1133,7 +1159,7 @@ func TestUpdateUserPassword(t *testing.T) {
1133
1159
require .Equal (t , int32 (http .StatusNotFound ), auditor .AuditLogs ()[numLogs - 1 ].StatusCode )
1134
1160
})
1135
1161
1136
- t .Run ("AdminCanUpdateOwnPasswordWithoutOldPassword " , func (t * testing.T ) {
1162
+ t .Run ("AdminCantUpdateOwnPasswordWithoutOldPassword " , func (t * testing.T ) {
1137
1163
t .Parallel ()
1138
1164
auditor := audit .NewMock ()
1139
1165
client := coderdtest .New (t , & coderdtest.Options {Auditor : auditor })
@@ -1150,7 +1176,8 @@ func TestUpdateUserPassword(t *testing.T) {
1150
1176
})
1151
1177
numLogs ++ // add an audit log for user update
1152
1178
1153
- require .NoError (t , err , "admin should be able to update own password without providing old password" )
1179
+ require .Error (t , err , "admin should not be able to update own password without providing old password" )
1180
+ require .ErrorContains (t , err , "Old password is required." )
1154
1181
1155
1182
require .Len (t , auditor .AuditLogs (), numLogs )
1156
1183
require .Equal (t , database .AuditActionWrite , auditor .AuditLogs ()[numLogs - 1 ].Action )
@@ -1170,7 +1197,8 @@ func TestUpdateUserPassword(t *testing.T) {
1170
1197
require .NoError (t , err )
1171
1198
1172
1199
err = client .UpdateUserPassword (ctx , "me" , codersdk.UpdateUserPasswordRequest {
1173
- Password : "MyNewSecurePassword!" ,
1200
+ OldPassword : "SomeSecurePassword!" ,
1201
+ Password : "MyNewSecurePassword!" ,
1174
1202
})
1175
1203
require .NoError (t , err )
1176
1204
0 commit comments