summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authordanielsdeleo <dan@chef.io>2016-10-24 17:32:37 -0700
committerdanielsdeleo <dan@chef.io>2016-11-02 08:06:38 -0700
commitb95fce9f28693aa09dd0d37742063027596f6847 (patch)
treee205b2ff4406a618380712320aa0365c10ce4592 /spec
parentf9c619bc45e161e1518fd8f534898c4f7665166f (diff)
downloadchef-b95fce9f28693aa09dd0d37742063027596f6847.tar.gz
Allow optional signed header auth for data collector
* When the data collector is enabled but the token is nil, data collector will use signed header auth. * Switch data collector to an HTTP client that includes the JSON content middlewares so both auth methods talk to the `http` object the same way. Signed-off-by: Daniel DeLeo <dan@chef.io>
Diffstat (limited to 'spec')
-rw-r--r--spec/unit/data_collector_spec.rb48
1 files changed, 47 insertions, 1 deletions
diff --git a/spec/unit/data_collector_spec.rb b/spec/unit/data_collector_spec.rb
index 37df758ff2..25de91864a 100644
--- a/spec/unit/data_collector_spec.rb
+++ b/spec/unit/data_collector_spec.rb
@@ -23,6 +23,14 @@ require "chef/data_collector"
require "chef/resource_builder"
describe Chef::DataCollector do
+
+ # TODO:
+ # * auto-configure a URL that is relative to Chef Server URL,
+ # like https://chef.example/organizations/:orgname/data_collector
+ # * Use an HTTP client that does signed header auth if no token is configured
+ # * register_reporter should be `true` for the auto-configure case
+ # * when talking to a server without automate/data collector, disabling the collector should not be noisy
+
describe ".register_reporter?" do
context "when no data collector URL is configured" do
it "returns false" do
@@ -150,14 +158,52 @@ describe Chef::DataCollector do
end
end
end
+
end
describe Chef::DataCollector::Reporter do
let(:reporter) { described_class.new }
let(:run_status) { Chef::RunStatus.new(Chef::Node.new, Chef::EventDispatch::Dispatcher.new) }
+ let(:token) { "supersecrettoken" }
+
before do
Chef::Config[:data_collector][:server_url] = "http://my-data-collector-server.mycompany.com"
+ Chef::Config[:data_collector][:token] = token
+ end
+
+ describe "selecting token or signed header authentication" do
+
+ context "when the token is set in the config" do
+
+ before do
+ Chef::Config[:client_key] = "/no/key/should/exist/at/this/path.pem"
+ end
+
+ it "configures an HTTP client that doesn't do signed header auth" do
+ # Initializing with the wrong kind of HTTP class should cause Chef::Exceptions::PrivateKeyMissing
+ expect { reporter.http }.to_not raise_error
+ end
+
+ end
+
+ context "when no token is set in the config" do
+
+ let(:token) { nil }
+
+ let(:client_key) { File.join(CHEF_SPEC_DATA, "ssl", "private_key.pem") }
+
+ before do
+ Chef::Config[:client_key] = client_key
+ end
+
+ it "configures an HTTP client that does signed header auth" do
+ expect { reporter.http }.to_not raise_error
+ expect(reporter.http.options).to have_key(:signing_key_filename)
+ expect(reporter.http.options[:signing_key_filename]).to eq(client_key)
+ end
+ end
+
end
describe "#run_started" do
@@ -177,7 +223,7 @@ describe Chef::DataCollector::Reporter do
.to receive(:run_start_message)
.with(run_status)
.and_return(key: "value")
- expect(reporter).to receive(:send_to_data_collector).with('{"key":"value"}')
+ expect(reporter).to receive(:send_to_data_collector).with({ key: "value" })
reporter.run_started(run_status)
end
end