Change-Id: I35dfca684039512e2a238466ff7df5f3fd34d956 Addresses: blueprint refactor-spec-files Closes-Bug: 1282996
81 lines
3.0 KiB
Ruby
81 lines
3.0 KiB
Ruby
# encoding: UTF-8
|
|
require_relative 'spec_helper'
|
|
require ::File.join ::File.dirname(__FILE__), '..', 'libraries', 'passwords'
|
|
|
|
describe 'openstack-common::default' do
|
|
describe 'Passwords' do
|
|
let(:runner) { ChefSpec::Runner.new(CHEFSPEC_OPTS) }
|
|
let(:node) { runner.node }
|
|
let(:chef_run) { runner.converge(described_recipe) }
|
|
let(:subject) { Object.new.extend(Openstack) }
|
|
|
|
include_context 'library-stubs'
|
|
|
|
describe '#secret' do
|
|
it 'returns index param when developer_mode is true' do
|
|
node.set['openstack']['developer_mode'] = true
|
|
expect(subject.secret('passwords', 'nova')).to eq('nova')
|
|
end
|
|
|
|
it 'returns databag when developer_mode is false' do
|
|
value = { 'nova' => 'this' }
|
|
::Chef::EncryptedDataBagItem.stub(:load_secret).with('/etc/chef/openstack_data_bag_secret').and_return('secret')
|
|
::Chef::EncryptedDataBagItem.stub(:load).with('passwords', 'nova', 'secret').and_return(value)
|
|
expect(subject.secret('passwords', 'nova')).to eq('this')
|
|
end
|
|
end
|
|
|
|
describe '#get_password_service_password' do
|
|
it 'returns index param when developer_mode is true' do
|
|
node.set['openstack']['developer_mode'] = true
|
|
expect(subject.get_password('service', 'nova')).to eq('nova')
|
|
end
|
|
|
|
it 'returns databag when developer_mode is false' do
|
|
value = { 'nova' => 'this' }
|
|
::Chef::EncryptedDataBagItem.stub(:load_secret).with('/etc/chef/openstack_data_bag_secret').and_return('secret')
|
|
::Chef::EncryptedDataBagItem.stub(:load).with('service_passwords', 'nova', 'secret').and_return(value)
|
|
expect(
|
|
subject.get_password('service', 'nova')
|
|
).to eq('this')
|
|
end
|
|
end
|
|
|
|
describe '#get_password_db_password' do
|
|
it 'returns index param when developer_mode is true' do
|
|
node.set['openstack']['developer_mode'] = true
|
|
expect(
|
|
subject.get_password('db', 'nova')
|
|
).to eq('nova')
|
|
end
|
|
|
|
it 'returns databag when developer_mode is false' do
|
|
value = { 'nova' => 'this' }
|
|
::Chef::EncryptedDataBagItem.stub(:load_secret).with('/etc/chef/openstack_data_bag_secret').and_return('secret')
|
|
::Chef::EncryptedDataBagItem.stub(:load).with('db_passwords', 'nova', 'secret').and_return(value)
|
|
expect(
|
|
subject.get_password('db', 'nova')
|
|
).to eq('this')
|
|
end
|
|
end
|
|
|
|
describe '#get_password_user_password' do
|
|
it 'returns index param when developer_mode is true' do
|
|
node.set['openstack']['developer_mode'] = true
|
|
expect(
|
|
subject.get_password('user', 'nova')
|
|
).to eq('nova')
|
|
end
|
|
|
|
it 'returns databag when developer_mode is false' do
|
|
value = { 'nova' => 'this' }
|
|
::Chef::EncryptedDataBagItem.stub(:load_secret).with('/etc/chef/openstack_data_bag_secret').and_return('secret')
|
|
::Chef::EncryptedDataBagItem.stub(:load).with('user_passwords', 'nova', 'secret').and_return(value)
|
|
expect(
|
|
subject.get_password('user', 'nova')
|
|
).to eq('this')
|
|
end
|
|
end
|
|
end
|
|
end
|