wp-hmac 0.2.3 → 0.2.4
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 +4 -4
- data/lib/wp/hmac/key_cabinet.rb +6 -4
- data/lib/wp/hmac/version.rb +1 -1
- data/spec/hmac_spec.rb +23 -27
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fabdf9898de29b2dac5ba244f9e96cdd008bb126
|
4
|
+
data.tar.gz: 228fef53f920e1d4e08ecca8113f21f21988927b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 35a0facf321f5acde5224ff62d80cad3401b35563457d965e8029757f0883971317d88360809f8ac32b37e2281d92cdddb759135b3dc5794a4b08651caae33e0
|
7
|
+
data.tar.gz: 54859f1e2c700e97ff1443397e0bc560545ff8f80a48eb17d690519a44458629ae3c4738e29947e38b9c40bfa4572fd7df21cda93187db644f96060458cea1fc
|
data/lib/wp/hmac/key_cabinet.rb
CHANGED
@@ -7,18 +7,20 @@ module WP
|
|
7
7
|
class KeyNotFound < Exception; end
|
8
8
|
|
9
9
|
class << self
|
10
|
-
|
11
|
-
attr_writer :lookup_block
|
10
|
+
attr_writer :lookup_block, :keys
|
12
11
|
|
13
12
|
def add_key(id:, auth_key:)
|
13
|
+
keys[id] = { id: id, auth_key: auth_key }
|
14
|
+
end
|
15
|
+
|
16
|
+
def keys
|
14
17
|
@keys ||= {}
|
15
|
-
@keys[id] = { id: id, auth_key: auth_key }
|
16
18
|
end
|
17
19
|
|
18
20
|
# This method will be called by EY::ApiHMAC. It must return
|
19
21
|
# an object that responds to +id+ and +auth_key+
|
20
22
|
def find_by_auth_id(id)
|
21
|
-
hash = lookup(id) ||
|
23
|
+
hash = lookup(id) || keys[id]
|
22
24
|
msg = 'Ensure secret keys are loaded with `HMAC::KeyCabinet.add_key`'
|
23
25
|
fail KeyNotFound, msg if hash.nil?
|
24
26
|
OpenStruct.new(hash)
|
data/lib/wp/hmac/version.rb
CHANGED
data/spec/hmac_spec.rb
CHANGED
@@ -23,38 +23,27 @@ end
|
|
23
23
|
|
24
24
|
RSpec.describe WP::HMAC, type: :request do
|
25
25
|
let(:app) { App::Application }
|
26
|
+
let(:hmac_client) { WP::HMAC::Client.new(nil) }
|
26
27
|
|
27
28
|
before(:example) do
|
28
29
|
WP::HMAC.configure do
|
29
|
-
add_key(id: 'esso', auth_key: 'secret_key')
|
30
30
|
add_hmac_enabled_route %r{^/dummy/}
|
31
31
|
get_auth_id_for_request -> { 'esso' }
|
32
32
|
end
|
33
33
|
|
34
34
|
WP::HMAC::Client.rack_app = app
|
35
|
-
end
|
36
|
-
|
37
|
-
after(:example) do
|
38
|
-
WP::HMAC.reset
|
39
|
-
end
|
40
35
|
|
41
|
-
let(:hmac_client) { WP::HMAC::Client.new(nil) }
|
42
|
-
|
43
|
-
before do
|
44
36
|
Rails.application.routes.draw do
|
45
37
|
resources :dummy
|
46
38
|
end
|
47
39
|
end
|
48
40
|
|
49
|
-
after do
|
41
|
+
after(:example) do
|
42
|
+
WP::HMAC.reset
|
50
43
|
Rails.application.reload_routes!
|
51
44
|
end
|
52
45
|
|
53
46
|
context 'with no key' do
|
54
|
-
before(:each) do
|
55
|
-
WP::HMAC::KeyCabinet.instance_eval('@keys = {}')
|
56
|
-
end
|
57
|
-
|
58
47
|
context 'when hmac is enabled for the route' do
|
59
48
|
it 'raises an exception' do
|
60
49
|
expect do
|
@@ -73,6 +62,13 @@ RSpec.describe WP::HMAC, type: :request do
|
|
73
62
|
end
|
74
63
|
|
75
64
|
context 'with a key cabinet' do
|
65
|
+
|
66
|
+
before(:example) do
|
67
|
+
WP::HMAC.configure do
|
68
|
+
add_key(id: 'esso', auth_key: 'secret_key')
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
76
72
|
it 'fails when a request is not signed' do
|
77
73
|
get 'http://esso.example.org/dummy/1'
|
78
74
|
|
@@ -126,23 +122,23 @@ RSpec.describe WP::HMAC, type: :request do
|
|
126
122
|
|
127
123
|
expect(rack_response.body).to include('Hello, updated world!')
|
128
124
|
end
|
129
|
-
end
|
130
125
|
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
126
|
+
context 'with a key configured via a block' do
|
127
|
+
before do
|
128
|
+
WP::HMAC.configure do
|
129
|
+
lookup_auth_key_with { |id| id == 'account2' ? 'mykey' : nil }
|
130
|
+
end
|
135
131
|
end
|
136
|
-
end
|
137
132
|
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
133
|
+
it 'looks up the key via the block' do
|
134
|
+
key = WP::HMAC::KeyCabinet.find_by_auth_id('account2')
|
135
|
+
expect(key.auth_key).to eq 'mykey'
|
136
|
+
end
|
142
137
|
|
143
|
-
|
144
|
-
|
145
|
-
|
138
|
+
it 'still finds keys from the add_key method' do
|
139
|
+
key = WP::HMAC::KeyCabinet.find_by_auth_id('esso')
|
140
|
+
expect(key.auth_key).to eq 'secret_key'
|
141
|
+
end
|
146
142
|
end
|
147
143
|
end
|
148
144
|
end
|