ey-hmac 2.0.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +3 -4
- data/README.md +1 -1
- data/ey-hmac.gemspec +1 -3
- data/lib/ey-hmac/adapter/faraday.rb +11 -5
- data/lib/ey-hmac/version.rb +1 -1
- data/spec/faraday_spec.rb +70 -37
- data/spec/rack_spec.rb +1 -0
- metadata +3 -5
- data/Guardfile +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4bf59e1087a2bb852ce1369afa06913660f30c2e
|
4
|
+
data.tar.gz: 93441d3b60b6a85ec126c0451c804b747a722b96
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5a9898ab08b0f02936a94bafd16e58565df0f74de3e79636647823769e1b73cbd97f99ab5e938a1379f4e12441bc1fa3ff6a7dd63ef7dbca7f74ee0ff178a8e8
|
7
|
+
data.tar.gz: ea32437e299a19a3a712e06f2532a32dfd89a5d03c7f3a6a8ad5983fb88d9e73ed7a92f732cc3e0a9b194c55e8393b2092784ee58e7bdde5bbc6b9ce129f6045
|
data/Gemfile
CHANGED
@@ -4,10 +4,8 @@ source 'https://rubygems.org'
|
|
4
4
|
gemspec
|
5
5
|
|
6
6
|
group(:test) do
|
7
|
-
gem 'guard-bundler'
|
8
|
-
gem 'guard-rspec', '~> 4.2'
|
9
7
|
gem 'pry-nav'
|
10
|
-
gem 'rspec', '~>
|
8
|
+
gem 'rspec', '~> 3.3'
|
11
9
|
end
|
12
10
|
|
13
11
|
group(:rack) do
|
@@ -17,5 +15,6 @@ group(:rack) do
|
|
17
15
|
end
|
18
16
|
|
19
17
|
group(:faraday) do
|
20
|
-
gem 'faraday', '~> 0.9
|
18
|
+
gem 'faraday', '~> 0.9'
|
19
|
+
gem 'faraday_middleware'
|
21
20
|
end
|
data/README.md
CHANGED
data/ey-hmac.gemspec
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'ey-hmac/version'
|
2
|
+
require File.expand_path('../lib/ey-hmac/version', __FILE__)
|
5
3
|
|
6
4
|
Gem::Specification.new do |gem|
|
7
5
|
gem.name = "ey-hmac"
|
@@ -10,16 +10,21 @@ class Ey::Hmac::Adapter::Faraday < Ey::Hmac::Adapter
|
|
10
10
|
def content_digest
|
11
11
|
if existing = %w[CONTENT-DIGEST CONTENT_DIGEST Content-Digest Content_Digest].inject(nil) { |r,h| r || request[:request_headers][h] }
|
12
12
|
existing
|
13
|
-
elsif
|
14
|
-
|
15
|
-
|
13
|
+
elsif body
|
14
|
+
digestable = if body.respond_to?(:rewind)
|
15
|
+
body.rewind
|
16
|
+
body.read.tap { |_| body.rewind }
|
17
|
+
else
|
18
|
+
body.to_s
|
19
|
+
end
|
20
|
+
|
21
|
+
request[:request_headers]['Content-Digest'] = Digest::MD5.hexdigest(digestable)
|
16
22
|
end
|
17
23
|
end
|
18
24
|
|
19
25
|
def body
|
20
26
|
if request[:body] && request[:body].to_s != ""
|
21
27
|
request[:body]
|
22
|
-
else nil
|
23
28
|
end
|
24
29
|
end
|
25
30
|
|
@@ -33,7 +38,8 @@ class Ey::Hmac::Adapter::Faraday < Ey::Hmac::Adapter
|
|
33
38
|
end
|
34
39
|
|
35
40
|
def sign!(key_id, key_secret)
|
36
|
-
%w[CONTENT-TYPE CONTENT_TYPE Content-Type Content_Type].inject(nil){|r,h| request[:request_headers][h]}
|
41
|
+
%w[CONTENT-TYPE CONTENT_TYPE Content-Type Content_Type].inject(nil) { |r,h| request[:request_headers][h] }
|
42
|
+
|
37
43
|
if options[:version]
|
38
44
|
request[:request_headers]['X-Signature-Version'] = options[:version]
|
39
45
|
end
|
data/lib/ey-hmac/version.rb
CHANGED
data/spec/faraday_spec.rb
CHANGED
@@ -2,24 +2,55 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe "faraday" do
|
4
4
|
before(:all) { Bundler.require(:faraday) }
|
5
|
-
|
6
|
-
let!(:
|
5
|
+
|
6
|
+
let!(:key_id) { SecureRandom.hex(8) }
|
7
|
+
let!(:key_secret) { SecureRandom.hex(16) }
|
7
8
|
|
8
9
|
describe "adapter" do
|
9
|
-
let!(:adapter)
|
10
|
+
let!(:adapter) { Ey::Hmac::Adapter::Faraday }
|
10
11
|
|
11
|
-
it "
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
it "signs a multipart post" do
|
13
|
+
app = lambda do |env|
|
14
|
+
authenticated = Ey::Hmac.authenticate!(env, adapter: Ey::Hmac::Adapter::Rack) do |auth_id|
|
15
|
+
(auth_id == key_id) && key_secret
|
16
|
+
end
|
17
|
+
[(authenticated ? 200 : 401), {"Content-Type" => "text/plain"}, []]
|
18
|
+
end
|
19
|
+
|
20
|
+
require 'ey-hmac/faraday'
|
21
|
+
|
22
|
+
connection = Faraday.new do |c|
|
23
|
+
c.request :multipart
|
24
|
+
c.request :json
|
25
|
+
|
26
|
+
c.use :hmac, key_id, key_secret
|
27
|
+
|
28
|
+
c.adapter(:rack, app)
|
29
|
+
end
|
30
|
+
|
31
|
+
tempfile = Tempfile.new("hmac")
|
32
|
+
tempfile.write SecureRandom.hex(512)
|
33
|
+
tempfile.close
|
34
|
+
|
35
|
+
expect(
|
36
|
+
connection.post { |req| req.body = {"output" => Faraday::UploadIO.new(tempfile.path, "text/plain")} }.status
|
37
|
+
).to eq(200)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "signs and reads a request" do
|
41
|
+
request = Faraday::Request.new.tap { |r|
|
42
|
+
r.method = :get
|
43
|
+
r.path = "/auth"
|
44
|
+
r.body = "{1: 2}"
|
16
45
|
r.headers = {"Content-Type" => "application/xml"}
|
17
|
-
|
46
|
+
}.to_env(
|
47
|
+
Faraday::Connection.new("http://localhost")
|
48
|
+
)
|
18
49
|
|
19
50
|
Ey::Hmac.sign!(request, key_id, key_secret, adapter: adapter)
|
20
51
|
|
21
|
-
expect(request[:request_headers]['Authorization']).to
|
22
|
-
expect(request[:request_headers]['Content-Digest']).to
|
52
|
+
expect(request[:request_headers]['Authorization']).to start_with("EyHmac")
|
53
|
+
expect(request[:request_headers]['Content-Digest']).to eq(Digest::MD5.hexdigest(request[:body]))
|
23
54
|
expect(Time.parse(request[:request_headers]['Date'])).not_to be_nil
|
24
55
|
|
25
56
|
yielded = false
|
@@ -33,13 +64,15 @@ describe "faraday" do
|
|
33
64
|
expect(yielded).to be_truthy
|
34
65
|
end
|
35
66
|
|
36
|
-
it "
|
37
|
-
request = Faraday::Request.new.tap
|
38
|
-
r.method
|
39
|
-
r.path
|
40
|
-
r.body
|
67
|
+
it "does not set Content-Digest if body is nil" do
|
68
|
+
request = Faraday::Request.new.tap { |r|
|
69
|
+
r.method = :get
|
70
|
+
r.path = "/auth"
|
71
|
+
r.body = nil
|
41
72
|
r.headers = {"Content-Type" => "application/xml"}
|
42
|
-
|
73
|
+
}.to_env(
|
74
|
+
Faraday::Connection.new("http://localhost")
|
75
|
+
)
|
43
76
|
|
44
77
|
Ey::Hmac.sign!(request, key_id, key_secret, adapter: adapter)
|
45
78
|
|
@@ -58,19 +91,19 @@ describe "faraday" do
|
|
58
91
|
expect(yielded).to be_truthy
|
59
92
|
end
|
60
93
|
|
61
|
-
it "
|
94
|
+
it "does not set Content-Digest if body is empty" do
|
62
95
|
request = Faraday::Request.new.tap do |r|
|
63
96
|
r.method = :get
|
64
97
|
r.path = "/auth"
|
65
98
|
r.body = ""
|
66
99
|
r.headers = {"Content-Type" => "application/xml"}
|
67
|
-
|
100
|
+
end.to_env(Faraday::Connection.new("http://localhost"))
|
68
101
|
|
69
102
|
Ey::Hmac.sign!(request, key_id, key_secret, adapter: adapter)
|
70
103
|
|
71
|
-
expect(request[:request_headers]['Authorization']).to
|
72
|
-
expect(request[:request_headers]).not_to
|
73
|
-
expect(Time.parse(request[:request_headers]['Date'])).not_to be_nil
|
104
|
+
expect(request[:request_headers]['Authorization']).to start_with("EyHmac")
|
105
|
+
expect(request[:request_headers]).not_to have_key('Content-Digest')
|
106
|
+
#expect(Time.parse(request[:request_headers]['Date'])).not_to be_nil
|
74
107
|
|
75
108
|
yielded = false
|
76
109
|
|
@@ -84,20 +117,20 @@ describe "faraday" do
|
|
84
117
|
end
|
85
118
|
|
86
119
|
context "with a request" do
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
120
|
+
let!(:request) do
|
121
|
+
Faraday::Request.new.tap do |r|
|
122
|
+
r.method = :get
|
123
|
+
r.path = "/auth"
|
124
|
+
r.body = "{1: 2}"
|
125
|
+
r.headers = {"Content-Type" => "application/xml"}
|
126
|
+
end.to_env(Faraday::Connection.new("http://localhost"))
|
127
|
+
end
|
95
128
|
include_examples "authentication"
|
96
129
|
end
|
97
130
|
end
|
98
131
|
|
99
132
|
describe "middleware" do
|
100
|
-
it "
|
133
|
+
it "accepts a SHA1 signature" do
|
101
134
|
require 'ey-hmac/faraday'
|
102
135
|
Bundler.require(:rack)
|
103
136
|
|
@@ -116,7 +149,7 @@ describe "faraday" do
|
|
116
149
|
expect(connection.get("/resources").status).to eq(200)
|
117
150
|
end
|
118
151
|
|
119
|
-
it "
|
152
|
+
it "accepts a SHA256 signature" do # default
|
120
153
|
require 'ey-hmac/faraday'
|
121
154
|
Bundler.require(:rack)
|
122
155
|
|
@@ -135,7 +168,7 @@ describe "faraday" do
|
|
135
168
|
expect(connection.get("/resources").status).to eq(200)
|
136
169
|
end
|
137
170
|
|
138
|
-
it "
|
171
|
+
it "accepts multiple digest signatures" do # default
|
139
172
|
require 'ey-hmac/faraday'
|
140
173
|
Bundler.require(:rack)
|
141
174
|
|
@@ -154,7 +187,7 @@ describe "faraday" do
|
|
154
187
|
expect(connection.get("/resources").status).to eq(200)
|
155
188
|
end
|
156
189
|
|
157
|
-
it "
|
190
|
+
it "signs empty request" do
|
158
191
|
require 'ey-hmac/faraday'
|
159
192
|
Bundler.require(:rack)
|
160
193
|
|
@@ -177,9 +210,9 @@ describe "faraday" do
|
|
177
210
|
end
|
178
211
|
|
179
212
|
expect(connection.get do |req|
|
180
|
-
req.path
|
181
|
-
req.body
|
182
|
-
req.params
|
213
|
+
req.path = "/resource"
|
214
|
+
req.body = nil
|
215
|
+
req.params = {"a" => "1"}
|
183
216
|
req.headers = {"Content-Type" => "application/x-www-form-urlencoded"}
|
184
217
|
end.status).to eq(200)
|
185
218
|
end
|
data/spec/rack_spec.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ey-hmac
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Josh Lane & Jason Hansen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-09-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -48,7 +48,6 @@ files:
|
|
48
48
|
- ".gitignore"
|
49
49
|
- ".travis.yml"
|
50
50
|
- Gemfile
|
51
|
-
- Guardfile
|
52
51
|
- LICENSE.txt
|
53
52
|
- README.md
|
54
53
|
- Rakefile
|
@@ -84,7 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
84
83
|
version: '0'
|
85
84
|
requirements: []
|
86
85
|
rubyforge_project:
|
87
|
-
rubygems_version: 2.
|
86
|
+
rubygems_version: 2.4.5
|
88
87
|
signing_key:
|
89
88
|
specification_version: 4
|
90
89
|
summary: Lightweight HMAC signing libraries and middleware for Farday and Rack
|
@@ -93,4 +92,3 @@ test_files:
|
|
93
92
|
- spec/rack_spec.rb
|
94
93
|
- spec/shared/authenticated.rb
|
95
94
|
- spec/spec_helper.rb
|
96
|
-
has_rdoc:
|