summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJay Mundrawala <jdmundrawala@gmail.com>2015-11-30 10:37:11 -0800
committerJay Mundrawala <jdmundrawala@gmail.com>2015-11-30 10:37:11 -0800
commit53fa0aa303713a99261d5182ccfea0c3bb06deb4 (patch)
treefb58c97b59a65b0b834dc06f5256ab34ed9193cb
parent09d47bde7f833fb13c59dac1fa12bd8a5c209106 (diff)
downloadmixlib-authentication-jdm/sign-v1.3.tar.gz
Use DEFAULT_SERVER_API_VERSION in all the placesjdm/sign-v1.3
-rw-r--r--lib/mixlib/authentication.rb2
-rw-r--r--lib/mixlib/authentication/http_authentication_request.rb2
-rw-r--r--lib/mixlib/authentication/signedheaderauth.rb2
-rw-r--r--spec/mixlib/authentication/http_authentication_request_spec.rb4
-rw-r--r--spec/mixlib/authentication/mixlib_authentication_spec.rb6
5 files changed, 13 insertions, 3 deletions
diff --git a/lib/mixlib/authentication.rb b/lib/mixlib/authentication.rb
index ab10db7..245aa24 100644
--- a/lib/mixlib/authentication.rb
+++ b/lib/mixlib/authentication.rb
@@ -20,6 +20,8 @@ require 'mixlib/log'
module Mixlib
module Authentication
+ DEFAULT_SERVER_API_VERSION = '0'
+
class AuthenticationError < StandardError
end
diff --git a/lib/mixlib/authentication/http_authentication_request.rb b/lib/mixlib/authentication/http_authentication_request.rb
index efa8d80..ad8354f 100644
--- a/lib/mixlib/authentication/http_authentication_request.rb
+++ b/lib/mixlib/authentication/http_authentication_request.rb
@@ -65,7 +65,7 @@ module Mixlib
end
def server_api_version
- (headers[:x_ops_server_api_version] || '0').chomp
+ (headers[:x_ops_server_api_version] || DEFAULT_SERVER_API_VERSION).chomp
end
def request_signature
diff --git a/lib/mixlib/authentication/signedheaderauth.rb b/lib/mixlib/authentication/signedheaderauth.rb
index 27e0e6a..8faf313 100644
--- a/lib/mixlib/authentication/signedheaderauth.rb
+++ b/lib/mixlib/authentication/signedheaderauth.rb
@@ -44,8 +44,6 @@ module Mixlib
DEFAULT_SIGN_ALGORITHM = 'sha1'.freeze
DEFAULT_PROTO_VERSION = '1.0'.freeze
- DEFAULT_SERVER_API_VERSION = '0'
-
# === signing_object
# This is the intended interface for signing requests with the
# Opscode/Chef signed header protocol. This wraps the constructor for a
diff --git a/spec/mixlib/authentication/http_authentication_request_spec.rb b/spec/mixlib/authentication/http_authentication_request_spec.rb
index b0299b9..1c6c814 100644
--- a/spec/mixlib/authentication/http_authentication_request_spec.rb
+++ b/spec/mixlib/authentication/http_authentication_request_spec.rb
@@ -125,4 +125,8 @@ SIG
expect(@http_authentication_request.request_signature).to eq(expected.chomp)
end
+ it "defaults to server api version 0" do
+ expect(@http_authentication_request.server_api_version).to eq('0')
+ end
+
end
diff --git a/spec/mixlib/authentication/mixlib_authentication_spec.rb b/spec/mixlib/authentication/mixlib_authentication_spec.rb
index 4ae0876..41cd7e9 100644
--- a/spec/mixlib/authentication/mixlib_authentication_spec.rb
+++ b/spec/mixlib/authentication/mixlib_authentication_spec.rb
@@ -102,6 +102,10 @@ describe "Mixlib::Authentication::SignedHeaderAuth" do
expect(V1_3_SHA1_SIGNING_OBJECT.sign(PRIVATE_KEY)).to eq(EXPECTED_SIGN_RESULT_V1_3_SHA1)
end
+ it "should default to server api version 0 for version 1.3" do
+ expect(V1_3_SHA1_SIGNING_OBJECT_API0.server_api_version).to eq('0')
+ end
+
it "should generate the correct string to sign and signature for version 1.3 with SHA256" do
expect(V1_3_SHA256_SIGNING_OBJECT.proto_version).to eq("1.3")
expect(V1_3_SHA256_SIGNING_OBJECT.algorithm).to eq("sha256")
@@ -710,6 +714,8 @@ V1_3_SHA256_CANONICAL_REQUEST = V1_3_SHA256_CANONICAL_REQUEST_DATA.chomp
V1_3_SHA256_SIGNING_OBJECT = Mixlib::Authentication::SignedHeaderAuth.signing_object(V1_3_ARGS_SHA256)
V1_3_SHA1_SIGNING_OBJECT = Mixlib::Authentication::SignedHeaderAuth.signing_object(V1_3_ARGS_SHA1)
+V1_3_SHA1_SIGNING_OBJECT_API0 = Mixlib::Authentication::SignedHeaderAuth.signing_object(
+ V1_3_ARGS_SHA1.dup.tap {|x| x.delete(:headers)})
V1_1_SIGNING_OBJECT = Mixlib::Authentication::SignedHeaderAuth.signing_object(V1_1_ARGS)
V1_0_SIGNING_OBJECT = Mixlib::Authentication::SignedHeaderAuth.signing_object(V1_0_ARGS)
LONG_SIGNING_OBJECT = Mixlib::Authentication::SignedHeaderAuth.signing_object(LONG_PATH_LONG_USER_ARGS)