Skip to content

Commit

Permalink
Make #auth_url a private Method separate from #swift.
Browse files Browse the repository at this point in the history
In order to test the private mechanisms within more easily, pull the auth_url
construction out of the private method #swift.

Add tests for it as well as for #uri_to_object_path, and to make sure #initialize
sets the container name correctly.

Add fog-openstack and mime-types to the gemspec.
  • Loading branch information
jerryk55 committed Oct 17, 2018
1 parent 2e8c9e8 commit e33d295
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 17 deletions.
14 changes: 7 additions & 7 deletions lib/gems/pending/util/object_storage/miq_swift_storage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ def self.new_with_opts(opts)

def initialize(settings)
super(settings)

# NOTE: This line to be removed once manageiq-ui-class region change implemented.
@bucket_name = URI(@settings[:uri]).host

raise "username and password are required values!" if @settings[:username].nil? || @settings[:password].nil?
Expand Down Expand Up @@ -114,16 +112,18 @@ def container(create_if_missing = true)

private

def swift
return @swift if @swift
require 'fog/openstack'

auth_url = URI::Generic.build(
def auth_url
URI::Generic.build(
:scheme => @security_protocol == 'non-ssl' ? "http" : "https",
:host => @host,
:port => @port.to_i,
:path => "/#{@api_version}#{@api_version == "v3" ? "/auth" : ".0"}/tokens"
).to_s
end

def swift
return @swift if @swift
require 'fog/openstack'

connection_params = {
:openstack_auth_url => auth_url,
Expand Down
2 changes: 2 additions & 0 deletions manageiq-gems-pending.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ Gem::Specification.new do |s|
s.add_runtime_dependency "aws-sdk", "~> 2.9.7"
s.add_runtime_dependency "binary_struct", "~> 2.1"
s.add_runtime_dependency "bundler", ">= 1.8.4" # rails-assets requires bundler >= 1.8.4, see: https://rails-assets.org/
s.add_runtime_dependency "fog-openstack", "~>0.1.22"
s.add_runtime_dependency "linux_admin", "~> 1.0"
s.add_runtime_dependency "mime-types", "~> 3.0"
s.add_runtime_dependency "minitar", "~> 0.6"
s.add_runtime_dependency "more_core_extensions", "~> 3.4"
s.add_runtime_dependency "net-scp", "~> 1.2.1"
Expand Down
70 changes: 60 additions & 10 deletions spec/util/object_storage/miq_swift_storage_spec.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,68 @@
require "util/object_storage/miq_swift_storage"

describe MiqSwiftStorage do
before(:each) do
@uri = "swift://foo.com/abc/def"
@object_storage = described_class.new(:uri => @uri, :username => 'user', :password => 'pass', :region => 'region')
end
context "public methods" do
let(:uri) { "swift://foo.com/abc/def" }
let(:object_storage) { described_class.new(:uri => uri, :username => 'user', :password => 'pass', :region => 'region') }

it "#initialize sets the container_name" do
container_name = object_storage.container_name
expect(container_name).to eq("abc/def")
end

it "#initialize sets the container_name" do
container_name = @object_storage.container_name
expect(container_name).to eq("abc/def")
it "#uri_to_object_path returns a new object path" do
result = object_storage.uri_to_object_path(uri)
expect(result).to eq("def")
end
end

it "#uri_to_object_path returns a new object path" do
result = @object_storage.uri_to_object_path(@uri)
expect(result).to eq("def")
describe "#auth_url (private)" do
context "with non-ssl security protocol" do
let(:uri) { "swift://foo.com:5678/abc/def?region=region&api_version=v3&security_protocol=non-ssl" }
let(:object_storage) { described_class.new(:uri => uri, :username => 'user', :password => 'pass') }
let(:auth_url) { object_storage.send(:auth_url) }

it "sets the scheme to http" do
expect(URI(auth_url).scheme).to eq("http")
end

it "sets the host to foo.com" do
expect(URI(auth_url).host).to eq("foo.com")
end
end

context "with ssl security protocol" do
let(:uri) { "swift://foo.com:5678/abc/def?region=region&api_version=v3&security_protocol=ssl" }
let(:object_storage) { described_class.new(:uri => uri, :username => 'user', :password => 'pass') }
let(:auth_url) { object_storage.send(:auth_url) }

it "sets the scheme to https" do
expect(URI(auth_url).scheme).to eq("https")
end

it "sets the host to foo.com" do
expect(URI(auth_url).host).to eq("foo.com")
end
end

context "with v3 api version" do
let(:uri) { "swift://foo.com:5678/abc/def?region=region&api_version=v3&security_protocol=ssl" }
let(:object_storage) { described_class.new(:uri => uri, :username => 'user', :password => 'pass') }
let(:auth_url) { object_storage.send(:auth_url) }

it "sets the path to a v3 path" do
expect(URI(auth_url).path).to eq("/v3/auth/tokens")
end
end

context "with v2 api version" do
let(:uri) { "swift://foo.com:5678/abc/def?region=region&api_version=v2&security_protocol=ssl" }
let(:object_storage) { described_class.new(:uri => uri, :username => 'user', :password => 'pass') }
let(:auth_url) { object_storage.send(:auth_url) }

it "sets the path to a v2 path" do
expect(URI(auth_url).path).to eq("/v2.0/tokens")
end
end
end
end

0 comments on commit e33d295

Please sign in to comment.