diff options
author | danielsdeleo <dan@opscode.com> | 2012-12-12 11:29:19 -0800 |
---|---|---|
committer | danielsdeleo <dan@opscode.com> | 2012-12-12 13:26:17 -0800 |
commit | 5157e050becc85a01d9cd4f076c670b5f573e721 (patch) | |
tree | ef43997a8394a02f77d8ab09edfe6c51d39ecfcc /spec/unit/api_client_spec.rb | |
parent | b0bd5359610355cb0c776e4de74cc0540042759b (diff) | |
download | chef-5157e050becc85a01d9cd4f076c670b5f573e721.tar.gz |
[CHEF-3662] ApiClient includes private key in JSON if present
After discussing with Adam and Seth F, there's no reason not to put the
private key in the serialized representation if we have it.
We ought to carefully review for behavior changes on the server side
before backporting to 10.x
Diffstat (limited to 'spec/unit/api_client_spec.rb')
-rw-r--r-- | spec/unit/api_client_spec.rb | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/spec/unit/api_client_spec.rb b/spec/unit/api_client_spec.rb index 6b41f1b211..4364bc1f16 100644 --- a/spec/unit/api_client_spec.rb +++ b/spec/unit/api_client_spec.rb @@ -100,33 +100,36 @@ describe Chef::ApiClient do end end - describe "serialize" do + describe "when serializing to JSON" do before(:each) do @client.name("black") @client.public_key("crowes") - @client.private_key("monkeypants") - @serial = @client.to_json + @json = @client.to_json end - it "should serialize to a json hash" do - @client.to_json.should match(/^\{.+\}$/) + it "serializes as a JSON object" do + @json.should match(/^\{.+\}$/) end - %w{ - name - public_key - }.each do |t| - it "should include '#{t}'" do - @serial.should =~ /"#{t}":"#{@client.send(t.to_sym)}"/ - end + it "includes the name value" do + @json.should include(%q{"name":"black"}) + end + + it "includes the public key value" do + @json.should include(%{"public_key":"crowes"}) end - it "should include 'admin'" do - @serial.should =~ /"admin":false/ + it "includes the 'admin' flag" do + @json.should include(%q{"admin":false}) + end + + it "includes the private key when present" do + @client.private_key("monkeypants") + @client.to_json.should include(%q{"private_key":"monkeypants"}) end - it "should not include the private key" do - @serial.should_not =~ /"private_key":/ + it "does not include the private key if not present" do + @json.should_not include("private_key") end end |