ey-hmac 2.0.0 → 2.0.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8dfeeb93b92db1297b05223d6bb2b3e5aebc4baf
4
- data.tar.gz: 4675e5002ad0686d6a819df058c6768110d442a1
3
+ metadata.gz: 4bf59e1087a2bb852ce1369afa06913660f30c2e
4
+ data.tar.gz: 93441d3b60b6a85ec126c0451c804b747a722b96
5
5
  SHA512:
6
- metadata.gz: 26a224b85612a8f673894612a5e0cc130a2f0dd0bccb0c945611bc2bc30c479b088cd7d19db3425ad09350c63f0c3e6e3b3304195239966dad760deccd8c33a4
7
- data.tar.gz: b977ba7137c163af67c3c2a4c5eaf49f7f8e1e7ce11e9967fd07f3aa1d39a1e399bfd4aa77af2a7ca62f477803c5fc440e3630dd3ab555bda4dfaf1962433901
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', '~> 2.99'
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.0'
18
+ gem 'faraday', '~> 0.9'
19
+ gem 'faraday_middleware'
21
20
  end
data/README.md CHANGED
@@ -41,7 +41,7 @@ end
41
41
  require 'ey-hmac/faraday'
42
42
 
43
43
  connection = Faraday.new do |c|
44
- c.request :hmac, key_id, key_secret
44
+ c.use :hmac, key_id, key_secret
45
45
  c.adapter(:rack, app)
46
46
  end
47
47
  ```
data/ey-hmac.gemspec CHANGED
@@ -1,7 +1,5 @@
1
1
  # -*- encoding: utf-8 -*-
2
- lib = File.expand_path('../lib', __FILE__)
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 digestable = body && Digest::MD5.hexdigest(body)
14
- request[:request_headers]['Content-Digest'] = digestable
15
- else nil
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
@@ -1,5 +1,5 @@
1
1
  module Ey
2
2
  module Hmac
3
- VERSION = "2.0.0"
3
+ VERSION = "2.0.1"
4
4
  end
5
5
  end
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
- let!(:key_id) { (0...8).map{ 65.+(rand(26)).chr}.join }
6
- let!(:key_secret) { (0...16).map{ 65.+(rand(26)).chr}.join }
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) { Ey::Hmac::Adapter::Faraday }
10
+ let!(:adapter) { Ey::Hmac::Adapter::Faraday }
10
11
 
11
- it "should sign and read request" do
12
- request = Faraday::Request.new.tap do |r|
13
- r.method = :get
14
- r.path = "/auth"
15
- r.body = "{1: 2}"
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
- end.to_env(Faraday::Connection.new("http://localhost"))
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 start_with("EyHmac")
22
- expect(request[:request_headers]['Content-Digest']).to eq(Digest::MD5.hexdigest(request[:body]))
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 "should not set Content-Digest if body is nil" do
37
- request = Faraday::Request.new.tap do |r|
38
- r.method = :get
39
- r.path = "/auth"
40
- r.body = nil
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
- end.to_env(Faraday::Connection.new("http://localhost"))
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 "should not set Content-Digest if body is empty" do
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
- end.to_env(Faraday::Connection.new("http://localhost"))
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 start_with("EyHmac")
72
- expect(request[:request_headers]).not_to have_key('Content-Digest')
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
- let!(:request) do
88
- Faraday::Request.new.tap do |r|
89
- r.method = :get
90
- r.path = "/auth"
91
- r.body = "{1: 2}"
92
- r.headers = {"Content-Type" => "application/xml"}
93
- end.to_env(Faraday::Connection.new("http://localhost"))
94
- end
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 "should accept a SHA1 signature" do
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 "should accept a SHA256 signature" do # default
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 "should accept multiple digest signatures" do # default
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 "should sign empty request" do
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 = "/resource"
181
- req.body = nil
182
- req.params = {"a" => "1"}
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
@@ -1,4 +1,5 @@
1
1
  require 'spec_helper'
2
+ require 'securerandom'
2
3
 
3
4
  describe "rack" do
4
5
  before(:all) { Bundler.require(:rack) }
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.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: 2014-08-09 00:00:00.000000000 Z
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.2.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:
data/Guardfile DELETED
@@ -1,7 +0,0 @@
1
- guard 'rspec' do
2
- watch(%r{^spec/.+_spec\.rb$})
3
- watch(%r{^spec/(shared|support)/.*\.rb$}) { "spec" }
4
- watch(%r{^lib/(.+)\.rb$}) { "spec" }
5
- watch('spec/spec_helper.rb') { "spec" }
6
- end
7
-