From: marios <[email protected]> Openstack driver needs auth for /api
Signed-off-by: marios <[email protected]> --- tests/deltacloud/base_api_test.rb | 8 ++++---- tests/deltacloud/test_setup.rb | 17 ++++++++++++++--- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/tests/deltacloud/base_api_test.rb b/tests/deltacloud/base_api_test.rb index 0af6c3d..65e5a0a 100644 --- a/tests/deltacloud/base_api_test.rb +++ b/tests/deltacloud/base_api_test.rb @@ -22,7 +22,7 @@ describe "Deltacloud API Entry Point" do # Get the API entrypoint without any authentication def get_api(params={}) - get("/", params.update(:noauth => true)) + get("/", params) #, params.update(:noauth => true)) end it 'return status 200 OK when accessing API entrypoint' do @@ -111,7 +111,7 @@ describe "Deltacloud API Entry Point" do it 'must re-validate the driver credentials when using "?force_auth" parameter in URL' do proc do - get_api(:force_auth => '1') + get_api(:noauth=> true, :force_auth => '1') end.must_raise RestClient::Request::Unauthorized res = get("/", :driver => "mock", :force_auth => '1', @@ -120,10 +120,10 @@ describe "Deltacloud API Entry Point" do end it 'must change the API PROVIDER using the /api;provider matrix parameter in URI' do - res = get(";provider=test1", :noauth=>true) + res = get(";driver=mock;provider=test1") res.xml.root[:provider].wont_be_nil res.xml.root[:provider].must_equal 'test1' - res = get(";provider=test2", :noauth=>true) + res = get(";driver=mock;provider=test2") res.xml.root[:provider].must_equal 'test2' end diff --git a/tests/deltacloud/test_setup.rb b/tests/deltacloud/test_setup.rb index 6182a63..c75b046 100644 --- a/tests/deltacloud/test_setup.rb +++ b/tests/deltacloud/test_setup.rb @@ -77,8 +77,20 @@ module Deltacloud private def xml unless @xml - @xml = RestClient.get(url).xml - drv = @xml.root[:driver] + begin + @xml = RestClient.get(url).xml + drv = @xml.root[:driver] + rescue RestClient::Unauthorized => e + #need to do this by hand - RestClient only return exception for 4XX + #(e.g. Openstack needs creds for /api) - but headers contain driver + uri = URI.parse(url) + http = Net::HTTP.new(uri.host, uri.port) + request = Net::HTTP::Get.new(uri.path) + res = http.request(request) + drv = res["X-Deltacloud-Driver"] + u,p = [@hash[drv]["user"], @hash[drv]["password"]] + @xml = RestClient.get(url, {'Authorization' => "Basic #{Base64.encode64("#{u}:#{p}")}"}).xml + end unless @hash[drv] raise "No config for #{drv} driver in config.yaml used by #{url}" end @@ -173,7 +185,6 @@ module Deltacloud::Test::Methods end private - def process_url_params(path, params) path = "" if path == "/" headers = {} -- 1.7.11.7
