lockbox_middleware 1.2.3 → 1.3.0

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.
@@ -5,8 +5,10 @@ require 'auth-hmac'
5
5
  class LockBox
6
6
  include HTTParty
7
7
  include LockBoxCache
8
+ @@config = nil
8
9
 
9
10
  def self.config
11
+ return @@config if @@config
10
12
  if defined?(Rails)
11
13
  root_dir = Rails.root
12
14
  else
@@ -25,7 +27,7 @@ class LockBox
25
27
  return_config = yaml_config[environment]
26
28
  end
27
29
  end
28
- return_config
30
+ @@config = return_config
29
31
  end
30
32
 
31
33
  base_uri config['base_uri']
@@ -87,7 +89,7 @@ class LockBox
87
89
  return {:authorized => cached_auth, :headers => {}}
88
90
  end
89
91
  end
90
- auth_response = self.class.get("/authentication/#{api_key}", {:headers => auth_headers(env)})
92
+ auth_response = self.class.get("/authentication/#{api_key}", {:headers => auth_headers(env), :request => {:application_name => LockBox.config['application_name']}})
91
93
  authorized = (auth_response.code == 200)
92
94
  cache_response_if_allowed(api_key, auth_response) if authorized
93
95
  {:authorized => authorized, :headers => response_headers(auth_response)}
@@ -11,6 +11,10 @@ describe 'LockBox' do
11
11
  end
12
12
 
13
13
  def safely_edit_config_file(settings, env=nil)
14
+ Object.class_eval do
15
+ remove_const LockBox.to_s if const_defined? :LockBox
16
+ end
17
+
14
18
  env ||= Rails.env if defined?(Rails)
15
19
  env ||= ENV['RACK_ENV']
16
20
  env ||= 'test'
@@ -24,6 +28,7 @@ describe 'LockBox' do
24
28
  File.open( @config_file, 'w' ) do |out|
25
29
  YAML.dump( config, out )
26
30
  end
31
+ load 'lib/lockbox_middleware.rb'
27
32
  end
28
33
 
29
34
  context "setting the base_uri" do
@@ -196,13 +201,13 @@ describe 'LockBox' do
196
201
  successful_response.stubs(:headers).returns({'Cache-Control' => 'public, no-cache'})
197
202
  Time.stubs(:now).returns(Time.parse("2010-05-10 16:30:00 EDT"))
198
203
  valid_headers = {'X-Referer-Method' => 'GET', 'X-Referer-Date' => [Time.now.httpdate], 'X-Referer-Authorization' => ['AuthHMAC key-id:uxx+EgyzWBKBgS+Y8MzpcWcfy7k='], 'Referer' => 'http://example.org/api/some_controller/some_action'}
199
- LockBox.stubs(:get).with("/authentication/hmac", {:headers => valid_headers}).returns(successful_response)
204
+ LockBox.stubs(:get).with("/authentication/hmac", {:headers => valid_headers, :request => {:application_name => 'test'}}).returns(successful_response)
200
205
 
201
206
  bad_response = mock("MockResponse")
202
207
  bad_response.stubs(:code).returns(401)
203
208
  bad_response.stubs(:headers).returns({'Cache-Control' => 'public, no-cache'})
204
209
  invalid_headers = {'X-Referer-Method' => 'GET', 'X-Referer-Date' => [Time.now.httpdate], 'X-Referer-Authorization' => 'foo', 'Referer' => 'http://example.org/api/some_controller/some_action'}
205
- LockBox.stubs(:get).with("/authentication/hmac", {:headers => invalid_headers}).returns(bad_response)
210
+ LockBox.stubs(:get).with("/authentication/hmac", {:headers => invalid_headers, :request => {:application_name => 'test'}}).returns(bad_response)
206
211
 
207
212
  @path = "/api/some_controller/some_action"
208
213
 
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lockbox_middleware
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
5
4
  prerelease: false
6
5
  segments:
7
6
  - 1
8
- - 2
9
7
  - 3
10
- version: 1.2.3
8
+ - 0
9
+ version: 1.3.0
11
10
  platform: ruby
12
11
  authors:
13
12
  - Chris Gill
@@ -18,18 +17,16 @@ autorequire:
18
17
  bindir: bin
19
18
  cert_chain: []
20
19
 
21
- date: 2010-07-08 00:00:00 -04:00
20
+ date: 2010-08-05 00:00:00 -04:00
22
21
  default_executable:
23
22
  dependencies:
24
23
  - !ruby/object:Gem::Dependency
25
24
  name: httparty
26
25
  prerelease: false
27
26
  requirement: &id001 !ruby/object:Gem::Requirement
28
- none: false
29
27
  requirements:
30
28
  - - ">="
31
29
  - !ruby/object:Gem::Version
32
- hash: 3
33
30
  segments:
34
31
  - 0
35
32
  version: "0"
@@ -39,11 +36,9 @@ dependencies:
39
36
  name: dnclabs-auth-hmac
40
37
  prerelease: false
41
38
  requirement: &id002 !ruby/object:Gem::Requirement
42
- none: false
43
39
  requirements:
44
40
  - - ">="
45
41
  - !ruby/object:Gem::Version
46
- hash: 3
47
42
  segments:
48
43
  - 0
49
44
  version: "0"
@@ -63,12 +58,6 @@ files:
63
58
  - lib/lockbox_middleware.rb
64
59
  - LICENSE
65
60
  - README.rdoc
66
- - spec/lib/lockbox_cache_spec.rb
67
- - spec/lib/lockbox_middleware_spec.rb
68
- - spec/spec.opts
69
- - spec/spec_helper.rb
70
- - spec/support/helper_methods.rb
71
- - spec/support/mocha.rb
72
61
  has_rdoc: true
73
62
  homepage: http://github.com/dnclabs/lockbox
74
63
  licenses: []
@@ -79,27 +68,23 @@ rdoc_options:
79
68
  require_paths:
80
69
  - lib
81
70
  required_ruby_version: !ruby/object:Gem::Requirement
82
- none: false
83
71
  requirements:
84
72
  - - ">="
85
73
  - !ruby/object:Gem::Version
86
- hash: 3
87
74
  segments:
88
75
  - 0
89
76
  version: "0"
90
77
  required_rubygems_version: !ruby/object:Gem::Requirement
91
- none: false
92
78
  requirements:
93
79
  - - ">="
94
80
  - !ruby/object:Gem::Version
95
- hash: 3
96
81
  segments:
97
82
  - 0
98
83
  version: "0"
99
84
  requirements: []
100
85
 
101
86
  rubyforge_project:
102
- rubygems_version: 1.3.7
87
+ rubygems_version: 1.3.6
103
88
  signing_key:
104
89
  specification_version: 3
105
90
  summary: Rack middleware for the LockBox centralized API authorization service.