rack_csrf 2.3.0 → 2.4.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.
- data/Changelog.md +13 -0
- data/Gemfile +12 -0
- data/LICENSE.rdoc +1 -1
- data/README.rdoc +61 -1
- data/Rakefile +11 -7
- data/VERSION +1 -1
- data/examples/cuba/Gemfile +1 -1
- data/examples/innate/Gemfile +1 -1
- data/examples/rack/Gemfile +1 -1
- data/examples/sinatra/Gemfile +1 -1
- data/features/check_only_some_specific_requests.feature +22 -0
- data/features/custom_http_methods.feature +46 -0
- data/features/empty_responses.feature +47 -0
- data/features/inspecting_also_get_requests.feature +14 -0
- data/features/raising_exception.feature +27 -0
- data/features/skip_if_block_passes.feature +40 -0
- data/features/skip_some_routes.feature +3 -3
- data/features/step_definitions/request_steps.rb +39 -7
- data/features/step_definitions/setup_steps.rb +56 -14
- data/features/variation_on_header_name.feature +35 -0
- data/lib/rack/csrf.rb +40 -13
- data/rack_csrf.gemspec +16 -7
- data/spec/csrf_spec.rb +105 -59
- metadata +57 -24
data/spec/csrf_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Rack::Csrf do
|
4
4
|
describe 'key' do
|
@@ -7,8 +7,7 @@ describe Rack::Csrf do
|
|
7
7
|
end
|
8
8
|
|
9
9
|
it "should be the value of the :key option" do
|
10
|
-
|
11
|
-
Rack::Csrf.new fakeapp, :key => 'whatever'
|
10
|
+
Rack::Csrf.new nil, :key => 'whatever'
|
12
11
|
Rack::Csrf.key.should == 'whatever'
|
13
12
|
end
|
14
13
|
end
|
@@ -25,8 +24,7 @@ describe Rack::Csrf do
|
|
25
24
|
end
|
26
25
|
|
27
26
|
it "should be the value of :field option" do
|
28
|
-
|
29
|
-
Rack::Csrf.new fakeapp, :field => 'whatever'
|
27
|
+
Rack::Csrf.new nil, :field => 'whatever'
|
30
28
|
Rack::Csrf.field.should == 'whatever'
|
31
29
|
end
|
32
30
|
end
|
@@ -37,6 +35,22 @@ describe Rack::Csrf do
|
|
37
35
|
end
|
38
36
|
end
|
39
37
|
|
38
|
+
describe 'header' do
|
39
|
+
subject { Rack::Csrf.header }
|
40
|
+
it { should == 'X_CSRF_TOKEN' }
|
41
|
+
|
42
|
+
context "when set to something" do
|
43
|
+
before { Rack::Csrf.new nil, :header => 'something' }
|
44
|
+
subject { Rack::Csrf.header }
|
45
|
+
it { should == 'something' }
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe 'csrf_header' do
|
50
|
+
subject { Rack::Csrf.method(:csrf_header) }
|
51
|
+
it { should == Rack::Csrf.method(:header) }
|
52
|
+
end
|
53
|
+
|
40
54
|
describe 'token(env)' do
|
41
55
|
let(:env) { {'rack.session' => {}} }
|
42
56
|
|
@@ -44,8 +58,7 @@ describe Rack::Csrf do
|
|
44
58
|
|
45
59
|
context 'when accessing/manipulating the session' do
|
46
60
|
before do
|
47
|
-
|
48
|
-
Rack::Csrf.new fakeapp, :key => 'whatever'
|
61
|
+
Rack::Csrf.new nil, :key => 'whatever'
|
49
62
|
end
|
50
63
|
|
51
64
|
it 'should use the key provided by method key' do
|
@@ -84,8 +97,7 @@ describe Rack::Csrf do
|
|
84
97
|
let(:env) { {'rack.session' => {}} }
|
85
98
|
|
86
99
|
let :tag do
|
87
|
-
|
88
|
-
Rack::Csrf.new fakeapp, :field => 'whatever'
|
100
|
+
Rack::Csrf.new nil, :field => 'whatever'
|
89
101
|
Rack::Csrf.tag env
|
90
102
|
end
|
91
103
|
|
@@ -113,78 +125,112 @@ describe Rack::Csrf do
|
|
113
125
|
end
|
114
126
|
end
|
115
127
|
|
116
|
-
describe '
|
117
|
-
|
118
|
-
attr_accessor :path_info, :request_method
|
119
|
-
end
|
120
|
-
|
121
|
-
before :each do
|
122
|
-
@request = MockReq.new
|
123
|
-
@request.path_info = '/hello'
|
124
|
-
@request.request_method = 'POST'
|
125
|
-
end
|
128
|
+
describe 'metatag(env)' do
|
129
|
+
let(:env) { {'rack.session' => {}} }
|
126
130
|
|
127
|
-
context '
|
128
|
-
let
|
131
|
+
context 'by default' do
|
132
|
+
let :metatag do
|
133
|
+
Rack::Csrf.new nil, :header => 'whatever'
|
134
|
+
Rack::Csrf.metatag env
|
135
|
+
end
|
129
136
|
|
130
|
-
|
131
|
-
|
137
|
+
subject { metatag }
|
138
|
+
it { should =~ /^<meta/ }
|
139
|
+
it { should =~ /name="_csrf"/ }
|
140
|
+
it "should have the content provided by method token(env)" do
|
141
|
+
quoted_value = Regexp.quote %Q(content="#{Rack::Csrf.token(env)}")
|
142
|
+
metatag.should =~ /#{quoted_value}/
|
132
143
|
end
|
133
144
|
end
|
134
145
|
|
135
|
-
context 'with
|
136
|
-
let
|
137
|
-
|
138
|
-
|
139
|
-
csrf.send(:skip_checking, @request).should be_true
|
146
|
+
context 'with custom name' do
|
147
|
+
let :metatag do
|
148
|
+
Rack::Csrf.new nil, :header => 'whatever'
|
149
|
+
Rack::Csrf.metatag env, :name => 'custom_name'
|
140
150
|
end
|
141
151
|
|
142
|
-
|
143
|
-
|
144
|
-
|
152
|
+
subject { metatag }
|
153
|
+
it { should =~ /^<meta/ }
|
154
|
+
it { should =~ /name="custom_name"/ }
|
155
|
+
it "should have the content provided by method token(env)" do
|
156
|
+
quoted_value = Regexp.quote %Q(content="#{Rack::Csrf.token(env)}")
|
157
|
+
metatag.should =~ /#{quoted_value}/
|
145
158
|
end
|
146
159
|
end
|
160
|
+
end
|
161
|
+
|
162
|
+
describe 'csrf_metatag(env)' do
|
163
|
+
it 'should be the same as method metatag(env)' do
|
164
|
+
Rack::Csrf.method(:csrf_metatag).should == Rack::Csrf.method(:metatag)
|
165
|
+
end
|
166
|
+
end
|
147
167
|
|
148
|
-
|
149
|
-
let(:csrf) { Rack::Csrf.new nil, :check_only => ['POST:/hello'] }
|
168
|
+
# Protected/private API
|
150
169
|
|
151
|
-
|
152
|
-
|
153
|
-
|
170
|
+
describe 'rackified_header' do
|
171
|
+
before { Rack::Csrf.new nil, :header => 'my-header' }
|
172
|
+
subject { Rack::Csrf.rackified_header }
|
173
|
+
it { should == 'HTTP_MY_HEADER'}
|
174
|
+
end
|
154
175
|
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
176
|
+
describe 'skip_checking' do
|
177
|
+
let :request do
|
178
|
+
double 'Request',
|
179
|
+
:path_info => '/hello',
|
180
|
+
:request_method => 'POST',
|
181
|
+
:env => {'HTTP_X_VERY_SPECIAL_HEADER' => 'so true'}
|
159
182
|
end
|
160
183
|
|
161
|
-
context '
|
162
|
-
let
|
163
|
-
Rack::Csrf.new nil,
|
164
|
-
:skip => ['POST:/hello'],
|
165
|
-
:check_only => ['POST:/byebye']
|
166
|
-
end
|
184
|
+
context 'when the lists are empty and there is no custom check' do
|
185
|
+
let(:csrf) { Rack::Csrf.new nil }
|
167
186
|
|
168
|
-
it 'should
|
169
|
-
csrf.send(:skip_checking,
|
187
|
+
it 'should run the check' do
|
188
|
+
csrf.send(:skip_checking, request).should be_false
|
170
189
|
end
|
190
|
+
end
|
191
|
+
|
192
|
+
context 'when the request is included in the :skip list' do
|
193
|
+
let(:csrf) { Rack::Csrf.new nil, :skip => ['POST:/hello'] }
|
171
194
|
|
172
|
-
it 'should run the check
|
173
|
-
|
174
|
-
csrf.send(:skip_checking, @request).should be_false
|
195
|
+
it 'should not run the check' do
|
196
|
+
csrf.send(:skip_checking, request).should be_true
|
175
197
|
end
|
176
198
|
end
|
177
199
|
|
178
|
-
context '
|
179
|
-
|
180
|
-
Rack::Csrf.new nil,
|
181
|
-
|
182
|
-
|
200
|
+
context 'when the request is not included in the :skip list' do
|
201
|
+
context 'but the request satisfies the custom check' do
|
202
|
+
let(:csrf) { Rack::Csrf.new nil, :skip_if => lambda { |req| req.env.key?('HTTP_X_VERY_SPECIAL_HEADER') } }
|
203
|
+
|
204
|
+
it 'should not run the check' do
|
205
|
+
csrf.send(:skip_checking, request).should be_true
|
206
|
+
end
|
183
207
|
end
|
184
208
|
|
185
|
-
context '
|
186
|
-
|
187
|
-
|
209
|
+
context 'and the request does not satisfies the custom check' do
|
210
|
+
context 'and the :check_only list is empty' do
|
211
|
+
let(:csrf) { Rack::Csrf.new nil, :check_only => [] }
|
212
|
+
|
213
|
+
it 'should run the check' do
|
214
|
+
csrf.send(:skip_checking, request).should be_false
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
context 'and the :check_only list is not empty' do
|
219
|
+
context 'and the request is included in the :check_only list' do
|
220
|
+
let(:csrf) { Rack::Csrf.new nil, :check_only => ['POST:/hello'] }
|
221
|
+
|
222
|
+
it 'should run the check' do
|
223
|
+
csrf.send(:skip_checking, request).should be_false
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
context 'but the request is not included in the :check_only list' do
|
228
|
+
let(:csrf) { Rack::Csrf.new nil, :check_only => ['POST:/ciao'] }
|
229
|
+
|
230
|
+
it 'should not run the check' do
|
231
|
+
csrf.send(:skip_checking, request).should be_true
|
232
|
+
end
|
233
|
+
end
|
188
234
|
end
|
189
235
|
end
|
190
236
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack_csrf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 31
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 2
|
8
|
-
-
|
8
|
+
- 4
|
9
9
|
- 0
|
10
|
-
version: 2.
|
10
|
+
version: 2.4.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Emanuele Vicentini
|
@@ -15,11 +15,11 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2012-02-28 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
|
-
name: rack
|
22
21
|
prerelease: false
|
22
|
+
type: :runtime
|
23
23
|
requirement: &id001 !ruby/object:Gem::Requirement
|
24
24
|
none: false
|
25
25
|
requirements:
|
@@ -30,28 +30,44 @@ dependencies:
|
|
30
30
|
- 0
|
31
31
|
- 9
|
32
32
|
version: "0.9"
|
33
|
-
type: :runtime
|
34
33
|
version_requirements: *id001
|
34
|
+
name: rack
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
|
-
name: cucumber
|
37
36
|
prerelease: false
|
37
|
+
type: :development
|
38
38
|
requirement: &id002 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ">="
|
42
42
|
- !ruby/object:Gem::Version
|
43
|
-
hash:
|
43
|
+
hash: 23
|
44
44
|
segments:
|
45
|
-
- 0
|
46
45
|
- 1
|
47
|
-
-
|
48
|
-
|
49
|
-
|
46
|
+
- 0
|
47
|
+
- 0
|
48
|
+
version: 1.0.0
|
50
49
|
version_requirements: *id002
|
50
|
+
name: bundler
|
51
51
|
- !ruby/object:Gem::Dependency
|
52
|
-
name: rack-test
|
53
52
|
prerelease: false
|
53
|
+
type: :development
|
54
54
|
requirement: &id003 !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
hash: 17
|
60
|
+
segments:
|
61
|
+
- 1
|
62
|
+
- 1
|
63
|
+
- 1
|
64
|
+
version: 1.1.1
|
65
|
+
version_requirements: *id003
|
66
|
+
name: cucumber
|
67
|
+
- !ruby/object:Gem::Dependency
|
68
|
+
prerelease: false
|
69
|
+
type: :development
|
70
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
55
71
|
none: false
|
56
72
|
requirements:
|
57
73
|
- - ">="
|
@@ -60,12 +76,12 @@ dependencies:
|
|
60
76
|
segments:
|
61
77
|
- 0
|
62
78
|
version: "0"
|
63
|
-
|
64
|
-
|
79
|
+
version_requirements: *id004
|
80
|
+
name: rack-test
|
65
81
|
- !ruby/object:Gem::Dependency
|
66
|
-
name: rspec
|
67
82
|
prerelease: false
|
68
|
-
|
83
|
+
type: :development
|
84
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
69
85
|
none: false
|
70
86
|
requirements:
|
71
87
|
- - ">="
|
@@ -76,12 +92,12 @@ dependencies:
|
|
76
92
|
- 0
|
77
93
|
- 0
|
78
94
|
version: 2.0.0
|
79
|
-
|
80
|
-
|
95
|
+
version_requirements: *id005
|
96
|
+
name: rspec
|
81
97
|
- !ruby/object:Gem::Dependency
|
82
|
-
name: rdoc
|
83
98
|
prerelease: false
|
84
|
-
|
99
|
+
type: :development
|
100
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
85
101
|
none: false
|
86
102
|
requirements:
|
87
103
|
- - ">="
|
@@ -92,8 +108,22 @@ dependencies:
|
|
92
108
|
- 4
|
93
109
|
- 2
|
94
110
|
version: 2.4.2
|
111
|
+
version_requirements: *id006
|
112
|
+
name: rdoc
|
113
|
+
- !ruby/object:Gem::Dependency
|
114
|
+
prerelease: false
|
95
115
|
type: :development
|
96
|
-
|
116
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
117
|
+
none: false
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
hash: 3
|
122
|
+
segments:
|
123
|
+
- 0
|
124
|
+
version: "0"
|
125
|
+
version_requirements: *id007
|
126
|
+
name: jeweler
|
97
127
|
description: Anti-CSRF Rack middleware
|
98
128
|
email: emanuele.vicentini@gmail.com
|
99
129
|
executables: []
|
@@ -106,6 +136,7 @@ extra_rdoc_files:
|
|
106
136
|
files:
|
107
137
|
- .rspec
|
108
138
|
- Changelog.md
|
139
|
+
- Gemfile
|
109
140
|
- LICENSE.rdoc
|
110
141
|
- README.rdoc
|
111
142
|
- Rakefile
|
@@ -150,6 +181,7 @@ files:
|
|
150
181
|
- features/inspecting_also_get_requests.feature
|
151
182
|
- features/raising_exception.feature
|
152
183
|
- features/setup.feature
|
184
|
+
- features/skip_if_block_passes.feature
|
153
185
|
- features/skip_some_routes.feature
|
154
186
|
- features/step_definitions/request_steps.rb
|
155
187
|
- features/step_definitions/response_steps.rb
|
@@ -157,6 +189,7 @@ files:
|
|
157
189
|
- features/support/env.rb
|
158
190
|
- features/support/fake_session.rb
|
159
191
|
- features/variation_on_field_name.feature
|
192
|
+
- features/variation_on_header_name.feature
|
160
193
|
- features/variation_on_key_name.feature
|
161
194
|
- lib/rack/csrf.rb
|
162
195
|
- lib/rack/vendor/securerandom.rb
|
@@ -171,7 +204,7 @@ rdoc_options:
|
|
171
204
|
- --line-numbers
|
172
205
|
- --inline-source
|
173
206
|
- --title
|
174
|
-
- Rack::Csrf 2.
|
207
|
+
- Rack::Csrf 2.4.0
|
175
208
|
- --main
|
176
209
|
- README.rdoc
|
177
210
|
require_paths:
|
@@ -197,7 +230,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
197
230
|
requirements: []
|
198
231
|
|
199
232
|
rubyforge_project: rackcsrf
|
200
|
-
rubygems_version: 1.8.
|
233
|
+
rubygems_version: 1.8.17
|
201
234
|
signing_key:
|
202
235
|
specification_version: 3
|
203
236
|
summary: Anti-CSRF Rack middleware
|