3 require 'puppet/provider/keystone'
7 klass = Puppet::Provider::Keystone
9 class Puppet::Provider::Keystone
18 describe Puppet::Provider::Keystone do
25 describe 'when retrieving the security token' do
27 it 'should return nothing if there is no keystone config file' do
28 ini_file = Puppet::Util::IniConfig::File.new
29 t = Tempfile.new('foo')
33 expect(klass.get_admin_token).to be_nil
36 it 'should return nothing if the keystone config file does not have a DEFAULT section' do
38 Puppet::Util::IniConfig::File.expects(:new).returns(mock)
39 mock.expects(:read).with('/etc/keystone/keystone.conf')
40 expect(klass.get_admin_token).to be_nil
43 it 'should fail if the keystone config file does not contain an admin token' do
44 mock = {'DEFAULT' => {'not_a_token' => 'foo'}}
45 Puppet::Util::IniConfig::File.expects(:new).returns(mock)
46 mock.expects(:read).with('/etc/keystone/keystone.conf')
47 expect(klass.get_admin_token).to be_nil
50 it 'should parse the admin token if it is in the config file' do
51 mock = {'DEFAULT' => {'admin_token' => 'foo'}}
52 Puppet::Util::IniConfig::File.expects(:new).returns(mock)
53 mock.expects(:read).with('/etc/keystone/keystone.conf')
54 klass.get_admin_token.should == 'foo'
57 it 'should use the specified bind_host in the admin endpoint' do
58 mock = {'DEFAULT' => {'admin_bind_host' => '192.168.56.210', 'admin_port' => '35357' }}
59 Puppet::Util::IniConfig::File.expects(:new).returns(mock)
60 mock.expects(:read).with('/etc/keystone/keystone.conf')
61 klass.get_admin_endpoint.should == 'http://192.168.56.210:35357/v2.0/'
64 it 'should use localhost in the admin endpoint if bind_host is 0.0.0.0' do
65 mock = {'DEFAULT' => { 'admin_bind_host' => '0.0.0.0', 'admin_port' => '35357' }}
66 Puppet::Util::IniConfig::File.expects(:new).returns(mock)
67 mock.expects(:read).with('/etc/keystone/keystone.conf')
68 klass.get_admin_endpoint.should == '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 Puppet::Util::IniConfig::File.expects(:new).returns(mock)
74 mock.expects(:read).with('/etc/keystone/keystone.conf')
75 klass.get_admin_endpoint.should == 'http://[::1]:35357/v2.0/'
78 it 'should use localhost in the admin endpoint if bind_host is unspecified' do
79 mock = {'DEFAULT' => { 'admin_port' => '35357' }}
80 Puppet::Util::IniConfig::File.expects(:new).returns(mock)
81 mock.expects(:read).with('/etc/keystone/keystone.conf')
82 klass.get_admin_endpoint.should == 'http://127.0.0.1:35357/v2.0/'
85 it 'should use https if ssl is enabled' do
86 mock = {'DEFAULT' => {'admin_bind_host' => '192.168.56.210', 'admin_port' => '35357' }, 'ssl' => {'enable' => 'True'}}
87 Puppet::Util::IniConfig::File.expects(:new).returns(mock)
88 mock.expects(:read).with('/etc/keystone/keystone.conf')
89 klass.get_admin_endpoint.should == 'https://192.168.56.210:35357/v2.0/'
92 it 'should use http if ssl is disabled' do
93 mock = {'DEFAULT' => {'admin_bind_host' => '192.168.56.210', 'admin_port' => '35357' }, 'ssl' => {'enable' => 'False'}}
94 Puppet::Util::IniConfig::File.expects(:new).returns(mock)
95 mock.expects(:read).with('/etc/keystone/keystone.conf')
96 klass.get_admin_endpoint.should == 'http://192.168.56.210:35357/v2.0/'
99 it 'should use the defined admin_endpoint if available' do
100 mock = {'DEFAULT' => {'admin_endpoint' => 'https://keystone.example.com' }, 'ssl' => {'enable' => 'False'}}
101 Puppet::Util::IniConfig::File.expects(:new).returns(mock)
102 mock.expects(:read).with('/etc/keystone/keystone.conf')
103 klass.get_admin_endpoint.should == 'https://keystone.example.com/v2.0/'
106 it 'should handle an admin_endpoint with a trailing slash' do
107 mock = {'DEFAULT' => {'admin_endpoint' => 'https://keystone.example.com/' }, 'ssl' => {'enable' => 'False'}}
108 Puppet::Util::IniConfig::File.expects(:new).returns(mock)
109 mock.expects(:read).with('/etc/keystone/keystone.conf')
110 klass.get_admin_endpoint.should == 'https://keystone.example.com/v2.0/'