Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log encryption failures #127

Merged
merged 2 commits into from
Dec 11, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion lib/miq_automation_engine/engine/miq_ae_engine/miq_ae_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ def self.convert_value_based_on_datatype(value, datatype)
return value.to_i if datatype == 'integer' || datatype == 'Fixnum'
return value.to_f if datatype == 'float' || datatype == 'Float'
return value.gsub(/[\[\]]/, '').strip.split(/\s*,\s*/) if datatype == 'array' && value.class == String
return MiqAePassword.new(MiqAePassword.decrypt(value)) if datatype == 'password'
return decrypt_password(value) if datatype == 'password'

if datatype &&
(service_model = "MiqAeMethodService::MiqAeService#{SM_LOOKUP[datatype]}".safe_constantize)
Expand All @@ -558,6 +558,14 @@ def self.convert_value_based_on_datatype(value, datatype)
value
end

def self.decrypt_password(value)
MiqAePassword.new(MiqAePassword.decrypt(value))
rescue MiqPassword::MiqPasswordError => err
$miq_ae_logger.error("Error decrypting password #{err.message}. Is this password imported from a different environment?")
raise err
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about changing the log message to:
"Error decrypting password: [#{err.message}]. Possible cause: Password value was encrypted with a different encryption key."

The logging message from the included test would read:
Error decrypting password: [can not decrypt v0_key encrypted string]. Possible cause: Password value was encrypted with a different encryption key.

Minor but you can just use raise to re-raise the last error. You do not need to pass the object.

end
private_class_method :decrypt_password

def process_assertion(f, message, args)
Benchmark.current_realtime[:assertion_count] += 1
Benchmark.realtime_block(:assertion_time) do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def instantiate(uri)
return nil if obj.nil?
MiqAeServiceObject.new(obj, self)
rescue => e
$miq_ae_logger.error("instantiate failed : #{e.message}")
return nil
end

Expand Down
17 changes: 17 additions & 0 deletions spec/miq_ae_object_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -300,3 +300,20 @@ def value_match(value, xml_value)
end
end
end

describe MiqAeEngine::MiqAeObject do
context "password" do
let(:p45) { "Pneumonoultramicroscopicsilicovolcanoconiosis" }
let(:p45_encrypted) { MiqAePassword.encrypt(p45) }

it "can decrypt passwords" do
expect(described_class.convert_value_based_on_datatype(p45_encrypted, 'password').encStr).to eq(p45_encrypted)
end

it "raises exception for bogus passwords" do
expect do
described_class.convert_value_based_on_datatype('gobbledygook', 'password')
end.to raise_exception(MiqPassword::MiqPasswordError)
end
end
end