summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Casey <james@opscode.com>2014-02-21 11:33:08 -0800
committerJames Casey <james@opscode.com>2014-02-21 11:33:08 -0800
commitea6feff495e88dbdf17a5bdb1ca942385b403da2 (patch)
tree8bcbe3d51b0c7680d1f82cc1c2476771ccadbaf0
parent2a8c2c1146dd714bfe18efc1917177b1ea6dae7e (diff)
parent075469c3edc95581090f857aa35ee0074d7e4a61 (diff)
downloadchef-ea6feff495e88dbdf17a5bdb1ca942385b403da2.tar.gz
Merge pull request #1269 from opscode/jc/CHEF-5047/client-show
knife client show does not show validator/admin correctly
-rw-r--r--lib/chef/api_client.rb4
-rw-r--r--spec/unit/api_client_spec.rb46
2 files changed, 47 insertions, 3 deletions
diff --git a/lib/chef/api_client.rb b/lib/chef/api_client.rb
index 66cbd3f30e..7b7fd99ff7 100644
--- a/lib/chef/api_client.rb
+++ b/lib/chef/api_client.rb
@@ -162,9 +162,7 @@ class Chef
if response.kind_of?(Chef::ApiClient)
response
else
- client = Chef::ApiClient.new
- client.name(response['clientname'])
- client
+ json_create(response)
end
end
diff --git a/spec/unit/api_client_spec.rb b/spec/unit/api_client_spec.rb
index 4ccd64bafe..8657fa59a8 100644
--- a/spec/unit/api_client_spec.rb
+++ b/spec/unit/api_client_spec.rb
@@ -164,6 +164,52 @@ describe Chef::ApiClient do
end
+ describe "when loading from JSON" do
+ before do
+ end
+
+ before(:each) do
+ client = {
+ "name" => "black",
+ "clientname" => "black",
+ "public_key" => "crowes",
+ "private_key" => "monkeypants",
+ "admin" => true,
+ "validator" => true,
+ "json_class" => "Chef::ApiClient"
+ }
+ @http_client = double("Chef::REST mock")
+ Chef::REST.stub(:new).and_return(@http_client)
+ @http_client.should_receive(:get).with("clients/black").and_return(client)
+ @client = Chef::ApiClient.load(client['name'])
+ end
+
+ it "should deserialize to a Chef::ApiClient object" do
+ @client.should be_a_kind_of(Chef::ApiClient)
+ end
+
+ it "preserves the name" do
+ @client.name.should == "black"
+ end
+
+ it "preserves the public key" do
+ @client.public_key.should == "crowes"
+ end
+
+ it "preserves the admin status" do
+ @client.admin.should be_a_kind_of(Chef::TrueClass)
+ end
+
+ it "preserves the 'validator' status" do
+ @client.validator.should be_a_kind_of(Chef::TrueClass)
+ end
+
+ it "includes the private key if present" do
+ @client.private_key.should == "monkeypants"
+ end
+
+ end
+
describe "with correctly configured API credentials" do
before do
Chef::Config[:node_name] = "silent-bob"