spec/scim_spec.rb in cf-uaa-lib-3.0.0 vs spec/scim_spec.rb in cf-uaa-lib-3.1.0

- old
+ new

@@ -1,8 +1,8 @@ #-- -# Cloud Foundry 2012.02.03 Beta -# Copyright (c) [2009-2012] VMware, Inc. All Rights Reserved. +# Cloud Foundry +# Copyright (c) [2009-2014] Pivotal Software, Inc. All Rights Reserved. # # This product is licensed to you under the Apache License, Version 2.0 (the "License"). # You may not use this product except in compliance with the License. # # This product includes a number of subcomponents with @@ -11,10 +11,12 @@ # subcomponent's license, as noted in the LICENSE file. #++ require 'spec_helper' require 'uaa/scim' +require 'uri' +require 'cgi' module CF::UAA describe Scim do let(:options) { {} } @@ -137,8 +139,74 @@ end result = subject.change_secret("id12345", "newpwd", "oldpwd") result['id'].should == "id12345" end + 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) + 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" + result['externalgroup'].should == "external-group-name" + end + + 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-group-name" + method.should == :delete + check_headers(headers, 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 "#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) + + [ + 200, + '{"resources": [{"groupId": "group-id", "displayName": "group-name", "externalGroup": "external-group-name"}], "totalResults": 1 }', + {"content-type" => "application/json"} + ] + end + + result = subject.list_group_mappings + result['resources'].length.should == 1 + result['totalresults'].should == 1 + end + + 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) + + query_params = CGI::parse(URI.parse(url).query) + start_index = query_params["startIndex"].first + count = query_params["count"].first + + start_index.should == "3" + count.should == "10" + + [ + 200, + '{"resources": [{"groupId": "group-id", "displayName": "group-name", "externalGroup": "external-group-name"}], "totalResults": 1 }', + {"content-type" => "application/json"} + ] + end + + subject.list_group_mappings(3, 10) + end + end end end