]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/keystone/spec/unit/provider/keystone_spec.rb
de9ceb0d1893a19075d31ae0b4dc637838bcc568
[dsa-puppet.git] / 3rdparty / modules / keystone / spec / unit / provider / keystone_spec.rb
1 require 'puppet'
2 require 'spec_helper'
3 require 'puppet/provider/keystone'
4 require 'tempfile'
5
6
7 klass = Puppet::Provider::Keystone
8
9 class Puppet::Provider::Keystone
10   def self.reset
11     @admin_endpoint = nil
12     @tenant_hash    = nil
13     @admin_token    = nil
14     @keystone_file  = nil
15   end
16 end
17
18 describe Puppet::Provider::Keystone do
19
20   after :each do
21     klass.reset
22   end
23
24
25   describe 'when retrieving the security token' do
26
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')
30       path = t.path
31       t.unlink
32       ini_file.read(path)
33       expect(klass.get_admin_token).to be_nil
34     end
35
36     it 'should return nothing if the keystone config file does not have a DEFAULT section' do
37       mock = {}
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
41     end
42
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
48     end
49
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'
55     end
56
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/'
62     end
63
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/'
69     end
70
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/'
76     end
77
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/'
83     end
84
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/'
90     end
91
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/'
97     end
98
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/'
104     end
105
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/'
111     end
112
113   end
114
115 end