ey_api_hmac 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ey_api_hmac (0.0.5)
4
+ ey_api_hmac (0.0.6.pre)
5
5
  json
6
6
  rack-client
7
7
 
@@ -54,12 +54,19 @@ module EY
54
54
 
55
55
  # Client middleware that's used to add authentication to requests.
56
56
  class Client
57
+ class AuthFailure < RuntimeError
58
+ end
59
+
57
60
  def initialize(app, auth_id, auth_key)
58
61
  @app, @auth_id, @auth_key = app, auth_id, auth_key
59
62
  end
60
63
  def call(env)
61
64
  ApiHMAC.sign!(env, @auth_id, @auth_key)
62
- @app.call(env)
65
+ tuple = @app.call(env)
66
+ if tuple.first.to_i == 401
67
+ raise AuthFailure, "HMAC Authentication Failed."
68
+ end
69
+ tuple
63
70
  end
64
71
  end
65
72
 
@@ -1,5 +1,5 @@
1
1
  module EY
2
2
  module ApiHMAC
3
- VERSION = "0.0.5"
3
+ VERSION = "0.0.6"
4
4
  end
5
5
  end
@@ -112,6 +112,7 @@ describe EY::ApiHMAC::ApiAuth do
112
112
  run MockApp.call(true, 'key')
113
113
  end
114
114
 
115
+ # no HMAC client means no nice exception for 401s
115
116
  response = client.get('/')
116
117
  response.status.should == 401
117
118
  response.body.should_not == 'Success'
@@ -134,9 +135,7 @@ describe EY::ApiHMAC::ApiAuth do
134
135
 
135
136
  client = hmac_client('wrongkey', MockApp.call(is_found, 'rightkey'))
136
137
 
137
- response = client.get('/')
138
- response.status.should == 401
139
- response.body.should_not == 'Success'
138
+ lambda { client.get('/') }.should raise_error(EY::ApiHMAC::ApiAuth::Client::AuthFailure)
140
139
  end
141
140
 
142
141
  it "fails when no consumer by that auth_id is found" do
@@ -146,9 +145,7 @@ describe EY::ApiHMAC::ApiAuth do
146
145
 
147
146
  client = hmac_client(auth_key, MockApp.call(is_found, auth_key))
148
147
 
149
- response = client.get('/')
150
- response.status.should == 401
151
- response.body.should_not == 'Success'
148
+ lambda { client.get('/') }.should raise_error(EY::ApiHMAC::ApiAuth::Client::AuthFailure)
152
149
  end
153
150
  end
154
151
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ey_api_hmac
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 5
10
- version: 0.0.5
9
+ - 6
10
+ version: 0.0.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - "Jacob Burkhart & Thorben Schr\xC3\xB6der & David Calavera & others"