rack-header-key 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rack/header_key.rb +3 -1
- data/lib/rack/header_key/version.rb +1 -1
- data/spec/header_key_spec.rb +6 -1
- metadata +4 -4
data/lib/rack/header_key.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
module Rack
|
2
2
|
class HeaderKey
|
3
3
|
AUTH_HEADER = "X_AUTHORIZATION_KEY".freeze
|
4
|
+
ALT_AUTH_HEADER = "HTTP_X_AUTHORIZATION_KEY".freeze
|
4
5
|
|
5
6
|
def initialize(app, options)
|
6
7
|
@app = app
|
@@ -33,7 +34,8 @@ module Rack
|
|
33
34
|
private
|
34
35
|
|
35
36
|
def token_ok?
|
36
|
-
@request.env[AUTH_HEADER]
|
37
|
+
header_key = @request.env[AUTH_HEADER] || @request.env[ALT_AUTH_HEADER]
|
38
|
+
header_key == @secret
|
37
39
|
end
|
38
40
|
|
39
41
|
def protected_path?
|
data/spec/header_key_spec.rb
CHANGED
@@ -39,7 +39,12 @@ describe "Requests using Rack::HeaderKey" do
|
|
39
39
|
response.should be_allowed
|
40
40
|
end
|
41
41
|
|
42
|
-
it "are
|
42
|
+
it "are allowed if the proper key is present in HTTP_X_AUTHORIZATION_KEY" do
|
43
|
+
response = Rack::MockRequest.new(app).get('/api/test', "HTTP_X_AUTHORIZATION_KEY" => key)
|
44
|
+
response.should be_allowed
|
45
|
+
end
|
46
|
+
|
47
|
+
it "are unauthorized if the proper key is not in X_AUTHORIZATION_KEY" do
|
43
48
|
response = Rack::MockRequest.new(app).get('/api/test', "X_AUTHORIZATION_KEY" => "bogus_key")
|
44
49
|
response.should be_unauthorized
|
45
50
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-header-key
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 4
|
10
|
+
version: 0.0.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Brendon Murphy
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-09-
|
18
|
+
date: 2011-09-06 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|