puppet-swift/spec/classes/swift_proxy_authtoken_spec.rb
Sebastien Badia f4cfe8e8e4 spec: updates for rspec-puppet 2.x and rspec 3.x
This patch aim to update our specs test in order to work with the
rspec-puppet release 2.0.0, in the mean time, we update rspec syntax
in order to be prepared for rspec 3.x move.

In details:
  * Use shared_examples "a Puppet::Error" for puppet::error tests
  * Convert 'should' keyword to 'is_expected.to' (prepare rspec 3.x)
  * Fix spec tests for rspec-puppet 2.0.0
  * Upgrade and pin rspec-puppet from 1.0.1 to 2.0.0
  * Clean Gemfile (remove over-specificication of runtime deps of puppetlabs_spec_helper)
  * Remove un-used puppet-lint (name_containing_dash config)

Change-Id: I5488507176d4665895eef65ddb4b6f0fb4eda3e7
Card: https://trello.com/c/eHXc1Ryd/4-investigate-the-necessary-change-to-be-rspec-puppet-2-0-0-compliant
2015-03-24 15:22:16 +01:00

203 lines
5.7 KiB
Ruby

require 'spec_helper'
describe 'swift::proxy::authtoken' do
let :facts do
{}
end
let :pre_condition do
'
include concat::setup
concat { "/etc/swift/proxy-server.conf": }
'
end
describe 'when using the default signing directory' do
let :file_defaults do
{
:mode => '0700',
:owner => 'swift',
:group => 'swift',
}
end
it {is_expected.to contain_file('/var/cache/swift').with(
{:ensure => 'directory'}.merge(file_defaults)
)}
end
let :fragment_file do
"/var/lib/puppet/concat/_etc_swift_proxy-server.conf/fragments/22_swift_authtoken"
end
describe "when using default parameters" do
it 'should build the fragment with correct parameters' do
verify_contents(catalogue, fragment_file,
[
'[filter:authtoken]',
'log_name = swift',
'signing_dir = /var/cache/swift',
'paste.filter_factory = keystonemiddleware.auth_token:filter_factory',
'auth_host = 127.0.0.1',
'auth_port = 35357',
'auth_protocol = http',
'auth_uri = http://127.0.0.1:5000',
'admin_tenant_name = services',
'admin_user = swift',
'admin_password = password',
'delay_auth_decision = 1',
'cache = swift.cache',
'include_service_catalog = False'
]
)
end
end
describe "when overriding admin_token" do
let :params do
{
:admin_token => 'ADMINTOKEN'
}
end
it 'should build the fragment with correct parameters' do
verify_contents(catalogue, fragment_file,
[
'[filter:authtoken]',
'log_name = swift',
'signing_dir = /var/cache/swift',
'paste.filter_factory = keystonemiddleware.auth_token:filter_factory',
'auth_host = 127.0.0.1',
'auth_port = 35357',
'auth_protocol = http',
'auth_uri = http://127.0.0.1:5000',
'admin_token = ADMINTOKEN',
'delay_auth_decision = 1',
'cache = swift.cache',
'include_service_catalog = False'
]
)
end
end
describe "when overriding parameters" do
let :params do
{
:auth_host => 'some.host',
:auth_port => '443',
:auth_protocol => 'https',
:auth_admin_prefix => '/keystone/admin',
:admin_tenant_name => 'admin',
:admin_user => 'swiftuser',
:admin_password => 'swiftpassword',
:cache => 'foo',
:delay_auth_decision => '0',
:signing_dir => '/home/swift/keystone-signing'
}
end
it 'should build the fragment with correct parameters' do
verify_contents(catalogue, fragment_file,
[
'[filter:authtoken]',
'log_name = swift',
'signing_dir = /home/swift/keystone-signing',
'paste.filter_factory = keystonemiddleware.auth_token:filter_factory',
'auth_host = some.host',
'auth_port = 443',
'auth_protocol = https',
'auth_admin_prefix = /keystone/admin',
'auth_uri = https://some.host:5000',
'admin_tenant_name = admin',
'admin_user = swiftuser',
'admin_password = swiftpassword',
'delay_auth_decision = 0',
'cache = foo',
'include_service_catalog = False'
]
)
end
end
describe 'when overriding auth_uri' do
let :params do
{ :auth_uri => 'http://public.host/keystone/main' }
end
it { is_expected.to contain_file(fragment_file).with_content(/auth_uri = http:\/\/public.host\/keystone\/main/)}
end
[
'keystone',
'keystone/',
'/keystone/',
'/keystone/admin/',
'keystone/admin/',
'keystone/admin'
].each do |auth_admin_prefix|
describe "when overriding auth_admin_prefix with incorrect value #{auth_admin_prefix}" do
let :params do
{ :auth_admin_prefix => auth_admin_prefix }
end
it { expect { is_expected.to contain_file(fragment_file).with_content(/auth_admin_prefix = #{auth_admin_prefix}/) }.to \
raise_error(Puppet::Error, /validate_re\(\): "#{auth_admin_prefix}" does not match/) }
end
end
describe "when identity_uri is set" do
let :params do
{
:identity_uri => 'https://foo.bar:35357/'
}
end
it 'should build the fragment with correct parameters' do
verify_contents(catalogue, fragment_file,
[
'[filter:authtoken]',
'log_name = swift',
'signing_dir = /var/cache/swift',
'paste.filter_factory = keystonemiddleware.auth_token:filter_factory',
'auth_host = 127.0.0.1',
'auth_port = 35357',
'auth_protocol = http',
'auth_uri = http://127.0.0.1:5000',
'identity_uri = https://foo.bar:35357/',
'delay_auth_decision = 1',
'cache = swift.cache',
'include_service_catalog = False'
]
)
end
end
describe "when both auth_uri and identity_uri are set" do
let :params do
{
:auth_uri => 'https://foo.bar:5000/v2.0/',
:identity_uri => 'https://foo.bar:35357/'
}
end
it 'should build the fragment with correct parameters' do
verify_contents(catalogue, fragment_file,
[
'[filter:authtoken]',
'log_name = swift',
'signing_dir = /var/cache/swift',
'paste.filter_factory = keystonemiddleware.auth_token:filter_factory',
'auth_uri = https://foo.bar:5000/v2.0/',
'identity_uri = https://foo.bar:35357/',
'delay_auth_decision = 1',
'cache = swift.cache',
'include_service_catalog = False'
]
)
end
end
end