A platform for community discussion. Free, open, simple.
FIX: setting new password should reset password_expired_at (#29296)
Kelv698748bfec64
diff --git a/app/models/user_password.rb b/app/models/user_password.rbindex bf5b3b5ad7c..27236d31a21 100644--- a/app/models/user_password.rb+++ b/app/models/user_password.rb@@ -59,6 +59,7 @@ class UserPassword < ActiveRecord::Baseself.password_salt = SecureRandom.hex(PASSWORD_SALT_LENGTH)self.password_algorithm = TARGET_PASSWORD_ALGORITHMself.password_hash = hash_password(@raw_password, password_salt, password_algorithm)+ self.password_expired_at = nilenddef regen_password!(pw)diff --git a/spec/models/user_password_spec.rb b/spec/models/user_password_spec.rbindex 908a4fc4d7d..0db6be80805 100644--- a/spec/models/user_password_spec.rb+++ b/spec/models/user_password_spec.rb@@ -1,6 +1,48 @@# frozen_string_literal: trueRSpec.describe UserPassword do+ describe "#ensure_password_is_hashed" do+ let(:password) { SecureRandom.hex }+ fab!(:user_password)++ it "ensures password_hash, password_salt, password_algorithm are saved correctly" do+ user_password.update!(password:)++ expect(user_password.password_salt).not_to be_nil+ expect(user_password.password_algorithm).to eq(UserPassword::TARGET_PASSWORD_ALGORITHM)+ new_hash =+ described_class.new.send(+ :hash_password,+ password,+ user_password.password_salt,+ user_password.password_algorithm,+ )+ expect(user_password.password_hash).to eq(new_hash)+ end++ it "does not hash the password if no password given" do+ expect { user_password.update!(password: nil) }.not_to change(user_password, :password_hash)+ end++ context "when password was expired" do+ fab!(:expired_user_password)++ it "resets expired password to nil when saving new password" do+ expect { expired_user_password.update!(password: SecureRandom.hex) }.to change(+ expired_user_password,+ :password_expired_at,+ ).to(nil)+ end++ it "does not remove password_expired_at if no password given" do+ expect { expired_user_password.update!(password: nil) }.not_to change(+ user_password,+ :password_expired_at,+ )+ end+ end+ end+describe "#confirm_password?" docontext "when input password is same as saved password" dolet(:pw) { SecureRandom.hex }