summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith84@gmail.com>2019-07-22 12:23:06 -0700
committerTim Smith <tsmith84@gmail.com>2019-08-06 20:33:17 -0700
commit3f1549cef2a452dbc3b655513e101c3fd8f8cf88 (patch)
tree11debdcd8264d9b5b6194a1559850d16bbcb7e01
parentfc26f4af81bd3b31dd41fc12ece770a0ced7d42f (diff)
downloadmixlib-authentication-3f1549cef2a452dbc3b655513e101c3fd8f8cf88.tar.gz
Chefstyle fixes
Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--.rubocop.yml2
-rw-r--r--Rakefile2
-rw-r--r--lib/mixlib/authentication/http_authentication_request.rb2
-rw-r--r--lib/mixlib/authentication/signatureverification.rb2
-rw-r--r--lib/mixlib/authentication/signedheaderauth.rb54
-rw-r--r--spec/mixlib/authentication/digester_spec.rb6
6 files changed, 35 insertions, 33 deletions
diff --git a/.rubocop.yml b/.rubocop.yml
deleted file mode 100644
index 5b837e2..0000000
--- a/.rubocop.yml
+++ /dev/null
@@ -1,2 +0,0 @@
-Style/HashSyntax:
- Enabled: true
diff --git a/Rakefile b/Rakefile
index 8aa53bc..0bd0b29 100644
--- a/Rakefile
+++ b/Rakefile
@@ -38,4 +38,4 @@ task :console do
IRB.start
end
-task default: [:spec, :style]
+task default: %i{spec style}
diff --git a/lib/mixlib/authentication/http_authentication_request.rb b/lib/mixlib/authentication/http_authentication_request.rb
index 8e45b4b..16907d1 100644
--- a/lib/mixlib/authentication/http_authentication_request.rb
+++ b/lib/mixlib/authentication/http_authentication_request.rb
@@ -22,7 +22,7 @@ module Mixlib
module Authentication
class HTTPAuthenticationRequest
- MANDATORY_HEADERS = [:x_ops_sign, :x_ops_userid, :x_ops_timestamp, :host, :x_ops_content_hash].freeze
+ MANDATORY_HEADERS = %i{x_ops_sign x_ops_userid x_ops_timestamp host x_ops_content_hash}.freeze
attr_reader :request
diff --git a/lib/mixlib/authentication/signatureverification.rb b/lib/mixlib/authentication/signatureverification.rb
index 1dfafd6..3231214 100644
--- a/lib/mixlib/authentication/signatureverification.rb
+++ b/lib/mixlib/authentication/signatureverification.rb
@@ -203,7 +203,7 @@ module Mixlib
# No file_param; we're running in Merb, or it's just not there..
if file_param.nil?
hash_param = request.params.values.find { |value| value.respond_to?(:has_key?) } # Hash responds to :has_key? .
- if !hash_param.nil?
+ unless hash_param.nil?
file_param = hash_param.values.find { |value| value.respond_to?(:read) } # File/Tempfile responds to :read.
end
end
diff --git a/lib/mixlib/authentication/signedheaderauth.rb b/lib/mixlib/authentication/signedheaderauth.rb
index 2a54c76..0ca74c4 100644
--- a/lib/mixlib/authentication/signedheaderauth.rb
+++ b/lib/mixlib/authentication/signedheaderauth.rb
@@ -34,7 +34,7 @@ module Mixlib
"1.0" => "sha1",
"1.1" => "sha1",
"1.3" => "sha256",
- }.freeze()
+ }.freeze
# Use of SUPPORTED_ALGORITHMS and SUPPORTED_VERSIONS is deprecated. Use
# ALGORITHM_FOR_VERSION instead
@@ -74,15 +74,14 @@ module Mixlib
# * `:host`: The host part of the URI
def self.signing_object(args = {})
SigningObject.new(args[:http_method],
- args[:path],
- args[:body],
- args[:host],
- args[:timestamp],
- args[:user_id],
- args[:file],
- args[:proto_version],
- args[:headers]
- )
+ args[:path],
+ args[:body],
+ args[:host],
+ args[:timestamp],
+ args[:user_id],
+ args[:file],
+ args[:proto_version],
+ args[:headers])
end
def algorithm
@@ -175,7 +174,7 @@ module Mixlib
# ====Parameters
#
def canonical_path
- p = path.gsub(/\/+/, "/")
+ p = path.gsub(%r{/+}, "/")
p.length > 1 ? p.chomp("/") : p
end
@@ -191,6 +190,7 @@ module Mixlib
else
@hashed_body_digest = digest
end
+
# Hash the file object if it was passed in, otherwise hash based on
# the body.
# TODO: tim 2009-12-28: It'd be nice to just remove this special case,
@@ -283,11 +283,13 @@ module Mixlib
do_sign_ssh_agent(rsa_key, string_to_sign)
else
raise AuthenticationError, "RSA private key is required to sign requests, but a public key was provided" unless rsa_key.private?
+
rsa_key.sign(digest.new, string_to_sign)
end
else
raise AuthenticationError, "Agent signing mode requires signing protocol version 1.3 or newer" if use_ssh_agent
raise AuthenticationError, "RSA private key is required to sign requests, but a public key was provided" unless rsa_key.private?
+
rsa_key.private_encrypt(string_to_sign)
end
end
@@ -339,25 +341,25 @@ module Mixlib
# generate a request signature. `SignedHeaderAuth.signing_object()`
# provides a more convenient interface to the constructor.
SigningObject = Struct.new(:http_method, :path, :body, :host,
- :timestamp, :user_id, :file, :proto_version,
- :headers) do
+ :timestamp, :user_id, :file, :proto_version,
+ :headers) do
- include SignedHeaderAuth
+ include SignedHeaderAuth
- def proto_version
- (self[:proto_version] || SignedHeaderAuth::DEFAULT_PROTO_VERSION).to_s
- end
+ def proto_version
+ (self[:proto_version] || SignedHeaderAuth::DEFAULT_PROTO_VERSION).to_s
+ end
- def server_api_version
- key = (self[:headers] || {}).keys.select do |k|
- k.casecmp("x-ops-server-api-version") == 0
- end.first
- if key
- self[:headers][key]
- else
- DEFAULT_SERVER_API_VERSION
+ def server_api_version
+ key = (self[:headers] || {}).keys.select do |k|
+ k.casecmp("x-ops-server-api-version") == 0
+ end.first
+ if key
+ self[:headers][key]
+ else
+ DEFAULT_SERVER_API_VERSION
+ end
end
end
- end
end
end
diff --git a/spec/mixlib/authentication/digester_spec.rb b/spec/mixlib/authentication/digester_spec.rb
index c54efa5..d094f40 100644
--- a/spec/mixlib/authentication/digester_spec.rb
+++ b/spec/mixlib/authentication/digester_spec.rb
@@ -27,14 +27,16 @@ describe Mixlib::Authentication::Digester do
describe "#hash_file" do
it "should default to use SHA1" do
expect(described_class.hash_file(StringIO.new(test_string))).to(
- eq(test_string_checksum))
+ eq(test_string_checksum)
+ )
end
end
describe "#hash_string" do
it "should default to use SHA1" do
expect(described_class.hash_string(test_string)).to(
- eq(test_string_checksum))
+ eq(test_string_checksum)
+ )
end
end
end