spec/scim_spec.rb in cf-uaa-lib-3.2.4 vs spec/scim_spec.rb in cf-uaa-lib-3.2.5

- old
+ new

@@ -27,16 +27,17 @@ @scim = Scim.new(@target, @authheader, options) end subject { @scim } - def check_headers(headers, content, accept) + def check_headers(headers, content, accept, zone) headers["content-type"].should =~ /application\/json/ if content == :json headers["content-type"].should be_nil unless content headers["accept"].should =~ /application\/json/ if accept == :json headers["accept"].should be_nil unless accept headers["authorization"].should =~ /^(?i:bearer)\s+xyz$/ + headers["X-Identity-Zone-Subdomain"].should eq zone end describe "initialize" do let(:options) { {:http_proxy => 'http-proxy.com', :https_proxy => 'https-proxy.com', :skip_ssl_validation => true} } @@ -52,11 +53,11 @@ it "adds an object" do subject.set_request_handler do |url, method, body, headers| url.should == "#{@target}/Users" method.should == :post - check_headers(headers, :json, :json) + check_headers(headers, :json, :json, nil) [200, '{"ID":"id12345"}', {"content-type" => "application/json"}] end result = subject.add(:user, :hair => "brown", :shoe_size => "large", :eye_color => ["blue", "green"], :name => "fred") result["id"].should == "id12345" @@ -66,11 +67,11 @@ obj = {:hair => "black", :shoe_size => "medium", :eye_color => ["hazel", "brown"], :name => "fredrick", :meta => {:version => 'v567'}, :id => "id12345"} subject.set_request_handler do |url, method, body, headers| url.should == "#{@target}/Users/id12345" method.should == :put - check_headers(headers, :json, :json) + check_headers(headers, :json, :json, nil) headers["if-match"].should == "v567" [200, '{"ID":"id12345"}', {"content-type" => "application/json"}] end result = subject.put(:user, obj) result["id"].should == "id12345" @@ -80,11 +81,11 @@ obj = {:hair => "black", :shoe_size => "medium", :eye_color => ["hazel", "brown"], :name => "fredrick", :meta => {:version => 'v567'}, :id => "id12345"} subject.set_request_handler do |url, method, body, headers| url.should == "#{@target}/Users/id12345" method.should == :patch - check_headers(headers, :json, :json) + check_headers(headers, :json, :json, nil) headers["if-match"].should == "v567" [200, '{"ID":"id12345"}', {"content-type" => "application/json"}] end result = subject.patch(:user, obj) result["id"].should == "id12345" @@ -92,11 +93,11 @@ it "gets an object" do subject.set_request_handler do |url, method, body, headers| url.should == "#{@target}/Users/id12345" method.should == :get - check_headers(headers, nil, :json) + check_headers(headers, nil, :json, nil) [200, '{"id":"id12345"}', {"content-type" => "application/json"}] end result = subject.get(:user, "id12345") result['id'].should == "id12345" end @@ -105,11 +106,11 @@ subject.set_request_handler do |url, method, body, headers| url.should =~ %r{^#{@target}/Users\?} url.should =~ %r{[\?&]attributes=id(&|$)} url.should =~ %r{[\?&]startIndex=[12](&|$)} method.should == :get - check_headers(headers, nil, :json) + check_headers(headers, nil, :json, nil) reply = url =~ /startIndex=1/ ? '{"TotalResults":2,"ItemsPerPage":1,"StartIndex":1,"RESOURCES":[{"id":"id12345"}]}' : '{"TotalResults":2,"ItemsPerPage":1,"StartIndex":2,"RESOURCES":[{"id":"id67890"}]}' [200, reply, {"content-type" => "application/json"}] end @@ -119,11 +120,11 @@ it "changes a user's password" do subject.set_request_handler do |url, method, body, headers| url.should == "#{@target}/Users/id12345/password" method.should == :put - check_headers(headers, :json, :json) + check_headers(headers, :json, :json, nil) body.should include('"password":"newpwd"', '"oldPassword":"oldpwd"') [200, '{"id":"id12345"}', {"content-type" => "application/json"}] end result = subject.change_password("id12345", "newpwd", "oldpwd") result['id'].should == "id12345" @@ -131,21 +132,21 @@ it "tries to change the user's password to be the same as the old one" do subject.set_request_handler do |url, method, body, headers| url.should == "#{@target}/Users/id12345/password" method.should == :put - check_headers(headers, :json, :json) + check_headers(headers, :json, :json, nil) [400, '{"error":"invalid_password","message":"Your new password cannot be the same as the old password."}', {"content-type" => "application/json"}] end expect {subject.change_password("id12345", "oldpwd", "oldpwd")}.to raise_error(error=TargetError) end it "changes a client's secret" do subject.set_request_handler do |url, method, body, headers| url.should == "#{@target}/oauth/clients/id12345/secret" method.should == :put - check_headers(headers, :json, :json) + check_headers(headers, :json, :json, nil) body.should include('"secret":"newpwd"', '"oldSecret":"oldpwd"') [200, '{"id":"id12345"}', {"content-type" => "application/json"}] end result = subject.change_secret("id12345", "newpwd", "oldpwd") result['id'].should == "id12345" @@ -153,11 +154,11 @@ it "adds a mapping from uaa groups to external group" do subject.set_request_handler do |url, method, body, headers| url.should == "#{@target}/Groups/External" method.should == :post - check_headers(headers, :json, :json) + check_headers(headers, :json, :json, nil) body.should include('"displayName":"uaa-scope-name"', '"externalGroup":"external-group-name"', '"schemas":["urn:scim:schemas:core:1.0"]') [201, '{"displayName":"uaa-scope-name", "externalGroup": "external-group-name"}', {"content-type" => "application/json"}] end result = subject.map_group("uaa-scope-name", false, "external-group-name") result['displayname'].should == "uaa-scope-name" @@ -166,23 +167,39 @@ it "unmaps a uaa group from an external group" do subject.set_request_handler do |url, method, body, headers| url.should == "#{@target}/Groups/External/id/uaa-group-id/external%20group%20name" method.should == :delete - check_headers(headers, nil, nil) + check_headers(headers, nil, nil, nil) [200, '{"displayName":"uaa-scope-name", "groupId": "uaa-group-id", "externalGroup": "external-group-name"}', {"content-type" => "application/json"}] end subject.unmap_group("uaa-group-id", "external group name") end + describe "users in a zone" do + let(:options) { {:http_proxy => 'http-proxy.com', :https_proxy => 'https-proxy.com', :skip_ssl_validation => true, :zone => 'derpzone'} } + + it "sends zone header" do + subject.set_request_handler do |url, method, body, headers| + url.should == "#{@target}/Users" + method.should == :post + check_headers(headers, :json, :json, 'derpzone') + [200, '{"ID":"id12345"}', {"content-type" => "application/json"}] + end + result = subject.add(:user, :hair => "brown", :shoe_size => "large", + :eye_color => ["blue", "green"], :name => "fred") + result["id"].should == "id12345" + end + end + describe "#list_group_mappings" do it "lists all the external group mappings with default pagination" do subject.set_request_handler do |url, method, body, headers| url.should start_with("#{@target}/Groups/External/list") method.should == :get - check_headers(headers, nil, :json) + check_headers(headers, nil, :json, nil) [ 200, '{"resources": [{"groupId": "group-id", "displayName": "group-name", "externalGroup": "external-group-name"}], "totalResults": 1 }', {"content-type" => "application/json"} @@ -196,11 +213,11 @@ it "lists a page of external group mappings starting from an index" do subject.set_request_handler do |url, method, body, headers| url.should start_with("#{@target}/Groups/External/list") method.should == :get - check_headers(headers, nil, :json) + check_headers(headers, nil, :json, nil) query_params = CGI::parse(URI.parse(url).query) start_index = query_params["startIndex"].first count = query_params["count"].first @@ -214,9 +231,11 @@ ] end subject.list_group_mappings(3, 10) end + + end end end