]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/keystone/spec/unit/provider/keystone_spec.rb
try with modules from master
[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 klass = Puppet::Provider::Keystone
7
8 class Puppet::Provider::Keystone
9   @credentials = Puppet::Provider::Openstack::CredentialsV2_0.new
10
11   def self.reset
12     @admin_endpoint = nil
13     @tenant_hash    = nil
14     @admin_token    = nil
15     @keystone_file  = nil
16   end
17 end
18
19 describe Puppet::Provider::Keystone do
20
21   after :each do
22     klass.reset
23   end
24
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
29     end
30
31     it 'should return nothing if the keystone config file does not have a DEFAULT section' do
32       mock = {}
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
37     end
38
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
45     end
46
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')
53     end
54
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/')
61     end
62
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/')
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       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/')
77     end
78
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/')
85     end
86
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/')
93     end
94
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/')
101     end
102
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/')
109     end
110
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/')
117     end
118
119   end
120
121 end