3 require 'puppet/provider/keystone'
6 klass = Puppet::Provider::Keystone
8 class Puppet::Provider::Keystone
9 @credentials = Puppet::Provider::Openstack::CredentialsV2_0.new
19 describe Puppet::Provider::Keystone do
25 describe 'when retrieving the security token' do
26 it 'should return nothing if there is no keystone config file' do
27 File.expects(:exists?).with("/etc/keystone/keystone.conf").returns(false)
28 expect(klass.get_admin_token).to be_nil
31 it 'should return nothing if the keystone config file does not have a DEFAULT section' do
33 File.expects(:exists?).with("/etc/keystone/keystone.conf").returns(true)
34 Puppet::Util::IniConfig::File.expects(:new).returns(mock)
35 mock.expects(:read).with('/etc/keystone/keystone.conf')
36 expect(klass.get_admin_token).to be_nil
39 it 'should fail if the keystone config file does not contain an admin token' do
40 mock = {'DEFAULT' => {'not_a_token' => 'foo'}}
41 File.expects(:exists?).with("/etc/keystone/keystone.conf").returns(true)
42 Puppet::Util::IniConfig::File.expects(:new).returns(mock)
43 mock.expects(:read).with('/etc/keystone/keystone.conf')
44 expect(klass.get_admin_token).to be_nil
47 it 'should parse the admin token if it is in the config file' do
48 mock = {'DEFAULT' => {'admin_token' => 'foo'}}
49 File.expects(:exists?).with("/etc/keystone/keystone.conf").returns(true)
50 Puppet::Util::IniConfig::File.expects(:new).returns(mock)
51 mock.expects(:read).with('/etc/keystone/keystone.conf')
52 expect(klass.get_admin_token).to eq('foo')
55 it 'should use the specified bind_host in the admin endpoint' do
56 mock = {'DEFAULT' => {'admin_bind_host' => '192.168.56.210', 'admin_port' => '35357' }}
57 File.expects(:exists?).with("/etc/keystone/keystone.conf").returns(true)
58 Puppet::Util::IniConfig::File.expects(:new).returns(mock)
59 mock.expects(:read).with('/etc/keystone/keystone.conf')
60 expect(klass.get_admin_endpoint).to eq('http://192.168.56.210:35357/v2.0/')
63 it 'should use localhost in the admin endpoint if bind_host is 0.0.0.0' do
64 mock = {'DEFAULT' => { 'admin_bind_host' => '0.0.0.0', 'admin_port' => '35357' }}
65 File.expects(:exists?).with("/etc/keystone/keystone.conf").returns(true)
66 Puppet::Util::IniConfig::File.expects(:new).returns(mock)
67 mock.expects(:read).with('/etc/keystone/keystone.conf')
68 expect(klass.get_admin_endpoint).to eq('http://127.0.0.1:35357/v2.0/')
71 it 'should use [::1] in the admin endpoint if bind_host is ::0' do
72 mock = {'DEFAULT' => { 'admin_bind_host' => '::0', 'admin_port' => '35357' }}
73 File.expects(:exists?).with("/etc/keystone/keystone.conf").returns(true)
74 Puppet::Util::IniConfig::File.expects(:new).returns(mock)
75 mock.expects(:read).with('/etc/keystone/keystone.conf')
76 expect(klass.get_admin_endpoint).to eq('http://[::1]:35357/v2.0/')
79 it 'should use localhost in the admin endpoint if bind_host is unspecified' do
80 mock = {'DEFAULT' => { 'admin_port' => '35357' }}
81 File.expects(:exists?).with("/etc/keystone/keystone.conf").returns(true)
82 Puppet::Util::IniConfig::File.expects(:new).returns(mock)
83 mock.expects(:read).with('/etc/keystone/keystone.conf')
84 expect(klass.get_admin_endpoint).to eq('http://127.0.0.1:35357/v2.0/')
87 it 'should use https if ssl is enabled' do
88 mock = {'DEFAULT' => {'admin_bind_host' => '192.168.56.210', 'admin_port' => '35357' }, 'ssl' => {'enable' => 'True'}}
89 File.expects(:exists?).with("/etc/keystone/keystone.conf").returns(true)
90 Puppet::Util::IniConfig::File.expects(:new).returns(mock)
91 mock.expects(:read).with('/etc/keystone/keystone.conf')
92 expect(klass.get_admin_endpoint).to eq('https://192.168.56.210:35357/v2.0/')
95 it 'should use http if ssl is disabled' do
96 mock = {'DEFAULT' => {'admin_bind_host' => '192.168.56.210', 'admin_port' => '35357' }, 'ssl' => {'enable' => 'False'}}
97 File.expects(:exists?).with("/etc/keystone/keystone.conf").returns(true)
98 Puppet::Util::IniConfig::File.expects(:new).returns(mock)
99 mock.expects(:read).with('/etc/keystone/keystone.conf')
100 expect(klass.get_admin_endpoint).to eq('http://192.168.56.210:35357/v2.0/')
103 it 'should use the defined admin_endpoint if available' do
104 mock = {'DEFAULT' => {'admin_endpoint' => 'https://keystone.example.com' }, 'ssl' => {'enable' => 'False'}}
105 File.expects(:exists?).with("/etc/keystone/keystone.conf").returns(true)
106 Puppet::Util::IniConfig::File.expects(:new).returns(mock)
107 mock.expects(:read).with('/etc/keystone/keystone.conf')
108 expect(klass.get_admin_endpoint).to eq('https://keystone.example.com/v2.0/')
111 it 'should handle an admin_endpoint with a trailing slash' do
112 mock = {'DEFAULT' => {'admin_endpoint' => 'https://keystone.example.com/' }, 'ssl' => {'enable' => 'False'}}
113 File.expects(:exists?).with("/etc/keystone/keystone.conf").returns(true)
114 Puppet::Util::IniConfig::File.expects(:new).returns(mock)
115 mock.expects(:read).with('/etc/keystone/keystone.conf')
116 expect(klass.get_admin_endpoint).to eq('https://keystone.example.com/v2.0/')