From d6ddf0fcb6a61406846087465c598f65b585d5cc Mon Sep 17 00:00:00 2001 From: Jillian Tullo Date: Tue, 27 Jun 2017 10:00:42 -0400 Subject: [PATCH] allow raw_connect to accept encrypted passwords --- .../providers/openstack/manager_mixin.rb | 2 +- .../providers/openstack/cloud_manager_spec.rb | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/app/models/manageiq/providers/openstack/manager_mixin.rb b/app/models/manageiq/providers/openstack/manager_mixin.rb index f518a6146..31108a9eb 100644 --- a/app/models/manageiq/providers/openstack/manager_mixin.rb +++ b/app/models/manageiq/providers/openstack/manager_mixin.rb @@ -13,7 +13,7 @@ module ManageIQ::Providers::Openstack::ManagerMixin module ClassMethods def raw_connect(username, password, auth_url, service = "Compute") require 'manageiq/providers/openstack/legacy/openstack_handle' - OpenstackHandle::Handle.raw_connect(username, password, auth_url, service) + OpenstackHandle::Handle.raw_connect(username, MiqPassword.try_decrypt(password), auth_url, service) end def auth_url(address, port = nil) diff --git a/spec/models/manageiq/providers/openstack/cloud_manager_spec.rb b/spec/models/manageiq/providers/openstack/cloud_manager_spec.rb index 2912b5244..c6497729a 100644 --- a/spec/models/manageiq/providers/openstack/cloud_manager_spec.rb +++ b/spec/models/manageiq/providers/openstack/cloud_manager_spec.rb @@ -53,6 +53,34 @@ end end + describe ".raw_connect" do + before do + require 'manageiq/providers/openstack/legacy/openstack_handle/handle' + end + + it "accepts and decrypts encrypted passwords" do + expect(OpenstackHandle::Handle).to receive(:raw_connect).with( + "dummy", + "dummy", + "http://address:5000/v2.0/tokens", + "Compute" + ) + + described_class.raw_connect("dummy", MiqPassword.encrypt("dummy"), "http://address:5000/v2.0/tokens", "Compute") + end + + it "works with unencrypted passwords" do + expect(OpenstackHandle::Handle).to receive(:raw_connect).with( + "dummy", + "dummy", + "http://address:5000/v2.0/tokens", + "Compute" + ) + + described_class.raw_connect("dummy", "dummy", "http://address:5000/v2.0/tokens", "Compute") + end + end + context "validation" do before :each do @ems = FactoryGirl.create(:ems_openstack_with_authentication)