
Starting on the identity_uri blueprint. A difference between the public auth_uri and the admin identity_uri is that the identity_uri does not include the path/version (/v2.0). And the auth_uri has to modify the version depending upon the needs of the environment. There existed a helper routine called, auth_uri_transform, so to be consistent and make this easy to follow, I created a identity_uri_transform which simply removes the path/version from the uri given. This helper will then be used thru out the cookbooks to make the switch to the identity_uri very easy. I guess the alturnatives are messing with our generic endpoint definitions/methods, but since they are used for many different purposes, I think having another matching transform method is the right way to go here. Bumped version for adding new method which other cookbooks will depend upon. Change-Id: I035a4491945c600dea8feb317b357a1a69da28cd Implements: blueprint identity-uri
136 lines
3.5 KiB
Ruby
136 lines
3.5 KiB
Ruby
# encoding: UTF-8
|
|
require_relative 'spec_helper'
|
|
require ::File.join ::File.dirname(__FILE__), '..', 'libraries', 'uri'
|
|
require 'uri'
|
|
|
|
describe 'Openstack uri' do
|
|
let(:subject) { Object.new.extend(Openstack) }
|
|
|
|
describe '#uri_from_hash' do
|
|
it 'returns nil when no host or uri key found' do
|
|
hash = {
|
|
'port' => 8888,
|
|
'path' => '/path'
|
|
}
|
|
expect(
|
|
subject.uri_from_hash(hash)
|
|
).to be_nil
|
|
end
|
|
|
|
it 'returns uri when uri key found, ignoring other parts' do
|
|
uri = 'http://localhost/'
|
|
hash = {
|
|
'port' => 8888,
|
|
'path' => '/path',
|
|
'uri' => uri
|
|
}
|
|
result = subject.uri_from_hash(hash)
|
|
expect(result).to be_a URI
|
|
expect(result.to_s).to eq(uri)
|
|
end
|
|
|
|
it 'constructs from host' do
|
|
uri = 'https://localhost:8888/path'
|
|
hash = {
|
|
'scheme' => 'https',
|
|
'port' => 8888,
|
|
'path' => '/path',
|
|
'host' => 'localhost'
|
|
}
|
|
expect(
|
|
subject.uri_from_hash(hash).to_s
|
|
).to eq(uri)
|
|
end
|
|
|
|
it 'constructs with defaults' do
|
|
uri = 'https://localhost'
|
|
hash = {
|
|
'scheme' => 'https',
|
|
'host' => 'localhost'
|
|
}
|
|
expect(
|
|
subject.uri_from_hash(hash).to_s
|
|
).to eq(uri)
|
|
end
|
|
|
|
it 'constructs with extraneous keys' do
|
|
uri = 'http://localhost'
|
|
hash = {
|
|
'host' => 'localhost',
|
|
'network' => 'public' # To emulate the osops-utils::ip_location way...
|
|
}
|
|
expect(
|
|
subject.uri_from_hash(hash).to_s
|
|
).to eq(uri)
|
|
end
|
|
end
|
|
|
|
describe '#uri_join_paths' do
|
|
it 'returns nil when no paths are passed in' do
|
|
expect(subject.uri_join_paths).to be_nil
|
|
end
|
|
|
|
it 'preserves absolute path when only absolute path passed in' do
|
|
path = '/abspath'
|
|
expect(
|
|
subject.uri_join_paths(path)
|
|
).to eq(path)
|
|
end
|
|
|
|
it 'preserves relative path when only relative path passed in' do
|
|
path = 'abspath/'
|
|
expect(
|
|
subject.uri_join_paths(path)
|
|
).to eq(path)
|
|
end
|
|
|
|
it 'preserves leadng and trailing slashes' do
|
|
expected = '/path/to/resource/'
|
|
expect(
|
|
subject.uri_join_paths('/path', 'to', 'resource/')
|
|
).to eq(expected)
|
|
end
|
|
|
|
it 'removes extraneous intermediate slashes' do
|
|
expected = '/path/to/resource'
|
|
expect(
|
|
subject.uri_join_paths('/path', '//to/', '/resource')
|
|
).to eq(expected)
|
|
end
|
|
end
|
|
|
|
describe '#auth_uri_transform' do
|
|
it 'preserves the original auth uri when the auth version passed is v2.0' do
|
|
auth_version = 'v2.0'
|
|
auth_uri = 'http://localhost:5000/v2.0'
|
|
expect(
|
|
subject.auth_uri_transform(auth_uri, auth_version)
|
|
).to eq(auth_uri)
|
|
end
|
|
|
|
it 'substitute /v2.0 with /v3 in the passed auth uri when auth version passed is v3.0' do
|
|
auth_version = 'v3.0'
|
|
auth_uri = 'http://localhost:5000/v2.0'
|
|
expected_auth_uri = 'http://localhost:5000/v3'
|
|
expect(
|
|
subject.auth_uri_transform(auth_uri, auth_version)
|
|
).to eq(expected_auth_uri)
|
|
end
|
|
end
|
|
|
|
describe '#identity_uri_transform' do
|
|
it 'removes the path segment from identity admin endpoint' do
|
|
expect(
|
|
subject.identity_uri_transform('http://localhost:35357/v2.0')
|
|
).to eq('http://localhost:35357/')
|
|
end
|
|
|
|
it 'does not effect a valid identity admin endpoint' do
|
|
identity_uri = 'http://localhost:35357/'
|
|
expect(
|
|
subject.identity_uri_transform(identity_uri)
|
|
).to eq(identity_uri)
|
|
end
|
|
end
|
|
end
|