rack_csrf 1.1.0 → 1.1.1

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/README.rdoc CHANGED
@@ -4,6 +4,9 @@ This is just a small Rack middleware whose only goal is to lessen the hazards
4
4
  posed by CSRF attacks by trying to ensure that all requests of particular
5
5
  types come from the right client, not from a mischievous impersonator.
6
6
 
7
+ Rack::Csrf is not tailored to any particular web framework, so it can be used
8
+ with your preferred Rack-based framework.
9
+
7
10
  == Usage
8
11
 
9
12
  First of all, beyond Rack itself, there is only one prerequisite: you must set
@@ -23,10 +26,12 @@ possibly work.
23
26
  The following options allow you to tweak Rack::Csrf.
24
27
 
25
28
  [<tt>:raise</tt>]
26
- Set it to true to change the handling of bad request: instead of producing
29
+ Set it to true to change the handling of bad requests: instead of producing
27
30
  an empty response, Rack::Csrf will raise an exception of class
28
31
  Rack::Csrf::InvalidCsrfToken.
29
32
 
33
+ use Rack::Csrf, :raise => true
34
+
30
35
  Default value: false.
31
36
 
32
37
  [<tt>:skip</tt>]
@@ -46,11 +51,17 @@ The following options allow you to tweak Rack::Csrf.
46
51
  Default field name (see below) is <tt>_csrf</tt>; you can adapt it to
47
52
  specific needs.
48
53
 
54
+ use Rack::Csrf, :field => '_my_own_csrf_field'
55
+
56
+ Default value: _csrf
57
+
49
58
  [<tt>:browser_only</tt>]
50
59
  Set it to true to inspect only requests with Content-Type typically produced
51
- only by web browser. This means that curl, Active Resource, etc. can send
60
+ only by web browsers. This means that curl, Active Resource, etc. can send
52
61
  any request without worring about the token.
53
62
 
63
+ use Rack::Csrf, :browser_only => true
64
+
54
65
  Default value: false.
55
66
 
56
67
  == Helpers
@@ -73,9 +84,23 @@ token.
73
84
 
74
85
  == Working examples
75
86
 
76
- In the +example+ directory there is a mini Sinatra application with two
77
- slightly different rackup files. Beside Rack you only need Sinatra to try
78
- them, but Rack::Csrf is not tailored to any particular web framework.
87
+ In the +examples+ directory there are some small, working web applications
88
+ written with different Rack-based frameworks. They are named after the used
89
+ framework; see the various README files for other details.
90
+
91
+ == Contributing
92
+
93
+ If you want to help:
94
+
95
+ * fork the project[http://github.com/baldowl/rack_csrf] on GitHub;
96
+ * work in a topic branch;
97
+ * add features/specs for your additions or bug fixes;
98
+ * write your additions/bug fixes;
99
+ * commit;
100
+ * send me a pull request for the topic branch.
101
+
102
+ If you have any issue, please post them on the {project's issue
103
+ list}[http://github.com/baldowl/rack_csrf] on GitHub.
79
104
 
80
105
  == Warning! Warning! Warning!
81
106
 
data/Rakefile CHANGED
@@ -1,30 +1,47 @@
1
1
  require 'rake/clean'
2
2
  require 'cucumber/rake/task'
3
3
  require 'spec/rake/spectask'
4
- require 'echoe'
4
+ require 'rake/rdoctask'
5
+ require 'jeweler'
5
6
 
6
- Cucumber::Rake::Task.new do |c|
7
+ Cucumber::Rake::Task.new :features do |c|
7
8
  c.cucumber_opts = '--profile default'
8
9
  end
9
10
 
11
+ task :features => :check_dependencies
12
+ task :default => :features
13
+
10
14
  Spec::Rake::SpecTask.new do |t|
11
15
  t.spec_opts = %w(-O spec/spec.opts)
12
16
  end
13
17
 
14
- Echoe.new('rack_csrf', '1.1.0') do |s|
15
- s.author = 'Emanuele Vicentini'
16
- s.email = 'emanuele.vicentini@gmail.com'
17
- s.summary = 'Anti-CSRF Rack middleware'
18
- s.runtime_dependencies = ['rack >=0.9']
19
- s.development_dependencies = ['rake >=0.8.2', 'cucumber >=1.1.13', 'rspec', 'echoe']
20
- s.need_tar_gz = false
21
- s.project = 'rackcsrf'
22
- s.gemspec_format = :yaml
23
- s.retain_gemspec = true
24
- s.rdoc_pattern = /^README|^LICENSE/
25
- s.url = 'http://github.com/baldowl/rack_csrf'
18
+ task :spec => :check_dependencies
19
+ task :default => :spec
20
+
21
+ version = File.exists?('VERSION') ? File.read('VERSION').strip : ''
22
+
23
+ Rake::RDocTask.new :doc do |rdoc|
24
+ rdoc.rdoc_dir = 'doc'
25
+ rdoc.title = "Rack::Csrf #{version}"
26
+ rdoc.rdoc_files.include('README.rdoc', 'LICENSE.rdoc')
27
+ rdoc.rdoc_files.include('lib/**/*.rb')
28
+ end
29
+
30
+ Jeweler::Tasks.new do |gem|
31
+ gem.name = 'rack_csrf'
32
+ gem.summary = 'Anti-CSRF Rack middleware'
33
+ gem.description = 'Anti-CSRF Rack middleware'
34
+ gem.email = 'emanuele.vicentini@gmail.com'
35
+ gem.homepage = 'http://github.com/baldowl/rack_csrf'
36
+ gem.authors = ['Emanuele Vicentini']
37
+ gem.rubyforge_project = 'rackcsrf'
38
+ gem.add_dependency 'rack', '>= 0.9'
39
+ gem.add_development_dependency 'cucumber', '>= 0.1.13'
40
+ gem.add_development_dependency 'rspec'
41
+ gem.rdoc_options << '--line-numbers' << '--inline-source' << '--title' <<
42
+ "Rack::Csrf #{version}" << '--main' << 'README.rdoc'
43
+ gem.test_files.clear
26
44
  end
27
45
 
28
- Rake::Task[:default].clear
29
- Rake::Task.tasks.each {|t| t.clear if t.name =~ /test/}
30
- task :default => [:features, :spec]
46
+ Jeweler::RubyforgeTasks.new
47
+ Jeweler::GemcutterTasks.new
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.1.1
@@ -0,0 +1,13 @@
1
+ = How to use Rack::Csrf with Innate
2
+
3
+ These are two mini, slightly different, Innate applications. You only need
4
+ Innate to try them.
5
+
6
+ $ sudo gem install manveru-innate --source http://gems.github.com
7
+ $ ruby start.rb
8
+ $ ruby start-with-raise.rb
9
+
10
+ Tested with Innate 2009.07.
11
+
12
+ Please, note that Innate is, to some extent, the kernel of Ramaze; "upgrading"
13
+ these examples to use Ramaze is left as an exercise to the reader :-)
@@ -0,0 +1,10 @@
1
+ class LittleApp
2
+ Innate.node '/'
3
+
4
+ provide :html, :engine => :ERB
5
+
6
+ def response
7
+ redirect_referer unless request.post?
8
+ @utterance, @csrf = request[:utterance, Rack::Csrf.csrf_field]
9
+ end
10
+ end
@@ -0,0 +1,14 @@
1
+ require 'rubygems'
2
+ require 'innate'
3
+
4
+ $: << File.join(File.dirname(__FILE__), '../../lib')
5
+ require 'rack/csrf'
6
+
7
+ require 'app'
8
+
9
+ Innate.start do |m|
10
+ m.use Rack::ShowExceptions
11
+ m.use Rack::Session::Cookie
12
+ m.use Rack::Csrf, :raise => true
13
+ m.innate
14
+ end
@@ -0,0 +1,13 @@
1
+ require 'rubygems'
2
+ require 'innate'
3
+
4
+ $: << File.join(File.dirname(__FILE__), '../../lib')
5
+ require 'rack/csrf'
6
+
7
+ require 'app'
8
+
9
+ Innate.start do |m|
10
+ m.use Rack::Session::Cookie
11
+ m.use Rack::Csrf
12
+ m.innate
13
+ end
@@ -0,0 +1,8 @@
1
+ <form action="/response" method="post">
2
+ <h1>Spit your utterance!</h1>
3
+ <input type="text" name="utterance">
4
+ <%= Rack::Csrf.csrf_tag(request.env) %>
5
+ <p><input type="submit" value="Send!"></p>
6
+ </form>
7
+
8
+ <p>Try also the <a href="/notworking">not working</a> form!</p>
@@ -0,0 +1,5 @@
1
+ <p>It seems you've just said: <em><%= @utterance %></em></p>
2
+
3
+ <p>Here's the anti-CSRF token stuffed in the session: <strong><%= @csrf %></strong></p>
4
+
5
+ <p><a href='/'>Back</a></p>
@@ -0,0 +1,10 @@
1
+ = How to use Rack::Csrf with Rack
2
+
3
+ This is a mini Rack application with two slightly different rackup files. You
4
+ only need Rack to try them.
5
+
6
+ $ sudo gem install rack
7
+ $ thin -R config.ru -p 3000 start
8
+ $ thin -R config-with-raise.ru -p 3000 start
9
+
10
+ Tested with Rack 1.0.0.
@@ -0,0 +1,45 @@
1
+ class LittleApp
2
+ @form = ERB.new <<-EOT
3
+ <form action="/response" method="post">
4
+ <h1>Spit your utterance!</h1>
5
+ <input type="text" name="utterance">
6
+ <%= Rack::Csrf.csrf_tag(env) %>
7
+ <p><input type="submit" value="Send!"></p>
8
+ </form>
9
+
10
+ <p>Try also the <a href="/notworking">not working</a> form!</p>
11
+ EOT
12
+
13
+ @form_not_working = ERB.new <<-EOT
14
+ <form action="/response" method="post">
15
+ <h1>Spit your utterance!</h1>
16
+ <input type="text" name="utterance">
17
+ <p><input type="submit" value="Send!"></p>
18
+ </form>
19
+
20
+ <p>Try also the <a href="/">working</a> form!</p>
21
+ EOT
22
+
23
+ @response = ERB.new <<-EOT
24
+ <p>It seems you've just said: <em><%= utterance %></em></p>
25
+
26
+ <p>Here's the anti-CSRF token stuffed in the session: <strong><%= csrf %></strong></p>
27
+
28
+ <p><a href='/'>Back</a></p>
29
+ EOT
30
+
31
+ def self.call env
32
+ req = Rack::Request.new env
33
+ if req.get?
34
+ if req.path_info == '/notworking'
35
+ Rack::Response.new(@form_not_working.result(binding)).finish
36
+ else
37
+ Rack::Response.new(@form.result(binding)).finish
38
+ end
39
+ elsif req.post?
40
+ utterance = req['utterance']
41
+ csrf = req[Rack::Csrf.csrf_field]
42
+ Rack::Response.new(@response.result(binding)).finish
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,11 @@
1
+ $: << File.join(File.dirname(__FILE__), '../../lib')
2
+ require 'rack/csrf'
3
+
4
+ require 'erb'
5
+ require 'app'
6
+
7
+ use Rack::ShowExceptions
8
+ use Rack::Session::Cookie
9
+ use Rack::Csrf, :raise => true
10
+
11
+ run LittleApp
@@ -0,0 +1,10 @@
1
+ $: << File.join(File.dirname(__FILE__), '../../lib')
2
+ require 'rack/csrf'
3
+
4
+ require 'erb'
5
+ require 'app'
6
+
7
+ use Rack::Session::Cookie
8
+ use Rack::Csrf
9
+
10
+ run LittleApp
@@ -0,0 +1,10 @@
1
+ = How to use Rack::Csrf with Sinatra
2
+
3
+ This is a mini Sinatra application with two slightly different rackup files.
4
+ Beside Rack you only need Sinatra to try them.
5
+
6
+ $ sudo gem install sinatra
7
+ $ thin -R config.ru -p 3000 start
8
+ $ thin -R config-with-raise.ru -p 3000 start
9
+
10
+ Tested with Sinatra 0.9.4.
File without changes
@@ -1,5 +1,6 @@
1
1
  require 'sinatra'
2
- require File.dirname(__FILE__) + '/../lib/rack/csrf'
2
+ $: << File.join(File.dirname(__FILE__), '../../lib')
3
+ require 'rack/csrf'
3
4
 
4
5
  require 'erb'
5
6
  require 'app'
@@ -1,5 +1,6 @@
1
1
  require 'sinatra'
2
- require File.dirname(__FILE__) + '/../lib/rack/csrf'
2
+ $: << File.join(File.dirname(__FILE__), '../../lib')
3
+ require 'rack/csrf'
3
4
 
4
5
  require 'erb'
5
6
  require 'app'
File without changes
@@ -0,0 +1,7 @@
1
+ <form action="/response" method="post">
2
+ <h1>Spit your utterance!</h1>
3
+ <input type="text" name="utterance">
4
+ <p><input type="submit" value="Send!"></p>
5
+ </form>
6
+
7
+ <p>Try also the <a href="/">working</a> form!</p>
File without changes
@@ -14,7 +14,7 @@ Feature: Filtering only browser generated requests
14
14
  Scenario Outline: Handling request without CSRF token
15
15
  Given a rack with the anti-CSRF middleware and the :browser_only option
16
16
  When it receives a <method> request without the CSRF token from a browser
17
- Then it responds with 417
17
+ Then it responds with 403
18
18
  And the response body is empty
19
19
 
20
20
  Examples:
@@ -13,7 +13,7 @@ Feature: Handling of the HTTP requests returning an empty response
13
13
  Scenario Outline: Handling request without CSRF token
14
14
  Given a rack with the anti-CSRF middleware
15
15
  When it receives a <method> request without the CSRF token
16
- Then it responds with 417
16
+ Then it responds with 403
17
17
  And the response body is empty
18
18
 
19
19
  Examples:
@@ -36,7 +36,7 @@ Feature: Handling of the HTTP requests returning an empty response
36
36
  Scenario Outline: Handling request with the wrong CSRF token
37
37
  Given a rack with the anti-CSRF middleware
38
38
  When it receives a <method> request with the wrong CSRF token
39
- Then it responds with 417
39
+ Then it responds with 403
40
40
  And the response body is empty
41
41
 
42
42
  Examples:
@@ -26,7 +26,7 @@ Feature: Skipping the check for some specific routes
26
26
  | POST:/not_.*\.json |
27
27
  | DELETE:/cars/.*\.xml |
28
28
  When it receives a <method> request for <path> without the CSRF token
29
- Then it responds with 417
29
+ Then it responds with 403
30
30
  And the response body is empty
31
31
 
32
32
  Examples:
@@ -1,16 +1,9 @@
1
1
  require 'rubygems'
2
2
  require 'spec/expectations'
3
3
 
4
- require File.dirname(__FILE__) + "/../../lib/rack/csrf"
4
+ $: << File.join(File.dirname(__FILE__), '../../lib')
5
+ $: << File.join(File.dirname(__FILE__))
5
6
 
6
- # Simulated session used just to be able to insert data into it without seeing
7
- # them wiped out.
8
- class FakeSession
9
- def initialize(app)
10
- @app = app
11
- end
12
- def call(env)
13
- env['rack.session'] ||= Hash.new
14
- @app.call(env)
15
- end
16
- end
7
+ require 'rack/csrf'
8
+
9
+ require 'fake_session'
@@ -0,0 +1,11 @@
1
+ # Simulated session used just to be able to insert data into it without seeing
2
+ # them wiped out.
3
+ class FakeSession
4
+ def initialize(app)
5
+ @app = app
6
+ end
7
+ def call(env)
8
+ env['rack.session'] ||= Hash.new
9
+ @app.call(env)
10
+ end
11
+ end
@@ -19,7 +19,7 @@ Feature: Customization of the field name
19
19
  Scenario Outline: Handling request with the wrong CSRF token in custom field
20
20
  Given a rack with the anti-CSRF middleware and the :field option
21
21
  When it receives a <method> request with the wrong CSRF token
22
- Then it responds with 417
22
+ Then it responds with 403
23
23
  And the response body is empty
24
24
 
25
25
  Examples:
data/lib/rack/csrf.rb CHANGED
@@ -40,7 +40,7 @@ module Rack
40
40
  @app.call(env)
41
41
  else
42
42
  raise InvalidCsrfToken if @raisable
43
- [417, {'Content-Type' => 'text/html', 'Content-Length' => '0'}, []]
43
+ [403, {'Content-Type' => 'text/html', 'Content-Length' => '0'}, []]
44
44
  end
45
45
  end
46
46
 
data/rack_csrf.gemspec CHANGED
@@ -1,133 +1,86 @@
1
- --- !ruby/object:Gem::Specification
2
- name: rack_csrf
3
- version: !ruby/object:Gem::Version
4
- version: 1.1.0
5
- platform: ruby
6
- authors:
7
- - Emanuele Vicentini
8
- autorequire:
9
- bindir: bin
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
+ # -*- encoding: utf-8 -*-
10
5
 
11
- date: 2009-05-22 00:00:00 +02:00
12
- default_executable:
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: rack
16
- type: :runtime
17
- version_requirement:
18
- version_requirements: !ruby/object:Gem::Requirement
19
- requirements:
20
- - - ">="
21
- - !ruby/object:Gem::Version
22
- version: "0.9"
23
- version:
24
- - !ruby/object:Gem::Dependency
25
- name: rake
26
- type: :development
27
- version_requirement:
28
- version_requirements: !ruby/object:Gem::Requirement
29
- requirements:
30
- - - ">="
31
- - !ruby/object:Gem::Version
32
- version: 0.8.2
33
- version:
34
- - !ruby/object:Gem::Dependency
35
- name: cucumber
36
- type: :development
37
- version_requirement:
38
- version_requirements: !ruby/object:Gem::Requirement
39
- requirements:
40
- - - ">="
41
- - !ruby/object:Gem::Version
42
- version: 1.1.13
43
- version:
44
- - !ruby/object:Gem::Dependency
45
- name: rspec
46
- type: :development
47
- version_requirement:
48
- version_requirements: !ruby/object:Gem::Requirement
49
- requirements:
50
- - - ">="
51
- - !ruby/object:Gem::Version
52
- version: "0"
53
- version:
54
- - !ruby/object:Gem::Dependency
55
- name: echoe
56
- type: :development
57
- version_requirement:
58
- version_requirements: !ruby/object:Gem::Requirement
59
- requirements:
60
- - - ">="
61
- - !ruby/object:Gem::Version
62
- version: "0"
63
- version:
64
- description: Anti-CSRF Rack middleware
65
- email: emanuele.vicentini@gmail.com
66
- executables: []
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{rack_csrf}
8
+ s.version = "1.1.1"
67
9
 
68
- extensions: []
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Emanuele Vicentini"]
12
+ s.date = %q{2009-10-15}
13
+ s.description = %q{Anti-CSRF Rack middleware}
14
+ s.email = %q{emanuele.vicentini@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.rdoc",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ "LICENSE.rdoc",
21
+ "README.rdoc",
22
+ "Rakefile",
23
+ "VERSION",
24
+ "cucumber.yml",
25
+ "examples/innate/README.rdoc",
26
+ "examples/innate/app.rb",
27
+ "examples/innate/start-with-raise.rb",
28
+ "examples/innate/start.rb",
29
+ "examples/innate/view/index.erb",
30
+ "examples/innate/view/notworking.erb",
31
+ "examples/innate/view/response.erb",
32
+ "examples/rack/README.rdoc",
33
+ "examples/rack/app.rb",
34
+ "examples/rack/config-with-raise.ru",
35
+ "examples/rack/config.ru",
36
+ "examples/sinatra/README.rdoc",
37
+ "examples/sinatra/app.rb",
38
+ "examples/sinatra/config-with-raise.ru",
39
+ "examples/sinatra/config.ru",
40
+ "examples/sinatra/views/form.erb",
41
+ "examples/sinatra/views/form_not_working.erb",
42
+ "examples/sinatra/views/response.erb",
43
+ "features/browser_only.feature",
44
+ "features/empty_responses.feature",
45
+ "features/raising_exception.feature",
46
+ "features/setup.feature",
47
+ "features/skip_some_routes.feature",
48
+ "features/step_definitions/request_steps.rb",
49
+ "features/step_definitions/response_steps.rb",
50
+ "features/step_definitions/setup_steps.rb",
51
+ "features/support/env.rb",
52
+ "features/support/fake_session.rb",
53
+ "features/variation_on_field_name.feature",
54
+ "lib/rack/csrf.rb",
55
+ "lib/rack/vendor/securerandom.rb",
56
+ "rack_csrf.gemspec",
57
+ "spec/csrf_spec.rb",
58
+ "spec/spec.opts",
59
+ "spec/spec_helper.rb"
60
+ ]
61
+ s.homepage = %q{http://github.com/baldowl/rack_csrf}
62
+ s.rdoc_options = ["--charset=UTF-8", "--line-numbers", "--inline-source", "--title", "Rack::Csrf 1.1.1", "--main", "README.rdoc"]
63
+ s.require_paths = ["lib"]
64
+ s.rubyforge_project = %q{rackcsrf}
65
+ s.rubygems_version = %q{1.3.5}
66
+ s.summary = %q{Anti-CSRF Rack middleware}
69
67
 
70
- extra_rdoc_files:
71
- - LICENSE.rdoc
72
- - README.rdoc
73
- files:
74
- - cucumber.yml
75
- - example/app.rb
76
- - example/config-with-raise.ru
77
- - example/config.ru
78
- - example/views/form.erb
79
- - example/views/form_not_working.erb
80
- - example/views/response.erb
81
- - features/browser_only.feature
82
- - features/empty_responses.feature
83
- - features/raising_exception.feature
84
- - features/setup.feature
85
- - features/skip_some_routes.feature
86
- - features/step_definitions/request_steps.rb
87
- - features/step_definitions/response_steps.rb
88
- - features/step_definitions/setup_steps.rb
89
- - features/support/env.rb
90
- - features/variation_on_field_name.feature
91
- - lib/rack/csrf.rb
92
- - lib/rack/vendor/securerandom.rb
93
- - LICENSE.rdoc
94
- - Manifest
95
- - rack_csrf.gemspec
96
- - Rakefile
97
- - README.rdoc
98
- - spec/csrf_spec.rb
99
- - spec/spec.opts
100
- - spec/spec_helper.rb
101
- has_rdoc: true
102
- homepage: http://github.com/baldowl/rack_csrf
103
- licenses: []
68
+ if s.respond_to? :specification_version then
69
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
70
+ s.specification_version = 3
104
71
 
105
- post_install_message:
106
- rdoc_options:
107
- - --line-numbers
108
- - --inline-source
109
- - --title
110
- - Rack_csrf
111
- - --main
112
- - README.rdoc
113
- require_paths:
114
- - lib
115
- required_ruby_version: !ruby/object:Gem::Requirement
116
- requirements:
117
- - - ">="
118
- - !ruby/object:Gem::Version
119
- version: "0"
120
- version:
121
- required_rubygems_version: !ruby/object:Gem::Requirement
122
- requirements:
123
- - - ">="
124
- - !ruby/object:Gem::Version
125
- version: "1.2"
126
- version:
127
- requirements: []
128
-
129
- rubyforge_project: rackcsrf
130
- rubygems_version: 1.3.3
131
- specification_version: 3
132
- summary: Anti-CSRF Rack middleware
133
- test_files: []
72
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
73
+ s.add_runtime_dependency(%q<rack>, [">= 0.9"])
74
+ s.add_development_dependency(%q<cucumber>, [">= 0.1.13"])
75
+ s.add_development_dependency(%q<rspec>, [">= 0"])
76
+ else
77
+ s.add_dependency(%q<rack>, [">= 0.9"])
78
+ s.add_dependency(%q<cucumber>, [">= 0.1.13"])
79
+ s.add_dependency(%q<rspec>, [">= 0"])
80
+ end
81
+ else
82
+ s.add_dependency(%q<rack>, [">= 0.9"])
83
+ s.add_dependency(%q<cucumber>, [">= 0.1.13"])
84
+ s.add_dependency(%q<rspec>, [">= 0"])
85
+ end
86
+ end
data/spec/csrf_spec.rb CHANGED
@@ -1,13 +1,13 @@
1
- require File.dirname(__FILE__) + '/spec_helper.rb'
1
+ require File.join(File.dirname(__FILE__), 'spec_helper.rb')
2
2
 
3
3
  describe Rack::Csrf do
4
4
  describe '#csrf_field' do
5
- it "should be '_csrf'" do
5
+ it "should be '_csrf' by default" do
6
6
  Rack::Csrf.csrf_field.should == '_csrf'
7
7
  end
8
8
 
9
9
  it "should be the value of :field option" do
10
- fakeapp = [200, {}, []]
10
+ fakeapp = lambda {|env| [200, {}, []]}
11
11
  Rack::Csrf.new fakeapp, :field => 'whatever'
12
12
  Rack::Csrf.csrf_field.should == 'whatever'
13
13
  end
@@ -22,25 +22,31 @@ describe Rack::Csrf do
22
22
  Rack::Csrf.csrf_token(@env).length.should >= 32
23
23
  end
24
24
 
25
- it 'should store the token inside the session if it is not already there' do
26
- @env['rack.session'].should be_empty
27
- Rack::Csrf.csrf_token(@env)
28
- @env['rack.session'].should_not be_empty
29
- @env['rack.session']['csrf.token'].should_not be_empty
25
+ context 'when the session does not already contain the token' do
26
+ it 'should store the token inside the session' do
27
+ @env['rack.session'].should be_empty
28
+ csrf_token = Rack::Csrf.csrf_token(@env)
29
+ @env['rack.session'].should_not be_empty
30
+ @env['rack.session']['csrf.token'].should_not be_empty
31
+ csrf_token.should == @env['rack.session']['csrf.token']
32
+ end
30
33
  end
31
34
 
32
- it 'should get the token from the session if it is already there' do
33
- @env['rack.session'].should be_empty
34
- csrf_token = Rack::Csrf.csrf_token(@env)
35
- csrf_token.should == @env['rack.session']['csrf.token']
36
- csrf_token.should == Rack::Csrf.csrf_token(@env)
35
+ context 'when the session already contains the token' do
36
+ before do
37
+ Rack::Csrf.csrf_token @env
38
+ end
39
+ it 'should get the token from the session' do
40
+ @env['rack.session'].should_not be_empty
41
+ @env['rack.session']['csrf.token'].should == Rack::Csrf.csrf_token(@env)
42
+ end
37
43
  end
38
44
  end
39
45
 
40
46
  describe '#csrf_tag' do
41
47
  before do
42
48
  @env = {'rack.session' => {}}
43
- fakeapp = [200, {}, []]
49
+ fakeapp = lambda {|env| [200, {}, []]}
44
50
  Rack::Csrf.new fakeapp, :field => 'whatever'
45
51
  @tag = Rack::Csrf.csrf_tag(@env)
46
52
  end
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,6 @@
1
1
  require 'rubygems'
2
2
  require 'spec'
3
3
 
4
- require File.dirname(__FILE__) + '/../lib/rack/csrf'
4
+ $: << File.join(File.dirname(__FILE__), '../lib')
5
+
6
+ require 'rack/csrf'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack_csrf
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emanuele Vicentini
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-05-22 00:00:00 +02:00
12
+ date: 2009-10-15 00:00:00 +02:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -22,16 +22,6 @@ dependencies:
22
22
  - !ruby/object:Gem::Version
23
23
  version: "0.9"
24
24
  version:
25
- - !ruby/object:Gem::Dependency
26
- name: rake
27
- type: :development
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: 0.8.2
34
- version:
35
25
  - !ruby/object:Gem::Dependency
36
26
  name: cucumber
37
27
  type: :development
@@ -40,7 +30,7 @@ dependencies:
40
30
  requirements:
41
31
  - - ">="
42
32
  - !ruby/object:Gem::Version
43
- version: 1.1.13
33
+ version: 0.1.13
44
34
  version:
45
35
  - !ruby/object:Gem::Dependency
46
36
  name: rspec
@@ -52,16 +42,6 @@ dependencies:
52
42
  - !ruby/object:Gem::Version
53
43
  version: "0"
54
44
  version:
55
- - !ruby/object:Gem::Dependency
56
- name: echoe
57
- type: :development
58
- version_requirement:
59
- version_requirements: !ruby/object:Gem::Requirement
60
- requirements:
61
- - - ">="
62
- - !ruby/object:Gem::Version
63
- version: "0"
64
- version:
65
45
  description: Anti-CSRF Rack middleware
66
46
  email: emanuele.vicentini@gmail.com
67
47
  executables: []
@@ -72,13 +52,29 @@ extra_rdoc_files:
72
52
  - LICENSE.rdoc
73
53
  - README.rdoc
74
54
  files:
55
+ - LICENSE.rdoc
56
+ - README.rdoc
57
+ - Rakefile
58
+ - VERSION
75
59
  - cucumber.yml
76
- - example/app.rb
77
- - example/config-with-raise.ru
78
- - example/config.ru
79
- - example/views/form.erb
80
- - example/views/form_not_working.erb
81
- - example/views/response.erb
60
+ - examples/innate/README.rdoc
61
+ - examples/innate/app.rb
62
+ - examples/innate/start-with-raise.rb
63
+ - examples/innate/start.rb
64
+ - examples/innate/view/index.erb
65
+ - examples/innate/view/notworking.erb
66
+ - examples/innate/view/response.erb
67
+ - examples/rack/README.rdoc
68
+ - examples/rack/app.rb
69
+ - examples/rack/config-with-raise.ru
70
+ - examples/rack/config.ru
71
+ - examples/sinatra/README.rdoc
72
+ - examples/sinatra/app.rb
73
+ - examples/sinatra/config-with-raise.ru
74
+ - examples/sinatra/config.ru
75
+ - examples/sinatra/views/form.erb
76
+ - examples/sinatra/views/form_not_working.erb
77
+ - examples/sinatra/views/response.erb
82
78
  - features/browser_only.feature
83
79
  - features/empty_responses.feature
84
80
  - features/raising_exception.feature
@@ -88,14 +84,11 @@ files:
88
84
  - features/step_definitions/response_steps.rb
89
85
  - features/step_definitions/setup_steps.rb
90
86
  - features/support/env.rb
87
+ - features/support/fake_session.rb
91
88
  - features/variation_on_field_name.feature
92
89
  - lib/rack/csrf.rb
93
90
  - lib/rack/vendor/securerandom.rb
94
- - LICENSE.rdoc
95
- - Manifest
96
91
  - rack_csrf.gemspec
97
- - Rakefile
98
- - README.rdoc
99
92
  - spec/csrf_spec.rb
100
93
  - spec/spec.opts
101
94
  - spec/spec_helper.rb
@@ -105,10 +98,11 @@ licenses: []
105
98
 
106
99
  post_install_message:
107
100
  rdoc_options:
101
+ - --charset=UTF-8
108
102
  - --line-numbers
109
103
  - --inline-source
110
104
  - --title
111
- - Rack_csrf
105
+ - Rack::Csrf 1.1.1
112
106
  - --main
113
107
  - README.rdoc
114
108
  require_paths:
@@ -123,12 +117,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
123
117
  requirements:
124
118
  - - ">="
125
119
  - !ruby/object:Gem::Version
126
- version: "1.2"
120
+ version: "0"
127
121
  version:
128
122
  requirements: []
129
123
 
130
124
  rubyforge_project: rackcsrf
131
- rubygems_version: 1.3.3
125
+ rubygems_version: 1.3.5
132
126
  signing_key:
133
127
  specification_version: 3
134
128
  summary: Anti-CSRF Rack middleware
data/Manifest DELETED
@@ -1,27 +0,0 @@
1
- cucumber.yml
2
- example/app.rb
3
- example/config-with-raise.ru
4
- example/config.ru
5
- example/views/form.erb
6
- example/views/form_not_working.erb
7
- example/views/response.erb
8
- features/browser_only.feature
9
- features/empty_responses.feature
10
- features/raising_exception.feature
11
- features/setup.feature
12
- features/skip_some_routes.feature
13
- features/step_definitions/request_steps.rb
14
- features/step_definitions/response_steps.rb
15
- features/step_definitions/setup_steps.rb
16
- features/support/env.rb
17
- features/variation_on_field_name.feature
18
- lib/rack/csrf.rb
19
- lib/rack/vendor/securerandom.rb
20
- LICENSE.rdoc
21
- Manifest
22
- rack_csrf.gemspec
23
- Rakefile
24
- README.rdoc
25
- spec/csrf_spec.rb
26
- spec/spec.opts
27
- spec/spec_helper.rb