crashlog-auth-hmac 1.1.6 → 1.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.travis.yml +3 -4
- data/Gemfile +2 -0
- data/Gemfile.lock +6 -1
- data/lib/crash_log/auth_hmac.rb +4 -2
- data/lib/crash_log/auth_hmac/version.rb +1 -1
- data/spec/crash_log/auth_hmac_spec.rb +12 -13
- data/spec/crash_log/rack_test_request_spec.rb +16 -4
- metadata +20 -12
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
crashlog-auth-hmac (1.1.
|
4
|
+
crashlog-auth-hmac (1.1.7)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
@@ -9,11 +9,14 @@ GEM
|
|
9
9
|
activesupport (3.2.7)
|
10
10
|
i18n (~> 0.6)
|
11
11
|
multi_json (~> 1.0)
|
12
|
+
bouncy-castle-java (1.5.0146.1)
|
12
13
|
chronic (0.6.7)
|
13
14
|
delorean (2.0.0)
|
14
15
|
chronic
|
15
16
|
diff-lcs (1.1.3)
|
16
17
|
i18n (0.6.0)
|
18
|
+
jruby-openssl (0.7.7)
|
19
|
+
bouncy-castle-java (>= 1.5.0146.1)
|
17
20
|
multi_json (1.3.6)
|
18
21
|
rack (1.4.1)
|
19
22
|
rack-test (0.6.1)
|
@@ -29,12 +32,14 @@ GEM
|
|
29
32
|
rspec-mocks (2.11.1)
|
30
33
|
|
31
34
|
PLATFORMS
|
35
|
+
java
|
32
36
|
ruby
|
33
37
|
|
34
38
|
DEPENDENCIES
|
35
39
|
activesupport (~> 3.2.0)
|
36
40
|
crashlog-auth-hmac!
|
37
41
|
delorean
|
42
|
+
jruby-openssl
|
38
43
|
rack-test
|
39
44
|
rake
|
40
45
|
rspec (>= 2.7.0)
|
data/lib/crash_log/auth_hmac.rb
CHANGED
@@ -75,7 +75,7 @@ module CrashLog
|
|
75
75
|
request.request_method
|
76
76
|
elsif request.is_a?(Hash) && request.has_key?(:method)
|
77
77
|
request[:method].to_s
|
78
|
-
elsif request.respond_to?(:env)
|
78
|
+
elsif request.respond_to?(:env)
|
79
79
|
request.env['REQUEST_METHOD']
|
80
80
|
elsif request.is_a?(Hash) && request.has_key?('REQUEST_METHOD')
|
81
81
|
request['REQUEST_METHOD']
|
@@ -231,7 +231,9 @@ module CrashLog
|
|
231
231
|
def signature(request, secret)
|
232
232
|
digest = OpenSSL::Digest::Digest.new('sha1')
|
233
233
|
string = canonical_string(request)
|
234
|
-
|
234
|
+
hmac = OpenSSL::HMAC.digest(digest, secret, string)
|
235
|
+
encoded_signature = Base64.encode64(hmac)
|
236
|
+
encoded_signature.gsub(/\n/, '').strip
|
235
237
|
end
|
236
238
|
|
237
239
|
def canonical_string(request)
|
@@ -79,39 +79,38 @@ describe CrashLog::AuthHMAC do
|
|
79
79
|
'content-type' => 'text/plain',
|
80
80
|
'content-md5' => 'blahblah',
|
81
81
|
'date' => "Thu, 10 Jul 2008 03:29:56 GMT")
|
82
|
-
|
83
|
-
@store
|
82
|
+
|
83
|
+
@store = {'my-key-id' => 'secret'}
|
84
84
|
@authhmac = CrashLog::AuthHMAC.new(@store)
|
85
85
|
end
|
86
86
|
|
87
87
|
describe "default AuthHMAC with CanonicalString signature" do
|
88
88
|
it "should add an Authorization header" do
|
89
|
-
@authhmac.sign!(@get_request, 'key-id')
|
89
|
+
@authhmac.sign!(@get_request, 'my-key-id')
|
90
90
|
@get_request.key?("Authorization").should be_true
|
91
91
|
end
|
92
92
|
|
93
93
|
it "should fetch the secret from the store" do
|
94
|
-
@store.should_receive(:[]).with('key-id').and_return('secret')
|
95
|
-
@authhmac.sign!(@get_request, 'key-id')
|
94
|
+
@store.should_receive(:[]).with('my-key-id').and_return('secret')
|
95
|
+
@authhmac.sign!(@get_request, 'my-key-id')
|
96
96
|
end
|
97
97
|
|
98
98
|
it "should prefix the Authorization Header with AuthHMAC" do
|
99
|
-
@authhmac.sign!(@get_request, 'key-id')
|
99
|
+
@authhmac.sign!(@get_request, 'my-key-id')
|
100
100
|
@get_request['Authorization'].should match(/^AuthHMAC /)
|
101
101
|
end
|
102
102
|
|
103
103
|
it "should include the key id as the first part of the Authorization header value" do
|
104
|
-
@authhmac.sign!(@get_request, 'key-id')
|
105
|
-
@get_request['Authorization'].should match(/^AuthHMAC key-id:/)
|
104
|
+
@authhmac.sign!(@get_request, 'my-key-id')
|
105
|
+
@get_request['Authorization'].should match(/^AuthHMAC my-key-id:/)
|
106
106
|
end
|
107
107
|
|
108
108
|
it "should include the base64 encoded HMAC signature as the last part of the header value" do
|
109
|
-
@authhmac.sign!(@get_request, 'key-id')
|
109
|
+
@authhmac.sign!(@get_request, 'my-key-id')
|
110
110
|
@get_request['Authorization'].should match(/:[A-Za-z0-9+\/]{26,28}[=]{0,2}$/)
|
111
111
|
end
|
112
112
|
|
113
113
|
it "should create a complete signature" do
|
114
|
-
@store.should_receive(:[]).with('my-key-id').and_return('secret')
|
115
114
|
@authhmac.sign!(@put_request, "my-key-id")
|
116
115
|
@put_request['Authorization'].should == "AuthHMAC my-key-id:71wAJM4IIu/3o6lcqx/tw7XnAJs="
|
117
116
|
end
|
@@ -123,16 +122,16 @@ describe CrashLog::AuthHMAC do
|
|
123
122
|
:service_id => 'MyService',
|
124
123
|
:signature => CustomSignature
|
125
124
|
}
|
126
|
-
|
125
|
+
store = {'my-key-id' => 'secret'}
|
126
|
+
@authhmac = CrashLog::AuthHMAC.new(store, @options)
|
127
127
|
end
|
128
128
|
|
129
129
|
it "should prefix the Authorization header with custom service id" do
|
130
|
-
@authhmac.sign!(@get_request, 'key-id')
|
130
|
+
@authhmac.sign!(@get_request, 'my-key-id')
|
131
131
|
@get_request['Authorization'].should match(/^MyService /)
|
132
132
|
end
|
133
133
|
|
134
134
|
it "should create a complete signature using options" do
|
135
|
-
@store.should_receive(:[]).with('my-key-id').and_return('secret')
|
136
135
|
@authhmac.sign!(@put_request, "my-key-id")
|
137
136
|
@put_request['Authorization'].should == "MyService my-key-id:/L4N1v1BZSHfAYkQjsvZn696D9c="
|
138
137
|
end
|
@@ -23,11 +23,11 @@ describe CrashLog::AuthHMAC do
|
|
23
23
|
it 'can process rack test requests' do
|
24
24
|
# HMAC uses date to validate request signature, we need to fix the date so
|
25
25
|
# that it matches.
|
26
|
-
Delorean.time_travel_to(
|
26
|
+
Delorean.time_travel_to(Time.utc(2012,10,04,8,31,16))
|
27
27
|
|
28
|
-
env = current_session.__send__(:env_for, '/
|
29
|
-
signature = CrashLog::AuthHMAC.
|
30
|
-
signature.should == "
|
28
|
+
env = current_session.__send__(:env_for, '/events', {:method => "POST", 'CONTENT_TYPE' => "application/json; charset=UTF-8"})
|
29
|
+
signature = CrashLog::AuthHMAC.signature(env, "2Xbz25UpU8nQxaSAKuixJQMDxuiqryxzArzSJJ8Ci3Mr")
|
30
|
+
signature.should == "Rqj0DdG4/jNrzOXdybz13CaKzXU="
|
31
31
|
end
|
32
32
|
|
33
33
|
it 'can handle hash requests' do
|
@@ -49,4 +49,16 @@ describe CrashLog::AuthHMAC do
|
|
49
49
|
sig = CrashLog::AuthHMAC.signature(request_hash, 'secret')
|
50
50
|
sig.should == CrashLog::AuthHMAC.signature(standard_request, 'secret')
|
51
51
|
end
|
52
|
+
|
53
|
+
it 'accepts real request without content md5' do
|
54
|
+
Delorean.time_travel_to(Date.parse("Thu, 04 Oct 2012 08:31:16 GMT"))
|
55
|
+
|
56
|
+
request = Net::HTTP::Post.new("/events",
|
57
|
+
'content-type' => 'application/json; charset=UTF-8',
|
58
|
+
'date' => "Thu, 04 Oct 2012 08:31:16 GMT")
|
59
|
+
|
60
|
+
sig = CrashLog::AuthHMAC.signature(request, '2Xbz25UpU8nQxaSAKuixJQMDxuiqryxzArzSJJ8Ci3Mr')
|
61
|
+
sig.should == 'Rqj0DdG4/jNrzOXdybz13CaKzXU='
|
62
|
+
end
|
63
|
+
|
52
64
|
end
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: crashlog-auth-hmac
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
4
|
+
prerelease:
|
5
|
+
version: 1.1.7
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Ivan Vanderbyl
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-11-19 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: A Ruby Gem for authenticating HTTP requests using a HMAC
|
15
15
|
email:
|
@@ -36,26 +36,34 @@ files:
|
|
36
36
|
- spec/spec_helper.rb
|
37
37
|
homepage: http://crashlog.io
|
38
38
|
licenses: []
|
39
|
-
post_install_message:
|
39
|
+
post_install_message:
|
40
40
|
rdoc_options: []
|
41
41
|
require_paths:
|
42
42
|
- lib
|
43
43
|
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
-
none: false
|
45
44
|
requirements:
|
46
45
|
- - ! '>='
|
47
46
|
- !ruby/object:Gem::Version
|
48
|
-
|
49
|
-
|
47
|
+
segments:
|
48
|
+
- 0
|
49
|
+
hash: 2
|
50
|
+
version: !binary |-
|
51
|
+
MA==
|
50
52
|
none: false
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
54
|
requirements:
|
52
55
|
- - ! '>='
|
53
56
|
- !ruby/object:Gem::Version
|
54
|
-
|
57
|
+
segments:
|
58
|
+
- 0
|
59
|
+
hash: 2
|
60
|
+
version: !binary |-
|
61
|
+
MA==
|
62
|
+
none: false
|
55
63
|
requirements: []
|
56
|
-
rubyforge_project:
|
57
|
-
rubygems_version: 1.8.
|
58
|
-
signing_key:
|
64
|
+
rubyforge_project:
|
65
|
+
rubygems_version: 1.8.24
|
66
|
+
signing_key:
|
59
67
|
specification_version: 3
|
60
68
|
summary: A Ruby Gem for authenticating HTTP requests using a HMAC
|
61
69
|
test_files:
|