quo_vadis 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md ADDED
@@ -0,0 +1,32 @@
1
+ # CHANGELOG
2
+
3
+
4
+ ## 1.0.4 (22 February 2011)
5
+
6
+ * Work with Rails' improved CSRF protection.
7
+ * Prevent session fixation attacks.
8
+
9
+
10
+ ## 1.0.3 (7 February 2011)
11
+
12
+ * Remember user between browser sessions.
13
+
14
+
15
+ ## 1.0.2 (27 January 2011)
16
+
17
+ * Forgotten-password functionality.
18
+
19
+
20
+ ## 1.0.1 (26 January 2011)
21
+
22
+ * Configurable layout.
23
+ * Make flash messages optional.
24
+
25
+
26
+ ## 1.0.0 (25 January 2011)
27
+
28
+ * Sign in.
29
+ * Sign out.
30
+ * Authenticate actions.
31
+ * Remember URL user wants to view.
32
+ * Hooks for sign in, sign out, failed sign in.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- quo_vadis (1.0.2)
4
+ quo_vadis (1.0.4)
5
5
  bcrypt-ruby (~> 2.1.4)
6
6
  rails (~> 3.0)
7
7
 
@@ -9,36 +9,36 @@ GEM
9
9
  remote: http://rubygems.org/
10
10
  specs:
11
11
  abstract (1.0.0)
12
- actionmailer (3.0.3)
13
- actionpack (= 3.0.3)
14
- mail (~> 2.2.9)
15
- actionpack (3.0.3)
16
- activemodel (= 3.0.3)
17
- activesupport (= 3.0.3)
12
+ actionmailer (3.0.4)
13
+ actionpack (= 3.0.4)
14
+ mail (~> 2.2.15)
15
+ actionpack (3.0.4)
16
+ activemodel (= 3.0.4)
17
+ activesupport (= 3.0.4)
18
18
  builder (~> 2.1.2)
19
19
  erubis (~> 2.6.6)
20
20
  i18n (~> 0.4)
21
21
  rack (~> 1.2.1)
22
22
  rack-mount (~> 0.6.13)
23
- rack-test (~> 0.5.6)
23
+ rack-test (~> 0.5.7)
24
24
  tzinfo (~> 0.3.23)
25
- activemodel (3.0.3)
26
- activesupport (= 3.0.3)
25
+ activemodel (3.0.4)
26
+ activesupport (= 3.0.4)
27
27
  builder (~> 2.1.2)
28
28
  i18n (~> 0.4)
29
- activerecord (3.0.3)
30
- activemodel (= 3.0.3)
31
- activesupport (= 3.0.3)
29
+ activerecord (3.0.4)
30
+ activemodel (= 3.0.4)
31
+ activesupport (= 3.0.4)
32
32
  arel (~> 2.0.2)
33
33
  tzinfo (~> 0.3.23)
34
- activeresource (3.0.3)
35
- activemodel (= 3.0.3)
36
- activesupport (= 3.0.3)
37
- activesupport (3.0.3)
38
- arel (2.0.4)
34
+ activeresource (3.0.4)
35
+ activemodel (= 3.0.4)
36
+ activesupport (= 3.0.4)
37
+ activesupport (3.0.4)
38
+ arel (2.0.8)
39
39
  bcrypt-ruby (2.1.4)
40
40
  builder (2.1.2)
41
- capybara (0.4.1.1)
41
+ capybara (0.4.1.2)
42
42
  celerity (>= 0.7.9)
43
43
  culerity (>= 0.2.4)
44
44
  mime-types (>= 1.16)
@@ -47,8 +47,8 @@ GEM
47
47
  rack-test (>= 0.5.4)
48
48
  selenium-webdriver (>= 0.0.27)
49
49
  xpath (~> 0.1.3)
50
- celerity (0.8.7)
51
- childprocess (0.1.6)
50
+ celerity (0.8.8)
51
+ childprocess (0.1.7)
52
52
  ffi (~> 0.6.3)
53
53
  configuration (1.2.0)
54
54
  culerity (0.2.15)
@@ -56,14 +56,14 @@ GEM
56
56
  abstract (>= 1.0.0)
57
57
  ffi (0.6.3)
58
58
  rake (>= 0.8.7)
59
- i18n (0.4.1)
60
- json_pure (1.5.0)
59
+ i18n (0.5.0)
60
+ json_pure (1.5.1)
61
61
  launchy (0.3.7)
62
62
  configuration (>= 0.0.5)
63
63
  rake (>= 0.8.1)
64
- mail (2.2.10)
64
+ mail (2.2.15)
65
65
  activesupport (>= 2.3.6)
66
- i18n (~> 0.4.1)
66
+ i18n (>= 0.4.0)
67
67
  mime-types (~> 1.16)
68
68
  treetop (~> 1.4.8)
69
69
  mime-types (1.16)
@@ -72,33 +72,33 @@ GEM
72
72
  rack (1.2.1)
73
73
  rack-mount (0.6.13)
74
74
  rack (>= 1.0.0)
75
- rack-test (0.5.6)
75
+ rack-test (0.5.7)
76
76
  rack (>= 1.0)
77
- rails (3.0.3)
78
- actionmailer (= 3.0.3)
79
- actionpack (= 3.0.3)
80
- activerecord (= 3.0.3)
81
- activeresource (= 3.0.3)
82
- activesupport (= 3.0.3)
77
+ rails (3.0.4)
78
+ actionmailer (= 3.0.4)
79
+ actionpack (= 3.0.4)
80
+ activerecord (= 3.0.4)
81
+ activeresource (= 3.0.4)
82
+ activesupport (= 3.0.4)
83
83
  bundler (~> 1.0)
84
- railties (= 3.0.3)
85
- railties (3.0.3)
86
- actionpack (= 3.0.3)
87
- activesupport (= 3.0.3)
84
+ railties (= 3.0.4)
85
+ railties (3.0.4)
86
+ actionpack (= 3.0.4)
87
+ activesupport (= 3.0.4)
88
88
  rake (>= 0.8.7)
89
89
  thor (~> 0.14.4)
90
90
  rake (0.8.7)
91
91
  rubyzip (0.9.4)
92
- selenium-webdriver (0.1.2)
92
+ selenium-webdriver (0.1.3)
93
93
  childprocess (~> 0.1.5)
94
94
  ffi (~> 0.6.3)
95
95
  json_pure
96
96
  rubyzip
97
97
  sqlite3-ruby (1.2.5)
98
98
  thor (0.14.6)
99
- treetop (1.4.8)
99
+ treetop (1.4.9)
100
100
  polyglot (>= 0.3.1)
101
- tzinfo (0.3.23)
101
+ tzinfo (0.3.24)
102
102
  xpath (0.1.3)
103
103
  nokogiri (~> 1.3)
104
104
 
@@ -106,9 +106,8 @@ PLATFORMS
106
106
  ruby
107
107
 
108
108
  DEPENDENCIES
109
- bcrypt-ruby (~> 2.1.4)
110
109
  capybara (>= 0.4.0)
111
110
  launchy
112
111
  quo_vadis!
113
- rails (~> 3.0)
112
+ rails (>= 3.0.4)
114
113
  sqlite3-ruby
data/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  Quo Vadis adds simple username/password authentication to Rails 3 applications.
4
4
 
5
+ Why bother with yet another authentication gem? Well, I find all the others over-engineered. Code should be easy to use and easy to read. As far as I'm concerned, none of the others ticks both boxes.
6
+
5
7
  Features:
6
8
 
7
9
  * Minimal effort to add authentication to your app: get up and running in 5 minutes.
@@ -3,6 +3,11 @@ module ControllerMixin
3
3
  base.helper_method :current_user
4
4
  end
5
5
 
6
+ def handle_unverified_request
7
+ super
8
+ cookies.delete :remember_me
9
+ end
10
+
6
11
  private
7
12
 
8
13
  # Remembers the authenticated <tt>user</tt> (in this session and future sessions).
@@ -83,6 +83,7 @@ class QuoVadis::SessionsController < ApplicationController
83
83
  # and you need to sign them in. For example, if a new user has just signed up,
84
84
  # you should call this method to sign them in.
85
85
  def sign_in(user)
86
+ prevent_session_fixation
86
87
  self.current_user = user
87
88
  QuoVadis.signed_in_hook user, self
88
89
  redirect_to QuoVadis.signed_in_url(user, original_url)
@@ -106,4 +107,14 @@ class QuoVadis::SessionsController < ApplicationController
106
107
  QuoVadis.layout
107
108
  end
108
109
 
110
+ def prevent_session_fixation # :nodoc:
111
+ original_flash = flash.inject({}) { |hsh, (k,v)| hsh[k] = v; hsh }
112
+ original_url = session[:quo_vadis_original_url]
113
+
114
+ reset_session
115
+
116
+ original_flash.each { |k,v| flash[k] = v }
117
+ session[:quo_vadis_original_url] = original_url
118
+ end
119
+
109
120
  end
@@ -1,3 +1,3 @@
1
1
  module QuoVadis
2
- VERSION = '1.0.3'
2
+ VERSION = '1.0.4'
3
3
  end
data/quo_vadis.gemspec CHANGED
@@ -22,6 +22,7 @@ Gem::Specification.new do |s|
22
22
  s.add_dependency 'rails', '~>3.0'
23
23
  s.add_dependency 'bcrypt-ruby', '~>2.1.4'
24
24
 
25
+ s.add_development_dependency 'rails', '>=3.0.4' # so we can test CSRF protection
25
26
  s.add_development_dependency 'sqlite3-ruby'
26
27
  s.add_development_dependency 'capybara', '>= 0.4.0'
27
28
  s.add_development_dependency 'launchy'
@@ -8,4 +8,13 @@ class ArticlesController < ApplicationController
8
8
  def new
9
9
  @article = Article.new
10
10
  end
11
+
12
+ def create
13
+ @article = Article.new params[:article]
14
+ if @article.save
15
+ redirect_to :action => 'index'
16
+ else
17
+ render 'new'
18
+ end
19
+ end
11
20
  end
@@ -1 +1,11 @@
1
1
  <h1>New Article</h1>
2
+
3
+ <%= form_for @article do |f| %>
4
+ <%= f.label :title %>
5
+ <%= f.text_field :title %>
6
+
7
+ <%= f.label :content %>
8
+ <%= f.text_area :content %>
9
+
10
+ <%= f.submit %>
11
+ <% end %>
@@ -17,8 +17,8 @@ Dummy::Application.configure do
17
17
  # Raise exceptions instead of rendering exception templates
18
18
  config.action_dispatch.show_exceptions = false
19
19
 
20
- # Disable request forgery protection in test environment
21
- config.action_controller.allow_forgery_protection = false
20
+ # Enable request forgery protection in test environment
21
+ config.action_controller.allow_forgery_protection = true
22
22
 
23
23
  # Tell Action Mailer not to deliver emails to the real world.
24
24
  # The :test delivery method accumulates sent emails in the
@@ -69,29 +69,4 @@ class CookieTest < ActiveSupport::IntegrationCase
69
69
  visit new_article_path
70
70
  assert_equal sign_in_path, current_path
71
71
  end
72
-
73
-
74
- #
75
- # Code below from https://github.com/nruth/show_me_the_cookies
76
- #
77
-
78
- def delete_cookie(cookie_name)
79
- cookie_jar.instance_variable_get(:@cookies).reject! do |existing_cookie|
80
- existing_cookie.name.downcase == cookie_name
81
- end
82
- end
83
-
84
- def get_cookie(cookie_name)
85
- cookie_jar.instance_variable_get(:@cookies).select do |existing_cookie|
86
- existing_cookie.name.downcase == cookie_name
87
- end.first
88
- end
89
-
90
- def cookie_jar
91
- Capybara.current_session.driver.current_session.instance_variable_get(:@rack_mock_session).cookie_jar
92
- end
93
-
94
- def close_browser
95
- delete_cookie Rails.application.config.session_options[:key]
96
- end
97
72
  end
@@ -0,0 +1,41 @@
1
+ require 'test_helper'
2
+
3
+ class CsrfTest < ActionController::IntegrationTest
4
+ setup do
5
+ reset_quo_vadis_configuration
6
+ end
7
+
8
+ test 'cookies are destroyed on unverified requests' do
9
+ user_factory 'Bob', 'bob', 'secret'
10
+ # sign in
11
+ post sign_in_path, :username => 'bob', :password => 'secret'
12
+ get new_article_path
13
+ assert_equal new_article_path, path
14
+
15
+ # mimic closing browser
16
+ session.clear
17
+
18
+ # assert remember me cookie is still set
19
+ assert !cookies['remember_me'].blank?
20
+
21
+ # go to new article page, to start new session, and create article
22
+ get_via_redirect new_article_path
23
+ assert_equal new_article_path, path
24
+ assert_difference 'Article.count' do
25
+ post articles_path, :article => {:title => 'My article'}, :authenticity_token => session[:_csrf_token]
26
+ end
27
+
28
+ # assert remember me cookie is still set
29
+ assert !cookies['remember_me'].blank?
30
+
31
+ # make unverified request
32
+ assert_no_difference 'Article.count' do
33
+ post articles_path, :article => {:title => 'My article'}, :authenticity_token => 'INVALID'
34
+ end
35
+
36
+ # assert we are signed out, both at session level and cookie level.
37
+ assert cookies['remember_me'].blank?
38
+ get_via_redirect new_article_path
39
+ assert_equal sign_in_path, path
40
+ end
41
+ end
data/test/test_helper.rb CHANGED
@@ -54,3 +54,28 @@ def reset_quo_vadis_configuration
54
54
  QuoVadis.subject = 'Change your password'
55
55
  QuoVadis.remember_for = 2.weeks
56
56
  end
57
+
58
+
59
+ #
60
+ # Code below from https://github.com/nruth/show_me_the_cookies
61
+ #
62
+
63
+ def delete_cookie(cookie_name)
64
+ cookie_jar.instance_variable_get(:@cookies).reject! do |existing_cookie|
65
+ existing_cookie.name.downcase == cookie_name
66
+ end
67
+ end
68
+
69
+ def get_cookie(cookie_name)
70
+ cookie_jar.instance_variable_get(:@cookies).select do |existing_cookie|
71
+ existing_cookie.name.downcase == cookie_name
72
+ end.first
73
+ end
74
+
75
+ def cookie_jar
76
+ Capybara.current_session.driver.current_session.instance_variable_get(:@rack_mock_session).cookie_jar
77
+ end
78
+
79
+ def close_browser
80
+ delete_cookie Rails.application.config.session_options[:key]
81
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quo_vadis
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 31
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 3
10
- version: 1.0.3
9
+ - 4
10
+ version: 1.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Andy Stewart
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-02-07 00:00:00 +00:00
18
+ date: 2011-02-22 00:00:00 +00:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -50,9 +50,25 @@ dependencies:
50
50
  type: :runtime
51
51
  version_requirements: *id002
52
52
  - !ruby/object:Gem::Dependency
53
- name: sqlite3-ruby
53
+ name: rails
54
54
  prerelease: false
55
55
  requirement: &id003 !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ hash: 15
61
+ segments:
62
+ - 3
63
+ - 0
64
+ - 4
65
+ version: 3.0.4
66
+ type: :development
67
+ version_requirements: *id003
68
+ - !ruby/object:Gem::Dependency
69
+ name: sqlite3-ruby
70
+ prerelease: false
71
+ requirement: &id004 !ruby/object:Gem::Requirement
56
72
  none: false
57
73
  requirements:
58
74
  - - ">="
@@ -62,11 +78,11 @@ dependencies:
62
78
  - 0
63
79
  version: "0"
64
80
  type: :development
65
- version_requirements: *id003
81
+ version_requirements: *id004
66
82
  - !ruby/object:Gem::Dependency
67
83
  name: capybara
68
84
  prerelease: false
69
- requirement: &id004 !ruby/object:Gem::Requirement
85
+ requirement: &id005 !ruby/object:Gem::Requirement
70
86
  none: false
71
87
  requirements:
72
88
  - - ">="
@@ -78,11 +94,11 @@ dependencies:
78
94
  - 0
79
95
  version: 0.4.0
80
96
  type: :development
81
- version_requirements: *id004
97
+ version_requirements: *id005
82
98
  - !ruby/object:Gem::Dependency
83
99
  name: launchy
84
100
  prerelease: false
85
- requirement: &id005 !ruby/object:Gem::Requirement
101
+ requirement: &id006 !ruby/object:Gem::Requirement
86
102
  none: false
87
103
  requirements:
88
104
  - - ">="
@@ -92,7 +108,7 @@ dependencies:
92
108
  - 0
93
109
  version: "0"
94
110
  type: :development
95
- version_requirements: *id005
111
+ version_requirements: *id006
96
112
  description: Simple username/password authentication for Rails 3.
97
113
  email:
98
114
  - boss@airbladesoftware.com
@@ -104,6 +120,7 @@ extra_rdoc_files: []
104
120
 
105
121
  files:
106
122
  - .gitignore
123
+ - CHANGELOG.md
107
124
  - Gemfile
108
125
  - Gemfile.lock
109
126
  - README.md
@@ -178,6 +195,7 @@ files:
178
195
  - test/integration/authenticate_test.rb
179
196
  - test/integration/config_test.rb
180
197
  - test/integration/cookie_test.rb
198
+ - test/integration/csrf_test.rb
181
199
  - test/integration/forgotten_test.rb
182
200
  - test/integration/helper_test.rb
183
201
  - test/integration/locale_test.rb
@@ -280,6 +298,7 @@ test_files:
280
298
  - test/integration/authenticate_test.rb
281
299
  - test/integration/config_test.rb
282
300
  - test/integration/cookie_test.rb
301
+ - test/integration/csrf_test.rb
283
302
  - test/integration/forgotten_test.rb
284
303
  - test/integration/helper_test.rb
285
304
  - test/integration/locale_test.rb