diff options
author | Claire McQuin <mcquin@users.noreply.github.com> | 2014-06-10 16:20:07 -0700 |
---|---|---|
committer | Claire McQuin <mcquin@users.noreply.github.com> | 2014-06-10 16:20:07 -0700 |
commit | d9faf7fe80793bdf3dd205b5b777381de93db2b5 (patch) | |
tree | 3e91fe645a48a3ac30edb96d108723c74118f8af | |
parent | 3ca542e7a2e6eab4a19c13e1938d154aa22cb44d (diff) | |
parent | cc2d0f4b9bca39d115a059e79d04c7e540bedf65 (diff) | |
download | chef-d9faf7fe80793bdf3dd205b5b777381de93db2b5.tar.gz |
Merge pull request #1456 from onddo/CHEF-5328
[CHEF-5328] Chef::User.list API error with inflate=true
-rw-r--r-- | lib/chef/user.rb | 23 | ||||
-rw-r--r-- | spec/unit/user_spec.rb | 12 |
2 files changed, 24 insertions, 11 deletions
diff --git a/lib/chef/user.rb b/lib/chef/user.rb index 3f592e4b65..e2ef45dc5c 100644 --- a/lib/chef/user.rb +++ b/lib/chef/user.rb @@ -144,18 +144,19 @@ class Chef end def self.list(inflate=false) - response = if inflate - users = Chef::REST.new(Chef::Config[:chef_server_url]).get_rest('users') - users.map do |name| - Chef::User.load(name) - end - else - Chef::REST.new(Chef::Config[:chef_server_url]).get_rest('users') - end - if response.is_a? Array - transform_ohc_list_response(response) + response = Chef::REST.new(Chef::Config[:chef_server_url]).get_rest('users') + users = if response.is_a?(Array) + transform_ohc_list_response(response) # OHC/OPC else - response + response # OSC + end + if inflate + users.inject({}) do |user_map, (name, _url)| + user_map[name] = Chef::User.load(name) + user_map + end + else + users end end diff --git a/spec/unit/user_spec.rb b/spec/unit/user_spec.rb index c535e4172b..08bde33d7b 100644 --- a/spec/unit/user_spec.rb +++ b/spec/unit/user_spec.rb @@ -205,6 +205,8 @@ describe Chef::User do Chef::Config[:chef_server_url] = "http://www.example.com" @osc_response = { "admin" => "http://www.example.com/users/admin"} @ohc_response = [ { "user" => { "username" => "admin" }} ] + Chef::User.stub(:load).with("admin").and_return(@user) + @osc_inflated_response = { "admin" => @user } end it "lists all clients on an OSC server" do @@ -212,12 +214,22 @@ describe Chef::User do Chef::User.list.should == @osc_response end + it "inflate all clients on an OSC server" do + @http_client.stub(:get_rest).with("users").and_return(@osc_response) + Chef::User.list(true).should == @osc_inflated_response + end + it "lists all clients on an OHC/OPC server" do @http_client.stub(:get_rest).with("users").and_return(@ohc_response) # We expect that Chef::User.list will give a consistent response # so OHC API responses should be transformed to OSC-style output. Chef::User.list.should == @osc_response end + + it "inflate all clients on an OHC/OPC server" do + @http_client.stub(:get_rest).with("users").and_return(@ohc_response) + Chef::User.list(true).should == @osc_inflated_response + end end describe "create" do |