rack-header-key 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rack/header_key/version.rb +1 -1
- data/spec/header_key_spec.rb +25 -15
- metadata +3 -3
data/spec/header_key_spec.rb
CHANGED
@@ -1,6 +1,19 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
|
3
|
+
RSpec::Matchers.define :be_allowed do
|
4
|
+
match do |response|
|
5
|
+
response.status.should == 200
|
6
|
+
response.body.should == "success"
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
RSpec::Matchers.define :be_unauthorized do
|
11
|
+
match do |response|
|
12
|
+
response.status.should == 401
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "Requests using Rack::HeaderKey" do
|
4
17
|
let(:key) { "sekret" }
|
5
18
|
let(:app) {
|
6
19
|
Rack::Builder.new do
|
@@ -9,7 +22,7 @@ describe Rack::HeaderKey do
|
|
9
22
|
end
|
10
23
|
}
|
11
24
|
|
12
|
-
it "
|
25
|
+
it "raise an argument error if the initialization path option doesn't start with /" do
|
13
26
|
app = Rack::Builder.new do
|
14
27
|
use Rack::HeaderKey, :key => "sekret", :path => "bad_path"
|
15
28
|
run lambda { |env| [200, {'Content-Type' => "text/plain"}, ["success"]]}
|
@@ -21,40 +34,37 @@ describe Rack::HeaderKey do
|
|
21
34
|
end
|
22
35
|
|
23
36
|
context "for the protected path" do
|
24
|
-
it "
|
37
|
+
it "are allowed if the proper key is present in X_AUTHORIZATION_KEY" do
|
25
38
|
response = Rack::MockRequest.new(app).get('/api/test', "X_AUTHORIZATION_KEY" => key)
|
26
|
-
response.
|
27
|
-
response.body.should == "success"
|
39
|
+
response.should be_allowed
|
28
40
|
end
|
29
41
|
|
30
|
-
it "
|
42
|
+
it "are unauthorized if the the proper key is not in X_AUTHORIZATION_KEY" do
|
31
43
|
response = Rack::MockRequest.new(app).get('/api/test', "X_AUTHORIZATION_KEY" => "bogus_key")
|
32
|
-
response.
|
44
|
+
response.should be_unauthorized
|
33
45
|
end
|
34
46
|
end
|
35
47
|
|
36
48
|
context "for an unprotected path" do
|
37
|
-
it "
|
49
|
+
it "are allowed when no key is given" do
|
38
50
|
response = Rack::MockRequest.new(app).get('/test')
|
39
|
-
response.
|
40
|
-
response.body.should == "success"
|
51
|
+
response.should be_allowed
|
41
52
|
end
|
42
53
|
|
43
|
-
it "
|
54
|
+
it "are allowed even if an improper key is given" do
|
44
55
|
response = Rack::MockRequest.new(app).get('/test', "X_AUTHORIZATION_KEY" => "bogus_key")
|
45
|
-
response.
|
46
|
-
response.body.should == "success"
|
56
|
+
response.should be_allowed
|
47
57
|
end
|
48
58
|
end
|
49
59
|
|
50
60
|
context "when no path is given" do
|
51
|
-
it "
|
61
|
+
it "the root path is protected" do
|
52
62
|
app = Rack::Builder.new do
|
53
63
|
use Rack::HeaderKey, :key => "sekret"
|
54
64
|
run lambda { |env| [200, {'Content-Type' => "text/plain"}, ["success"]]}
|
55
65
|
end
|
56
66
|
response = Rack::MockRequest.new(app).get('/test', "X_AUTHORIZATION_KEY" => "bogus_key")
|
57
|
-
response.
|
67
|
+
response.should be_unauthorized
|
58
68
|
end
|
59
69
|
end
|
60
70
|
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: 27
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Brendon Murphy
|