From 0a94e25b14fd8534e45b32518d1e841a17ef44a4 Mon Sep 17 00:00:00 2001 From: Greg McCullough Date: Fri, 28 Sep 2018 12:04:02 -0400 Subject: [PATCH] Merge pull request #18031 from eclarizio/BZ1602883-Related Do not double encrypt a protected password dialog text field (cherry picked from commit 27c9fe355f36d372ec30ccd0eb26495421db1aa8) https://bugzilla.redhat.com/show_bug.cgi?id=1602883 --- app/models/dialog_field_text_box.rb | 6 +++++- spec/models/dialog_field_text_box_spec.rb | 12 ++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/app/models/dialog_field_text_box.rb b/app/models/dialog_field_text_box.rb index e0e74668b7e..16773a4f47d 100644 --- a/app/models/dialog_field_text_box.rb +++ b/app/models/dialog_field_text_box.rb @@ -31,7 +31,7 @@ def value_from_dialog_fields(dialog_values) def automate_output_value return nil if @value.nil? - return MiqPassword.encrypt(@value) if self.protected? + return MiqPassword.encrypt(@value) if self.protected? && !value_is_already_encrypted? convert_value_to_type end @@ -89,4 +89,8 @@ def load_values_on_init? return true unless show_refresh_button load_values_on_init end + + def value_is_already_encrypted? + return true if MiqPassword.encrypted?(@value) + end end diff --git a/spec/models/dialog_field_text_box_spec.rb b/spec/models/dialog_field_text_box_spec.rb index 6c66d3780b0..872fdbf10a2 100644 --- a/spec/models/dialog_field_text_box_spec.rb +++ b/spec/models/dialog_field_text_box_spec.rb @@ -118,6 +118,18 @@ it "#automate_key_name" do expect(df.automate_key_name).to eq("password::dialog_test field") end + + context "when the value is already encrypted" do + before do + allow(MiqPassword).to receive(:encrypted?).and_return(true) + end + + it "does not double encrypt it" do + df.value = MiqPassword.encrypt("test") + + expect(df.automate_output_value).to be_encrypted("test") + end + end end context "validation" do