ey-hmac 1.0.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4701be0a713277cd0ad6813838340929d9914728
4
- data.tar.gz: 616a0673853d637b92c53c9d2c8d9e68ed820ab7
3
+ metadata.gz: 8dfeeb93b92db1297b05223d6bb2b3e5aebc4baf
4
+ data.tar.gz: 4675e5002ad0686d6a819df058c6768110d442a1
5
5
  SHA512:
6
- metadata.gz: 07abea674ae77af416e7cf69caeab71c8a5e249a8fd2dc073f6f8966096428a4caaa373c904072f5579d28aad798ea9bc32270f5da05654c3b34e63a96be43f7
7
- data.tar.gz: 80c00e2ef84e5c56bf99971eaa2301dde1e1e7811dc94b78f2d38be331c5e8f3b72c438b6b89a5b2f20ebd7c82e5e7c771088d0fcfaf34d2f875f42de4614828
6
+ metadata.gz: 26a224b85612a8f673894612a5e0cc130a2f0dd0bccb0c945611bc2bc30c479b088cd7d19db3425ad09350c63f0c3e6e3b3304195239966dad760deccd8c33a4
7
+ data.tar.gz: b977ba7137c163af67c3c2a4c5eaf49f7f8e1e7ce11e9967fd07f3aa1d39a1e399bfd4aa77af2a7ca62f477803c5fc440e3630dd3ab555bda4dfaf1962433901
data/Gemfile CHANGED
@@ -4,10 +4,10 @@ source 'https://rubygems.org'
4
4
  gemspec
5
5
 
6
6
  group(:test) do
7
- gem 'rb-fsevent'
8
7
  gem 'guard-bundler'
9
- gem 'guard-rspec'
8
+ gem 'guard-rspec', '~> 4.2'
10
9
  gem 'pry-nav'
10
+ gem 'rspec', '~> 2.99'
11
11
  end
12
12
 
13
13
  group(:rack) do
@@ -17,6 +17,5 @@ group(:rack) do
17
17
  end
18
18
 
19
19
  group(:faraday) do
20
- gem 'faraday'
21
- gem 'faraday_middleware', "~> 0.9.0"
20
+ gem 'faraday', '~> 0.9.0'
22
21
  end
@@ -1,17 +1,8 @@
1
1
  require 'ey-hmac'
2
2
  require 'faraday'
3
3
 
4
- if Faraday.respond_to? :register_middleware
5
- Faraday.register_middleware(:request, {:hmac => lambda { Ey::Hmac::Faraday }})
6
- end
7
-
8
- # Request middleware that performs HMAC request signing
9
- require 'faraday_middleware/response_middleware'
10
-
11
- class Ey::Hmac::Faraday < FaradayMiddleware::ResponseMiddleware
12
- dependency do
13
- require 'ey-hmac' unless defined?(Ey::Hmac)
14
- end
4
+ class Ey::Hmac::Faraday < Faraday::Response::Middleware
5
+ dependency("ey-hmac")
15
6
 
16
7
  attr_reader :key_id, :key_secret, :options
17
8
 
@@ -27,4 +18,4 @@ class Ey::Hmac::Faraday < FaradayMiddleware::ResponseMiddleware
27
18
  end
28
19
  end
29
20
 
30
- Faraday::Request.register_middleware(:hmac => lambda { Ey::Hmac::Faraday })
21
+ Faraday::Middleware.register_middleware :hmac => Ey::Hmac::Faraday
@@ -1,5 +1,5 @@
1
1
  module Ey
2
2
  module Hmac
3
- VERSION = "1.0.0"
3
+ VERSION = "2.0.0"
4
4
  end
5
5
  end
data/spec/faraday_spec.rb CHANGED
@@ -18,19 +18,19 @@ describe "faraday" do
18
18
 
19
19
  Ey::Hmac.sign!(request, key_id, key_secret, adapter: adapter)
20
20
 
21
- request[:request_headers]['Authorization'].should start_with("EyHmac")
22
- request[:request_headers]['Content-Digest'].should == Digest::MD5.hexdigest(request[:body])
23
- Time.parse(request[:request_headers]['Date']).should_not be_nil
21
+ expect(request[:request_headers]['Authorization']).to start_with("EyHmac")
22
+ expect(request[:request_headers]['Content-Digest']).to eq(Digest::MD5.hexdigest(request[:body]))
23
+ expect(Time.parse(request[:request_headers]['Date'])).not_to be_nil
24
24
 
25
25
  yielded = false
26
26
 
27
- Ey::Hmac.authenticated?(request, adapter: adapter) do |key_id|
28
- key_id.should == key_id
27
+ expect(Ey::Hmac.authenticated?(request, adapter: adapter) do |key_id|
28
+ expect(key_id).to eq(key_id)
29
29
  yielded = true
30
30
  key_secret
31
- end.should be_true
31
+ end).to be_truthy
32
32
 
33
- yielded.should be_true
33
+ expect(yielded).to be_truthy
34
34
  end
35
35
 
36
36
  it "should not set Content-Digest if body is nil" do
@@ -43,19 +43,19 @@ describe "faraday" do
43
43
 
44
44
  Ey::Hmac.sign!(request, key_id, key_secret, adapter: adapter)
45
45
 
46
- request[:request_headers]['Authorization'].should start_with("EyHmac")
47
- request[:request_headers].should_not have_key('Content-Digest')
48
- Time.parse(request[:request_headers]['Date']).should_not be_nil
46
+ expect(request[:request_headers]['Authorization']).to start_with("EyHmac")
47
+ expect(request[:request_headers]).not_to have_key('Content-Digest')
48
+ expect(Time.parse(request[:request_headers]['Date'])).not_to be_nil
49
49
 
50
50
  yielded = false
51
51
 
52
- Ey::Hmac.authenticated?(request, adapter: adapter) do |key_id|
53
- key_id.should == key_id
52
+ expect(Ey::Hmac.authenticated?(request, adapter: adapter) do |key_id|
53
+ expect(key_id).to eq(key_id)
54
54
  yielded = true
55
55
  key_secret
56
- end.should be_true
56
+ end).to be_truthy
57
57
 
58
- yielded.should be_true
58
+ expect(yielded).to be_truthy
59
59
  end
60
60
 
61
61
  it "should not set Content-Digest if body is empty" do
@@ -68,19 +68,19 @@ describe "faraday" do
68
68
 
69
69
  Ey::Hmac.sign!(request, key_id, key_secret, adapter: adapter)
70
70
 
71
- request[:request_headers]['Authorization'].should start_with("EyHmac")
72
- request[:request_headers].should_not have_key('Content-Digest')
73
- Time.parse(request[:request_headers]['Date']).should_not be_nil
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
74
74
 
75
75
  yielded = false
76
76
 
77
- Ey::Hmac.authenticated?(request, adapter: adapter) do |key_id|
78
- key_id.should == key_id
77
+ expect(Ey::Hmac.authenticated?(request, adapter: adapter) do |key_id|
78
+ expect(key_id).to eq(key_id)
79
79
  yielded = true
80
80
  key_secret
81
- end.should be_true
81
+ end).to be_truthy
82
82
 
83
- yielded.should be_true
83
+ expect(yielded).to be_truthy
84
84
  end
85
85
 
86
86
  context "with a request" do
@@ -108,13 +108,12 @@ describe "faraday" do
108
108
  [(authenticated ? 200 : 401), {"Content-Type" => "text/plain"}, []]
109
109
  end
110
110
 
111
- request_env = nil
112
111
  connection = Faraday.new do |c|
113
- c.request :hmac, key_id, key_secret, sign_with: :sha1
112
+ c.use :hmac, key_id, key_secret, sign_with: :sha1
114
113
  c.adapter(:rack, app)
115
114
  end
116
115
 
117
- connection.get("/resources").status.should == 200
116
+ expect(connection.get("/resources").status).to eq(200)
118
117
  end
119
118
 
120
119
  it "should accept a SHA256 signature" do # default
@@ -128,13 +127,12 @@ describe "faraday" do
128
127
  [(authenticated ? 200 : 401), {"Content-Type" => "text/plain"}, []]
129
128
  end
130
129
 
131
- request_env = nil
132
130
  connection = Faraday.new do |c|
133
- c.request :hmac, key_id, key_secret
131
+ c.use :hmac, key_id, key_secret
134
132
  c.adapter(:rack, app)
135
133
  end
136
134
 
137
- connection.get("/resources").status.should == 200
135
+ expect(connection.get("/resources").status).to eq(200)
138
136
  end
139
137
 
140
138
  it "should accept multiple digest signatures" do # default
@@ -148,13 +146,12 @@ describe "faraday" do
148
146
  [(authenticated ? 200 : 401), {"Content-Type" => "text/plain"}, []]
149
147
  end
150
148
 
151
- request_env = nil
152
149
  connection = Faraday.new do |c|
153
- c.request :hmac, key_id, key_secret
150
+ c.use :hmac, key_id, key_secret
154
151
  c.adapter(:rack, app)
155
152
  end
156
153
 
157
- connection.get("/resources").status.should == 200
154
+ expect(connection.get("/resources").status).to eq(200)
158
155
  end
159
156
 
160
157
  it "should sign empty request" do
@@ -174,18 +171,17 @@ describe "faraday" do
174
171
  })
175
172
  end
176
173
 
177
- request_env = nil
178
174
  connection = Faraday.new do |c|
179
- c.request :hmac, key_id, key_secret
175
+ c.use :hmac, key_id, key_secret
180
176
  c.adapter(:rack, app)
181
177
  end
182
178
 
183
- connection.get do |req|
179
+ expect(connection.get do |req|
184
180
  req.path = "/resource"
185
181
  req.body = nil
186
182
  req.params = {"a" => "1"}
187
183
  req.headers = {"Content-Type" => "application/x-www-form-urlencoded"}
188
- end.status.should == 200
184
+ end.status).to eq(200)
189
185
  end
190
186
  end
191
187
  end
data/spec/rack_spec.rb CHANGED
@@ -16,19 +16,19 @@ describe "rack" do
16
16
  )
17
17
  Ey::Hmac.sign!(request, key_id, key_secret, adapter: adapter)
18
18
 
19
- request.env['HTTP_AUTHORIZATION'].should start_with("EyHmac")
20
- request.env['HTTP_CONTENT_DIGEST'].should == Digest::MD5.hexdigest(request.body.tap(&:rewind).read)
21
- Time.parse(request.env['HTTP_DATE']).should_not be_nil
19
+ expect(request.env['HTTP_AUTHORIZATION']).to start_with("EyHmac")
20
+ expect(request.env['HTTP_CONTENT_DIGEST']).to eq(Digest::MD5.hexdigest(request.body.tap(&:rewind).read))
21
+ expect(Time.parse(request.env['HTTP_DATE'])).not_to be_nil
22
22
 
23
23
  yielded = false
24
24
 
25
- Ey::Hmac.authenticated?(request, adapter: adapter) do |key_id|
26
- key_id.should == key_id
25
+ expect(Ey::Hmac.authenticated?(request, adapter: adapter) do |key_id|
26
+ expect(key_id).to eq(key_id)
27
27
  yielded = true
28
28
  key_secret
29
- end.should be_true
29
+ end).to be_truthy
30
30
 
31
- yielded.should be_true
31
+ expect(yielded).to be_truthy
32
32
  end
33
33
 
34
34
  it "should not set Content-Digest if body is nil" do
@@ -38,19 +38,19 @@ describe "rack" do
38
38
 
39
39
  Ey::Hmac.sign!(request, key_id, key_secret, adapter: adapter)
40
40
 
41
- request.env['HTTP_AUTHORIZATION'].should start_with("EyHmac")
42
- request.env.should_not have_key('HTTP_CONTENT_DIGEST')
43
- Time.parse(request.env['HTTP_DATE']).should_not be_nil
41
+ expect(request.env['HTTP_AUTHORIZATION']).to start_with("EyHmac")
42
+ expect(request.env).not_to have_key('HTTP_CONTENT_DIGEST')
43
+ expect(Time.parse(request.env['HTTP_DATE'])).not_to be_nil
44
44
 
45
45
  yielded = false
46
46
 
47
- Ey::Hmac.authenticated?(request, adapter: adapter) do |key_id|
48
- key_id.should == key_id
47
+ expect(Ey::Hmac.authenticated?(request, adapter: adapter) do |key_id|
48
+ expect(key_id).to eq(key_id)
49
49
  yielded = true
50
50
  key_secret
51
- end.should be_true
51
+ end).to be_truthy
52
52
 
53
- yielded.should be_true
53
+ expect(yielded).to be_truthy
54
54
  end
55
55
 
56
56
  it "should not set Content-Digest if body is empty" do
@@ -61,19 +61,19 @@ describe "rack" do
61
61
 
62
62
  Ey::Hmac.sign!(request, key_id, key_secret, adapter: adapter)
63
63
 
64
- request.env['HTTP_AUTHORIZATION'].should start_with("EyHmac")
65
- request.env.should_not have_key('HTTP_CONTENT_DIGEST')
66
- Time.parse(request.env['HTTP_DATE']).should_not be_nil
64
+ expect(request.env['HTTP_AUTHORIZATION']).to start_with("EyHmac")
65
+ expect(request.env).not_to have_key('HTTP_CONTENT_DIGEST')
66
+ expect(Time.parse(request.env['HTTP_DATE'])).not_to be_nil
67
67
 
68
68
  yielded = false
69
69
 
70
- Ey::Hmac.authenticated?(request, adapter: adapter) do |key_id|
71
- key_id.should == key_id
70
+ expect(Ey::Hmac.authenticated?(request, adapter: adapter) do |key_id|
71
+ expect(key_id).to eq(key_id)
72
72
  yielded = true
73
73
  key_secret
74
- end.should be_true
74
+ end).to be_truthy
75
75
 
76
- yielded.should be_true
76
+ expect(yielded).to be_truthy
77
77
  end
78
78
 
79
79
  context "with a request" do
@@ -103,7 +103,7 @@ describe "rack" do
103
103
  run app
104
104
  end
105
105
 
106
- client.get("/resource").status.should == 200
106
+ expect(client.get("/resource").status).to eq(200)
107
107
  end
108
108
 
109
109
  it "should accept a SHA256 signature" do # default
@@ -120,7 +120,7 @@ describe "rack" do
120
120
  run app
121
121
  end
122
122
 
123
- client.get("/resource").status.should == 200
123
+ expect(client.get("/resource").status).to eq(200)
124
124
  end
125
125
 
126
126
  it "should accept multiple digest signatures" do # default
@@ -134,13 +134,12 @@ describe "rack" do
134
134
  [(authenticated ? 200 : 401), {"Content-Type" => "text/plain"}, []]
135
135
  end
136
136
 
137
- request_env = nil
138
137
  connection = Faraday.new do |c|
139
- c.request :hmac, key_id, key_secret, digest: [:sha1, :sha256]
138
+ c.use :hmac, key_id, key_secret, digest: [:sha1, :sha256]
140
139
  c.adapter(:rack, app)
141
140
  end
142
141
 
143
- connection.get("/resources").status.should == 200
142
+ expect(connection.get("/resources").status).to eq(200)
144
143
  end
145
144
  end
146
145
  end
@@ -3,23 +3,23 @@ shared_examples_for "authentication" do
3
3
  it "should not authenticate invalid secret" do
4
4
  Ey::Hmac.sign!(request, key_id, "#{key_secret}bad", adapter: adapter)
5
5
 
6
- Ey::Hmac.authenticated?(request, adapter: adapter) do |auth_id|
6
+ expect(Ey::Hmac.authenticated?(request, adapter: adapter) do |auth_id|
7
7
  (auth_id == key_id) && key_secret
8
- end.should be_false
8
+ end).to be_falsey
9
9
  end
10
10
 
11
11
  it "should not authenticate invalid id" do
12
12
  Ey::Hmac.sign!(request, "what#{key_id}", key_secret, adapter: adapter)
13
13
 
14
- Ey::Hmac.authenticated?(request, adapter: adapter) do |auth_id|
14
+ expect(Ey::Hmac.authenticated?(request, adapter: adapter) do |auth_id|
15
15
  (auth_id == key_id) && key_secret
16
- end.should be_false
16
+ end).to be_falsey
17
17
  end
18
18
 
19
19
  it "should not authenticate missing header" do
20
- Ey::Hmac.authenticated?(request, adapter: adapter) do |auth_id|
20
+ expect(Ey::Hmac.authenticated?(request, adapter: adapter) do |auth_id|
21
21
  (auth_id == key_id) && key_secret
22
- end.should be_false
22
+ end).to be_falsey
23
23
  end
24
24
  end
25
25
 
@@ -27,29 +27,29 @@ shared_examples_for "authentication" do
27
27
  it "should not authenticate invalid secret" do
28
28
  Ey::Hmac.sign!(request, key_id, "#{key_secret}bad", adapter: adapter)
29
29
 
30
- lambda {
30
+ expect {
31
31
  Ey::Hmac.authenticate!(request, adapter: adapter) do |auth_id|
32
32
  (auth_id == key_id) && key_secret
33
33
  end
34
- }.should raise_exception(Ey::Hmac::SignatureMismatch)
34
+ }.to raise_exception(Ey::Hmac::SignatureMismatch)
35
35
  end
36
36
 
37
37
  it "should not authenticate invalid id" do
38
38
  Ey::Hmac.sign!(request, "what#{key_id}", key_secret, adapter: adapter)
39
39
 
40
- lambda {
40
+ expect {
41
41
  Ey::Hmac.authenticate!(request, adapter: adapter) do |auth_id|
42
42
  (auth_id == key_id) && key_secret
43
43
  end
44
- }.should raise_exception(Ey::Hmac::MissingSecret)
44
+ }.to raise_exception(Ey::Hmac::MissingSecret)
45
45
  end
46
46
 
47
47
  it "should not authenticate missing header" do
48
- lambda {
49
- Ey::Hmac.authenticate!(request, adapter: adapter) do |auth_id|
48
+ expect {
49
+ expect(Ey::Hmac.authenticate!(request, adapter: adapter) do |auth_id|
50
50
  (auth_id == key_id) && key_secret
51
- end.should be_false
52
- }.should raise_exception(Ey::Hmac::MissingAuthorization)
51
+ end).to be_falsey
52
+ }.to raise_exception(Ey::Hmac::MissingAuthorization)
53
53
  end
54
54
  end
55
55
  end
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: 1.0.0
4
+ version: 2.0.0
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-04-29 00:00:00.000000000 Z
11
+ date: 2014-08-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake