summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoah Kantrowitz <noah@coderanger.net>2018-05-30 15:57:48 -0700
committerNoah Kantrowitz <noah@coderanger.net>2018-05-30 15:57:48 -0700
commite3fa9ca9d2b40422c2bc7b485e9dbcc9edfb4fed (patch)
treebb3a3220e7efd91628fc6fe3bbabd26d9e0a0b84
parent88c7a1200909b7b3ae2ee1484498475dda63a7cf (diff)
downloadmixlib-authentication-e3fa9ca9d2b40422c2bc7b485e9dbcc9edfb4fed.tar.gz
Sigh, the existing arguments are positional not kwargs.
Make both syntaxes do the right thing. Signed-off-by: Noah Kantrowitz <noah@coderanger.net>
-rw-r--r--lib/mixlib/authentication/signedheaderauth.rb17
-rw-r--r--spec/mixlib/authentication/mixlib_authentication_spec.rb3
2 files changed, 19 insertions, 1 deletions
diff --git a/lib/mixlib/authentication/signedheaderauth.rb b/lib/mixlib/authentication/signedheaderauth.rb
index c9102dd..dcc9ee1 100644
--- a/lib/mixlib/authentication/signedheaderauth.rb
+++ b/lib/mixlib/authentication/signedheaderauth.rb
@@ -100,7 +100,22 @@ module Mixlib
# true, this must have the public key portion populated. If `use_ssh_agent`
# is false, this must have the private key portion populated.
# @param use_ssh_agent [Boolean] If true, use ssh-agent for request signing.
- def sign(rsa_key, sign_algorithm = algorithm, sign_version = proto_version, use_ssh_agent: false)
+ def sign(rsa_key, sign_algorithm = algorithm, sign_version = proto_version, **opts)
+ # Backwards compat stuff.
+ if sign_algorithm.is_a?(Hash)
+ # Was called like sign(key, sign_algorithm: 'foo', other: 'bar')
+ opts.update(sign_algorithm)
+ opts[:sign_algorithm] ||= algorithm
+ else
+ # Was called like sign(key, 'foo', '1.3', other: 'bar')
+ Mixlib::Authentication.logger.warn("Using deprecated positional arguments for sign(), please update to keyword arguments (from #{caller[1][/^(.*:\d+):in /, 1]})")
+ opts[:sign_algorithm] ||= sign_algorithm
+ opts[:sign_version] ||= sign_version
+ end
+ sign_algorithm = opts[:sign_algorithm]
+ sign_version = opts[:sign_version]
+ use_ssh_agent = opts[:use_ssh_agent]
+
digest = validate_sign_version_digest!(sign_algorithm, sign_version)
# Our multiline hash for authorization will be encoded in multiple header
# lines - X-Ops-Authorization-1, ... (starts at 1, not 0!)
diff --git a/spec/mixlib/authentication/mixlib_authentication_spec.rb b/spec/mixlib/authentication/mixlib_authentication_spec.rb
index 4307470..2c233a2 100644
--- a/spec/mixlib/authentication/mixlib_authentication_spec.rb
+++ b/spec/mixlib/authentication/mixlib_authentication_spec.rb
@@ -121,14 +121,17 @@ describe "Mixlib::Authentication::SignedHeaderAuth" do
# the results of res.inspect and copy them as appropriate into the
# the constants in this file.
expect(V1_1_SIGNING_OBJECT.sign(PRIVATE_KEY, algorithm, version)).to eq(EXPECTED_SIGN_RESULT_V1_1)
+ expect(V1_1_SIGNING_OBJECT.sign(PRIVATE_KEY, sign_algorithm: algorithm, sign_version: version)).to eq(EXPECTED_SIGN_RESULT_V1_1)
end
it "should not choke when signing a request for a long user id with version 1.1" do
expect { LONG_SIGNING_OBJECT.sign(PRIVATE_KEY, "sha1", "1.1") }.not_to raise_error
+ expect { LONG_SIGNING_OBJECT.sign(PRIVATE_KEY, sign_algorithm: "sha1", sign_version: "1.1") }.not_to raise_error
end
it "should choke when signing a request for a long user id with version 1.0" do
expect { LONG_SIGNING_OBJECT.sign(PRIVATE_KEY, "sha1", "1.0") }.to raise_error(OpenSSL::PKey::RSAError)
+ expect { LONG_SIGNING_OBJECT.sign(PRIVATE_KEY, sign_algorithm: "sha1", sign_version: "1.0") }.to raise_error(OpenSSL::PKey::RSAError)
end
it "should choke when signing a request with a bad version" do