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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: db868028407a6446871761f00d2344bdaea894f8
4
- data.tar.gz: 6ac7ab349d36f90aa6ab398f72b1c53632a23ef4
3
+ metadata.gz: fabdf9898de29b2dac5ba244f9e96cdd008bb126
4
+ data.tar.gz: 228fef53f920e1d4e08ecca8113f21f21988927b
5
5
  SHA512:
6
- metadata.gz: 91a8b8aa1a81fddaf79f577455a43671b0cdc4dbb0da28c55be29c550695917da42e441905724dd8abf08a20dbdd3b9d490f1d208bc747dcdf4b80308b828114
7
- data.tar.gz: e2927f2c94c822d9220e41ebb71ae76d09ce7c23e6183880061ec9cadb6979f661cd55066ce0c063bc45fce4e1c1dde8677b20ecaa1c4cc94425acd471af1db0
6
+ metadata.gz: 35a0facf321f5acde5224ff62d80cad3401b35563457d965e8029757f0883971317d88360809f8ac32b37e2281d92cdddb759135b3dc5794a4b08651caae33e0
7
+ data.tar.gz: 54859f1e2c700e97ff1443397e0bc560545ff8f80a48eb17d690519a44458629ae3c4738e29947e38b9c40bfa4572fd7df21cda93187db644f96060458cea1fc
@@ -7,18 +7,20 @@ module WP
7
7
  class KeyNotFound < Exception; end
8
8
 
9
9
  class << self
10
- attr_accessor :keys
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) || @keys[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)
@@ -1,5 +1,5 @@
1
1
  module Wp
2
2
  module Hmac
3
- VERSION = '0.2.3'
3
+ VERSION = '0.2.4'
4
4
  end
5
5
  end
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
- context 'with a key configured via a block' do
132
- before do
133
- WP::HMAC.configure do
134
- lookup_auth_key_with { |id| id == 'account2' ? 'mykey' : nil }
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
- it 'looks up the key via the block' do
139
- key = WP::HMAC::KeyCabinet.find_by_auth_id('account2')
140
- expect(key.auth_key).to eq 'mykey'
141
- end
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
- it 'still finds keys from the add_key method' do
144
- key = WP::HMAC::KeyCabinet.find_by_auth_id('esso')
145
- expect(key.auth_key).to eq 'secret_key'
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wp-hmac
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Nagi