@@ -338,8 +338,8 @@ func (ts *UserTestSuite) TestUserUpdatePassword() {
338338 },
339339 {
340340 desc : "Current password checked when require current password set" ,
341- newPassword : "newpassword123 " ,
342- currentPassword : "password" ,
341+ newPassword : "updateToNewpassword123 " ,
342+ currentPassword : "newpassword123" , // match to the test case above
343343 nonce : "" ,
344344 requireReauthentication : false ,
345345 requireCurrentPassword : true ,
@@ -362,8 +362,13 @@ func (ts *UserTestSuite) TestUserUpdatePassword() {
362362 ts .Run (c .desc , func () {
363363 ts .Config .Security .UpdatePasswordRequireReauthentication = c .requireReauthentication
364364 ts .Config .Security .UpdatePasswordRequireCurrentPassword = c .requireCurrentPassword
365+
366+ userUpdateBody := map [string ]string {"password" : c .newPassword , "nonce" : c .nonce }
367+ if c .requireCurrentPassword {
368+ userUpdateBody ["current_password" ] = c .currentPassword
369+ }
365370 var buffer bytes.Buffer
366- require .NoError (ts .T (), json .NewEncoder (& buffer ).Encode (map [ string ] string { "password" : c . newPassword , "nonce" : c . nonce } ))
371+ require .NoError (ts .T (), json .NewEncoder (& buffer ).Encode (userUpdateBody ))
367372
368373 req := httptest .NewRequest (http .MethodPut , "http://localhost/user" , & buffer )
369374 req .Header .Set ("Content-Type" , "application/json" )
@@ -389,6 +394,7 @@ func (ts *UserTestSuite) TestUserUpdatePassword() {
389394}
390395
391396func (ts * UserTestSuite ) TestUserUpdatePasswordNoReauthenticationRequired () {
397+ ts .Config .Security .UpdatePasswordRequireCurrentPassword = false
392398 u , err := models .FindUserByEmailAndAudience (ts .API .db , "test@example.com" , ts .Config .JWT .Aud )
393399 require .NoError (ts .T (), err )
394400
@@ -452,7 +458,7 @@ func (ts *UserTestSuite) TestUserUpdatePasswordNoReauthenticationRequired() {
452458
453459func (ts * UserTestSuite ) TestUserUpdatePasswordReauthentication () {
454460 ts .Config .Security .UpdatePasswordRequireReauthentication = true
455-
461+ ts . Config . Security . UpdatePasswordRequireCurrentPassword = false
456462 u , err := models .FindUserByEmailAndAudience (ts .API .db , "test@example.com" , ts .Config .JWT .Aud )
457463 require .NoError (ts .T (), err )
458464
@@ -510,6 +516,7 @@ func (ts *UserTestSuite) TestUserUpdatePasswordReauthentication() {
510516
511517func (ts * UserTestSuite ) TestUserUpdatePasswordLogoutOtherSessions () {
512518 ts .Config .Security .UpdatePasswordRequireReauthentication = false
519+ ts .Config .Security .UpdatePasswordRequireCurrentPassword = false
513520 u , err := models .FindUserByEmailAndAudience (ts .API .db , "test@example.com" , ts .Config .JWT .Aud )
514521 require .NoError (ts .T (), err )
515522
@@ -609,6 +616,7 @@ func (ts *UserTestSuite) TestUserUpdatePasswordSendsNotificationEmail() {
609616 for _ , c := range cases {
610617 ts .Run (c .desc , func () {
611618 ts .Config .Security .UpdatePasswordRequireReauthentication = false
619+ ts .Config .Security .UpdatePasswordRequireCurrentPassword = false
612620 ts .Config .Mailer .Autoconfirm = false
613621 ts .Config .Mailer .Notifications .PasswordChangedEnabled = c .notificationEnabled
614622
0 commit comments