Skip to content

Commit

Permalink
Merge pull request #17345 from douglasgabriel/chg_pass
Browse files Browse the repository at this point in the history
Removing confirm_password field from change_password routine
  • Loading branch information
agrare authored Apr 26, 2018
2 parents 3d0c76e + 9ce156b commit 7f77ae9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 19 deletions.
15 changes: 5 additions & 10 deletions app/models/mixins/authentication_mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -345,13 +345,12 @@ def default_authentication
#
# @param [current_password] password currently used for connected userId in provider client
# @param [new_password] password that will replace the current one
# @param [confirm_password] must confirm the value of the `new_password`
#
# @return [Boolean] true if the routine is executed successfully
#
def change_password(current_password, new_password, confirm_password, auth_type = :default)
def change_password(current_password, new_password, auth_type = :default)
raise MiqException::Error, _("Change Password is not supported for #{self.class.description} provider") unless supports?(:change_password)
if change_password_params_valid?(current_password, new_password, confirm_password)
if change_password_params_valid?(current_password, new_password)
raw_change_password(current_password, new_password)
update_authentication(auth_type => {:userid => authentication_userid, :password => new_password})
end
Expand Down Expand Up @@ -445,16 +444,12 @@ def authentication_delete(type)
# Verifies if the change password params are valid
#
# @raise [MiqException::Error] if some required data is missing
# if new_password and confirm_password are differents
#
# @return [Boolean] true if the params are fine
#
def change_password_params_valid?(current_password, new_password, confirm_password)
if current_password.blank? || new_password.blank? || confirm_password.blank?
raise MiqException::Error, _("Please, fill the current_password, new_password and confirm_password fields.")
end
raise MiqException::Error, _("Confirm password did not match.") unless new_password.eql?(confirm_password)
def change_password_params_valid?(current_password, new_password)
return true unless current_password.blank? || new_password.blank?

true
raise MiqException::Error, _("Please, fill the current_password and new_password fields.")
end
end
10 changes: 1 addition & 9 deletions spec/models/mixins/authentication_mixin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -703,15 +703,7 @@ def self.name; "TestClass"; end
allow(@ems).to receive(:supports?).with(:change_password) { true }

expect { @ems.change_password(current_password, new_password, confirm_password) }
.to raise_error(MiqException::Error, "Please, fill the current_password, new_password and confirm_password fields.")
end

it "should fail if the confirm password is not equal to new password" do
confirm_password = "different_pass"
allow(@ems).to receive(:supports?).with(:change_password) { true }

expect { @ems.change_password(current_password, new_password, confirm_password) }
.to raise_error(MiqException::Error, "Confirm password did not match.")
.to raise_error(MiqException::Error, "Please, fill the current_password and new_password fields.")
end

it "should fail if the provider doesn't support this operation" do
Expand Down

0 comments on commit 7f77ae9

Please sign in to comment.