diff options
author | Thom May <thom@may.lt> | 2016-10-04 17:30:12 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-04 17:30:12 +0100 |
commit | b8804983cf5ced0fee5d27ca597bee27b7025357 (patch) | |
tree | 56a925e55f4872237235bd635f4636b96439ceea | |
parent | f33deece4b704437cb6ead06d1dc24414126150e (diff) | |
parent | 88550632a4205375287c34a9dd220ed3859fa02c (diff) | |
download | chef-b8804983cf5ced0fee5d27ca597bee27b7025357.tar.gz |
Merge pull request #5314 from chef/tm/raw_key
Allow raw_key to override the configured signing_key
-rw-r--r-- | lib/chef/server_api.rb | 2 | ||||
-rw-r--r-- | spec/unit/server_api_spec.rb | 50 |
2 files changed, 51 insertions, 1 deletions
diff --git a/lib/chef/server_api.rb b/lib/chef/server_api.rb index cad8586ac8..d233d25232 100644 --- a/lib/chef/server_api.rb +++ b/lib/chef/server_api.rb @@ -30,7 +30,7 @@ class Chef def initialize(url = Chef::Config[:chef_server_url], options = {}) options[:client_name] ||= Chef::Config[:node_name] - options[:signing_key_filename] ||= Chef::Config[:client_key] + options[:signing_key_filename] ||= Chef::Config[:client_key] unless options[:raw_key] options[:signing_key_filename] = nil if chef_zero_uri?(url) options[:inflate_json_class] = false super(url, options) diff --git a/spec/unit/server_api_spec.rb b/spec/unit/server_api_spec.rb new file mode 100644 index 0000000000..05d2a28ed4 --- /dev/null +++ b/spec/unit/server_api_spec.rb @@ -0,0 +1,50 @@ +require "spec_helper" + +SIGNING_KEY_DOT_PEM = "-----BEGIN RSA PRIVATE KEY----- +MIIEpAIBAAKCAQEA49TA0y81ps0zxkOpmf5V4/c4IeR5yVyQFpX3JpxO4TquwnRh +8VSUhrw8kkTLmB3cS39Db+3HadvhoqCEbqPE6915kXSuk/cWIcNozujLK7tkuPEy +YVsyTioQAddSdfe+8EhQVf3oHxaKmUd6waXrWqYCnhxgOjxocenREYNhZ/OETIei +PbOku47vB4nJK/0GhKBytL2XnsRgfKgDxf42BqAi1jglIdeq8lAWZNF9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+hauqhSzntK3k955GznpUatCqx0R +b857vWviwPX2/P6+E3GPdl8IVsKXCvGWOBZWTuNTjQtwbDzsUepWoMgXnlQJSn5I +YSlLxQKBgQD16Gw9kajpKlzsPa6XoQeGmZALT6aKWJQlrKtUQIrsIWM0Z6eFtX12 +2jjHZ0awuCQ4ldqwl8IfRogWMBkHOXjTPVK0YKWWlxMpD/5+bGPARa5fir8O1Zpo +Y6S6MeZ69Rp89ma4ttMZ+kwi1+XyHqC/dlcVRW42Zl5Dc7BALRlJjQ== +-----END RSA PRIVATE KEY-----" + +describe Chef::ServerAPI do + let(:url) { "http://chef.example.com:4000" } + let(:key_path) { "/tmp/foo" } + + describe "#initialize" do + it "uses the configured key file" do + allow(IO).to receive(:read).with(key_path).and_return(SIGNING_KEY_DOT_PEM) + Chef::Config[:client_key] = key_path + + api = described_class.new(url) + expect(api.options[:signing_key_filename]).to eql(key_path) + end + + it "allows a user to set a raw_key" do + api = described_class.new(url, raw_key: SIGNING_KEY_DOT_PEM) + expect(api.options[:signing_key_filename]).to be_nil + expect(api.options[:raw_key]).to eql(SIGNING_KEY_DOT_PEM) + end + end +end |