rack-header-key 0.0.1 → 0.0.2

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.
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  module HeaderKey
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
@@ -1,6 +1,19 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Rack::HeaderKey do
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 "raises an argument error if given a path option that doesn't start with /" do
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 "returns 200 if the proper key is present in X_AUTHORIZATION_KEY" do
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.status.should == 200
27
- response.body.should == "success"
39
+ response.should be_allowed
28
40
  end
29
41
 
30
- it "returns 401 if the the proper key is not in X_AUTHORIZATION_KEY" do
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.status.should == 401
44
+ response.should be_unauthorized
33
45
  end
34
46
  end
35
47
 
36
48
  context "for an unprotected path" do
37
- it "returns 200 when no key is given" do
49
+ it "are allowed when no key is given" do
38
50
  response = Rack::MockRequest.new(app).get('/test')
39
- response.status.should == 200
40
- response.body.should == "success"
51
+ response.should be_allowed
41
52
  end
42
53
 
43
- it "returns 200 even if an improper key is given" do
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.status.should == 200
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 "protects the root path" do
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.status.should == 401
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: 29
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Brendon Murphy