You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltacloud.apache.org by ma...@apache.org on 2013/01/17 17:17:30 UTC

git commit: Deltacloud tests: fix black box tests (base_api_test) for forced_auth drivers

Updated Branches:
  refs/heads/master a75ed47a6 -> 995910073


Deltacloud tests: fix black box tests (base_api_test) for forced_auth drivers

Openstack driver needs auth for /api


Project: http://git-wip-us.apache.org/repos/asf/deltacloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltacloud/commit/99591007
Tree: http://git-wip-us.apache.org/repos/asf/deltacloud/tree/99591007
Diff: http://git-wip-us.apache.org/repos/asf/deltacloud/diff/99591007

Branch: refs/heads/master
Commit: 995910073d7d7eadab375e381630de046e67b073
Parents: a75ed47
Author: marios <ma...@redhat.com>
Authored: Wed Jan 16 17:36:11 2013 +0200
Committer: marios <ma...@redhat.com>
Committed: Thu Jan 17 18:17:09 2013 +0200

----------------------------------------------------------------------
 tests/deltacloud/base_api_test.rb |    8 ++++----
 tests/deltacloud/test_setup.rb    |   17 ++++++++++++++---
 2 files changed, 18 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltacloud/blob/99591007/tests/deltacloud/base_api_test.rb
----------------------------------------------------------------------
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
 

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/99591007/tests/deltacloud/test_setup.rb
----------------------------------------------------------------------
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 = {}