Prevent dollar signs and single quotes in variables from being removed by shell

Change-Id: I88782bd60755f96816bf9d06cd57298cb46f8e40
This commit is contained in:
Konrad Scherer
2013-10-11 18:48:18 -04:00
parent 97e4579cb8
commit 4d1d56e7bb
2 changed files with 58 additions and 40 deletions

View File

@@ -10,18 +10,18 @@ describe 'openstack::auth_file' do
it 'should create a openrc file' do it 'should create a openrc file' do
verify_contents(subject, '/root/openrc', [ verify_contents(subject, '/root/openrc', [
'export OS_NO_CACHE=true', 'export OS_NO_CACHE=\'true\'',
'export OS_TENANT_NAME=openstack', 'export OS_TENANT_NAME=\'openstack\'',
'export OS_USERNAME=admin', 'export OS_USERNAME=\'admin\'',
'export OS_PASSWORD=admin', 'export OS_PASSWORD=\'admin\'',
'export OS_AUTH_URL=http://127.0.0.1:5000/v2.0/', 'export OS_AUTH_URL=\'http://127.0.0.1:5000/v2.0/\'',
'export OS_AUTH_STRATEGY=keystone', 'export OS_AUTH_STRATEGY=\'keystone\'',
'export OS_REGION_NAME=RegionOne', 'export OS_REGION_NAME=\'RegionOne\'',
'export CINDER_ENDPOINT_TYPE=publicURL', 'export CINDER_ENDPOINT_TYPE=\'publicURL\'',
'export GLANCE_ENDPOINT_TYPE=publicURL', 'export GLANCE_ENDPOINT_TYPE=\'publicURL\'',
'export KEYSTONE_ENDPOINT_TYPE=publicURL', 'export KEYSTONE_ENDPOINT_TYPE=\'publicURL\'',
'export NOVA_ENDPOINT_TYPE=publicURL', 'export NOVA_ENDPOINT_TYPE=\'publicURL\'',
'export NEUTRON_ENDPOINT_TYPE=publicURL' 'export NEUTRON_ENDPOINT_TYPE=\'publicURL\''
]) ])
end end
end end
@@ -44,21 +44,39 @@ describe 'openstack::auth_file' do
it 'should create a openrc file' do it 'should create a openrc file' do
verify_contents(subject, '/root/openrc', [ verify_contents(subject, '/root/openrc', [
'export OS_SERVICE_TOKEN=keystone', 'export OS_SERVICE_TOKEN=\'keystone\'',
'export OS_SERVICE_ENDPOINT=http://127.0.0.2:35357/v2.0/', 'export OS_SERVICE_ENDPOINT=\'http://127.0.0.2:35357/v2.0/\'',
'export OS_NO_CACHE=true', 'export OS_NO_CACHE=\'true\'',
'export OS_TENANT_NAME=admin', 'export OS_TENANT_NAME=\'admin\'',
'export OS_USERNAME=admin', 'export OS_USERNAME=\'admin\'',
'export OS_PASSWORD=admin', 'export OS_PASSWORD=\'admin\'',
'export OS_AUTH_URL=http://127.0.0.2:5000/v2.0/', 'export OS_AUTH_URL=\'http://127.0.0.2:5000/v2.0/\'',
'export OS_AUTH_STRATEGY=keystone', 'export OS_AUTH_STRATEGY=\'keystone\'',
'export OS_REGION_NAME=RegionOne', 'export OS_REGION_NAME=\'RegionOne\'',
'export CINDER_ENDPOINT_TYPE=privateURL', 'export CINDER_ENDPOINT_TYPE=\'privateURL\'',
'export GLANCE_ENDPOINT_TYPE=privateURL', 'export GLANCE_ENDPOINT_TYPE=\'privateURL\'',
'export KEYSTONE_ENDPOINT_TYPE=privateURL', 'export KEYSTONE_ENDPOINT_TYPE=\'privateURL\'',
'export NOVA_ENDPOINT_TYPE=privateURL', 'export NOVA_ENDPOINT_TYPE=\'privateURL\'',
'export NEUTRON_ENDPOINT_TYPE=privateURL' 'export NEUTRON_ENDPOINT_TYPE=\'privateURL\''
]) ])
end end
end end
describe "handle password and token with single quotes" do
let :params do
{
:admin_password => 'singlequote\'',
:keystone_admin_token => 'key\'stone'
}
end
it 'should create a openrc file' do
verify_contents(subject, '/root/openrc', [
'export OS_SERVICE_TOKEN=\'key\\\'stone\'',
'export OS_PASSWORD=\'singlequote\\\'\'',
])
end
end
end end

View File

@@ -1,17 +1,17 @@
#!/bin/sh #!/bin/sh
<% if @keystone_admin_token -%> <% if @keystone_admin_token -%>
export OS_SERVICE_TOKEN=<%= @keystone_admin_token %> export OS_SERVICE_TOKEN='<%= @keystone_admin_token.gsub(/'/){ %q(\') } %>'
export OS_SERVICE_ENDPOINT=http://<%= @controller_node %>:35357/v2.0/ export OS_SERVICE_ENDPOINT='http://<%= @controller_node %>:35357/v2.0/'
<% end -%> <% end -%>
export OS_NO_CACHE=<%= @use_no_cache %> export OS_NO_CACHE='<%= @use_no_cache %>'
export OS_TENANT_NAME=<%= @admin_tenant %> export OS_TENANT_NAME='<%= @admin_tenant %>'
export OS_USERNAME=<%= @admin_user %> export OS_USERNAME='<%= @admin_user %>'
export OS_PASSWORD=<%= @admin_password %> export OS_PASSWORD='<%= @admin_password.gsub(/'/){ %q(\') } %>'
export OS_AUTH_URL=http://<%= @controller_node %>:5000/v2.0/ export OS_AUTH_URL='http://<%= @controller_node %>:5000/v2.0/'
export OS_AUTH_STRATEGY=keystone export OS_AUTH_STRATEGY='keystone'
export OS_REGION_NAME=<%= @region_name %> export OS_REGION_NAME='<%= @region_name %>'
export CINDER_ENDPOINT_TYPE=<%= @cinder_endpoint_type %> export CINDER_ENDPOINT_TYPE='<%= @cinder_endpoint_type %>'
export GLANCE_ENDPOINT_TYPE=<%= @glance_endpoint_type %> export GLANCE_ENDPOINT_TYPE='<%= @glance_endpoint_type %>'
export KEYSTONE_ENDPOINT_TYPE=<%= @keystone_endpoint_type %> export KEYSTONE_ENDPOINT_TYPE='<%= @keystone_endpoint_type %>'
export NOVA_ENDPOINT_TYPE=<%= @nova_endpoint_type %> export NOVA_ENDPOINT_TYPE='<%= @nova_endpoint_type %>'
export NEUTRON_ENDPOINT_TYPE=<%= @neutron_endpoint_type %> export NEUTRON_ENDPOINT_TYPE='<%= @neutron_endpoint_type %>'