diff options
author | Noah Kantrowitz <noah@coderanger.net> | 2018-05-30 16:19:39 -0700 |
---|---|---|
committer | Noah Kantrowitz <noah@coderanger.net> | 2018-05-30 16:19:39 -0700 |
commit | adc252cce822004ff60219d0efdac2da96a0dcc9 (patch) | |
tree | f8184d592c14624e1303103200602061226c9c13 /spec/unit/http | |
parent | 16dcca01fad5b48a7c5d146c5b9f28bdefaa8ec0 (diff) | |
download | chef-adc252cce822004ff60219d0efdac2da96a0dcc9.tar.gz |
Add a test for ssh-agent mode.
Signed-off-by: Noah Kantrowitz <noah@coderanger.net>
Diffstat (limited to 'spec/unit/http')
-rw-r--r-- | spec/unit/http/authenticator_spec.rb | 41 |
1 files changed, 33 insertions, 8 deletions
diff --git a/spec/unit/http/authenticator_spec.rb b/spec/unit/http/authenticator_spec.rb index 5de39523cf..87f2a906b6 100644 --- a/spec/unit/http/authenticator_spec.rb +++ b/spec/unit/http/authenticator_spec.rb @@ -20,18 +20,18 @@ require "spec_helper" require "chef/http/authenticator" describe Chef::HTTP::Authenticator do - let(:class_instance) { Chef::HTTP::Authenticator.new } - let(:method) { double("method") } - let(:url) { double("url") } + let(:class_instance) { Chef::HTTP::Authenticator.new(client_name: 'test') } + let(:method) { "GET" } + let(:url) { URI("https://chef.example.com/organizations/test") } let(:headers) { Hash.new } - let(:data) { double("data") } - - before do - allow(class_instance).to receive(:authentication_headers).and_return({}) - end + let(:data) { "" } context "when handle_request is called" do shared_examples_for "merging the server API version into the headers" do + before do + allow(class_instance).to receive(:authentication_headers).and_return({}) + end + it "merges the default version of X-Ops-Server-API-Version into the headers" do # headers returned expect(class_instance.handle_request(method, url, headers, data)[2]). @@ -96,5 +96,30 @@ describe Chef::HTTP::Authenticator do class_instance.handle_request(method, url, headers, data) end end + + context "when ssh_agent_signing" do + let(:public_key) { <<-EOH } +-----BEGIN PUBLIC KEY----- +MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA49TA0y81ps0zxkOpmf5V +4/c4IeR5yVyQFpX3JpxO4TquwnRh8VSUhrw8kkTLmB3cS39Db+3HadvhoqCEbqPE +6915kXSuk/cWIcNozujLK7tkuPEyYVsyTioQAddSdfe+8EhQVf3oHxaKmUd6waXr +WqYCnhxgOjxocenREYNhZ/OETIeiPbOku47vB4nJK/0GhKBytL2XnsRgfKgDxf42 +BqAi1jglIdeq8lAWZNF9TbNBU21AO1iuT7Pm6LyQujhggPznR5FJhXKRUARXBJZa +wxpGV4dGtdcahwXNE4601aXPra+xPcRd2puCNoEDBzgVuTSsLYeKBDMSfs173W1Q +YwIDAQAB +-----END PUBLIC KEY----- +EOH + + let(:class_instance) { Chef::HTTP::Authenticator.new(client_name: 'test', raw_key: public_key, ssh_agent_signing: true) } + + it "sets use_ssh_agent if needed" do + expect(Mixlib::Authentication::SignedHeaderAuth).to receive(:signing_object).and_wrap_original { |m, *args| + m.call(*args).tap do |signing_obj| + expect(signing_obj).to receive(:sign).with(instance_of(OpenSSL::PKey::RSA), use_ssh_agent: true).and_return({}) + end + } + class_instance.handle_request(method, url, headers, data) + end + end end end |