From 8b3447c5a151a97e968aad2c348b03136402fa8c Mon Sep 17 00:00:00 2001 From: John Dewey Date: Mon, 26 Nov 2012 13:47:54 -0800 Subject: [PATCH] Need to URI encode before parsing Some endpoints don't have valid paths --- libraries/default.rb | 4 ++-- spec/default_spec.rb | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/libraries/default.rb b/libraries/default.rb index 9a5584e4..059b6d30 100644 --- a/libraries/default.rb +++ b/libraries/default.rb @@ -26,8 +26,8 @@ module ::Openstack # and construct the URI object from the endpoint parts. def endpoint name ep = endpoint_for name - if ep && ep.has_key?("uri") - ::URI.parse ep["uri"] + if ep && ep['uri'] + ::URI.parse ::URI.encode(ep['uri']) elsif ep uri_from_hash ep end diff --git a/spec/default_spec.rb b/spec/default_spec.rb index ed6beada..50be9f64 100644 --- a/spec/default_spec.rb +++ b/spec/default_spec.rb @@ -20,6 +20,20 @@ describe ::Openstack do @subject.instance_variable_set :@node, @chef_run.node @subject.endpoint("nonexisting").should be_nil end + it "handles a URI needing escaped" do + uri_hash = { + "openstack" => { + "endpoints" => { + "compute-api" => { + "uri" => "http://localhost:8080/v2/%(tenant_id)s" + } + } + } + } + @subject.instance_variable_set :@node, uri_hash + result = @subject.endpoint "compute-api" + result.path.should == "/v2/%25(tenant_id)s" + end it "returns endpoint URI object when uri key in endpoint hash" do uri_hash = { "openstack" => {