From 843b808ef38c6dcc4679bd07886bd7f8568ff135 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 --- Gemfile | 2 +- .../providers/openstack/manager_mixin.rb | 2 +- .../providers/openstack/cloud_manager_spec.rb | 28 +++++++++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index d3d69e379..622584ebb 100644 --- a/Gemfile +++ b/Gemfile @@ -8,7 +8,7 @@ gemspec # Git. Remember to move these dependencies to your gemspec before releasing # your gem to rubygems.org. -# We are using 'miq-module' from gems-pending +# We are using 'miq-module' and 'miq-password' from gems-pending gem "manageiq-gems-pending", ">0", :require => 'manageiq-gems-pending', :git => "https://github.com/ManageIQ/manageiq-gems-pending.git", :branch => "master" # Load Gemfile with dependencies from manageiq 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)