diff options
author | tylercloke <tylercloke@gmail.com> | 2015-04-29 16:04:50 -0700 |
---|---|---|
committer | tylercloke <tylercloke@gmail.com> | 2015-04-30 09:56:59 -0700 |
commit | 3d11fd861949c31096bc60e56914f74447bc604b (patch) | |
tree | 244af6eca09cd53d135459039131f596c4705a3d | |
parent | 75cb417e2edbf21427d778b4675c806bdb312b3f (diff) | |
download | chef-3d11fd861949c31096bc60e56914f74447bc604b.tar.gz |
Fixed a bug where create_key would conflict with public_key in hash returned from server on update.
-rw-r--r-- | lib/chef/key.rb | 8 | ||||
-rw-r--r-- | spec/unit/key_spec.rb | 22 |
2 files changed, 30 insertions, 0 deletions
diff --git a/lib/chef/key.rb b/lib/chef/key.rb index 3c8229f859..b52aaebf50 100644 --- a/lib/chef/key.rb +++ b/lib/chef/key.rb @@ -99,6 +99,10 @@ class Chef @public_key = nil end + def delete_create_key + @create_key = nil + end + def create_key(arg=nil) raise Chef::Exceptions::InvalidKeyAttribute, "you cannot set create_key to true if the public_key field exists" if arg == true && !@public_key.nil? set_or_return(:create_key, arg, @@ -171,6 +175,10 @@ class Chef put_name = @name if put_name.nil? new_key = chef_rest.put_rest("#{api_base}/#{@actor}/keys/#{put_name}", to_hash) + # if the server returned a public_key, remove the create_key field, as we now have a key + if new_key["public_key"] + self.delete_create_key + end Chef::Key.from_hash(self.to_hash.merge(new_key)) end diff --git a/spec/unit/key_spec.rb b/spec/unit/key_spec.rb index 6c631e200a..94ebbf6ae8 100644 --- a/spec/unit/key_spec.rb +++ b/spec/unit/key_spec.rb @@ -527,6 +527,28 @@ EOS key.update("old_name") end end + + context "when the server returns a public_key and create_key is true" do + before do + key.name "key_name" + key.create_key true + allow(rest).to receive(:put_rest).with(url, key.to_hash).and_return({ + "key" => "key_name", + "public_key" => public_key_string + }) + + end + + it "returns a key with public_key populated" do + new_key = key.update + expect(new_key.public_key).to eq(public_key_string) + end + + it "returns a key without create_key set" do + new_key = key.update + expect(new_key.create_key).to be_nil + end + end end context "when updating a user key" do |