devise 2.0.2 → 2.0.4

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of devise might be problematic. Click here for more details.

@@ -1,7 +1,20 @@
1
- == 2.0.2
1
+ == 2.0.4
2
2
 
3
3
  Notes: https://github.com/plataformatec/devise/wiki/How-To:-Upgrade-to-Devise-2.0
4
4
 
5
+ * bug fix
6
+ * Fix a regression that caused Warden to be initialized too late
7
+
8
+ == 2.0.3 (yanked)
9
+
10
+ * bug fix
11
+ * Ensure warning is not shown by mistake on apps with mounted engines
12
+ * Fixes related to remember_token and rememberable_options
13
+ * Ensure serializable_hash does not depend on accessible attributes
14
+ * Ensure that timeout callback does not run on sign out action
15
+
16
+ == 2.0.2
17
+
5
18
  * enhancements
6
19
  * Add devise_i18n_options to customize I18n message
7
20
 
@@ -106,7 +119,7 @@ Notes: https://github.com/plataformatec/devise/wiki/How-To:-Upgrade-to-Devise-2.
106
119
  * bug fix
107
120
  * Fix backward incompatible change from 1.4.6 for those using custom controllers
108
121
 
109
- == 1.4.6
122
+ == 1.4.6 (yanked)
110
123
 
111
124
  * enhancements
112
125
  * Allow devise_for :skip => :all
@@ -1,11 +1,11 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- devise (2.0.1)
4
+ devise (2.0.2)
5
5
  bcrypt-ruby (~> 3.0)
6
6
  orm_adapter (~> 0.0.3)
7
7
  railties (~> 3.1)
8
- warden (~> 1.1)
8
+ warden (~> 1.1.1)
9
9
 
10
10
  GEM
11
11
  remote: http://rubygems.org/
@@ -137,7 +137,7 @@ GEM
137
137
  polyglot
138
138
  polyglot (>= 0.3.1)
139
139
  tzinfo (0.3.31)
140
- warden (1.1.0)
140
+ warden (1.1.1)
141
141
  rack (>= 1.0)
142
142
  webrat (0.7.2)
143
143
  nokogiri (>= 1.2.0)
@@ -19,10 +19,9 @@ class Devise::SessionsController < DeviseController
19
19
 
20
20
  # DELETE /resource/sign_out
21
21
  def destroy
22
- signed_in = signed_in?(resource_name)
23
22
  redirect_path = after_sign_out_path_for(resource_name)
24
- Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name)
25
- set_flash_message :notice, :signed_out if signed_in
23
+ signed_out = (Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name))
24
+ set_flash_message :notice, :signed_out if signed_out
26
25
 
27
26
  # We actually need to hardcode this as Rails default responder doesn't
28
27
  # support returning empty response on GET request
@@ -18,7 +18,7 @@ Gem::Specification.new do |s|
18
18
  s.test_files = `git ls-files -- test/*`.split("\n")
19
19
  s.require_paths = ["lib"]
20
20
 
21
- s.add_dependency("warden", "~> 1.1")
21
+ s.add_dependency("warden", "~> 1.1.1")
22
22
  s.add_dependency("orm_adapter", "~> 0.0.3")
23
23
  s.add_dependency("bcrypt-ruby", "~> 3.0")
24
24
  s.add_dependency("railties", "~> 3.1")
@@ -0,0 +1,169 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ devise (2.0.2)
5
+ bcrypt-ruby (~> 3.0)
6
+ orm_adapter (~> 0.0.3)
7
+ railties (~> 3.1)
8
+ warden (~> 1.1.1)
9
+
10
+ GEM
11
+ remote: http://rubygems.org/
12
+ specs:
13
+ actionmailer (3.1.3)
14
+ actionpack (= 3.1.3)
15
+ mail (~> 2.3.0)
16
+ actionpack (3.1.3)
17
+ activemodel (= 3.1.3)
18
+ activesupport (= 3.1.3)
19
+ builder (~> 3.0.0)
20
+ erubis (~> 2.7.0)
21
+ i18n (~> 0.6)
22
+ rack (~> 1.3.5)
23
+ rack-cache (~> 1.1)
24
+ rack-mount (~> 0.8.2)
25
+ rack-test (~> 0.6.1)
26
+ sprockets (~> 2.0.3)
27
+ activemodel (3.1.3)
28
+ activesupport (= 3.1.3)
29
+ builder (~> 3.0.0)
30
+ i18n (~> 0.6)
31
+ activerecord (3.1.3)
32
+ activemodel (= 3.1.3)
33
+ activesupport (= 3.1.3)
34
+ arel (~> 2.2.1)
35
+ tzinfo (~> 0.3.29)
36
+ activeresource (3.1.3)
37
+ activemodel (= 3.1.3)
38
+ activesupport (= 3.1.3)
39
+ activesupport (3.1.3)
40
+ multi_json (~> 1.0)
41
+ addressable (2.2.7)
42
+ arel (2.2.1)
43
+ bcrypt-ruby (3.0.1)
44
+ bson (1.5.2)
45
+ bson_ext (1.3.1)
46
+ builder (3.0.0)
47
+ columnize (0.3.6)
48
+ erubis (2.7.0)
49
+ faraday (0.7.6)
50
+ addressable (~> 2.2)
51
+ multipart-post (~> 1.1)
52
+ rack (~> 1.1)
53
+ hashie (1.2.0)
54
+ hike (1.2.1)
55
+ i18n (0.6.0)
56
+ json (1.6.5)
57
+ linecache (0.46)
58
+ rbx-require-relative (> 0.0.4)
59
+ mail (2.3.0)
60
+ i18n (>= 0.4.0)
61
+ mime-types (~> 1.16)
62
+ treetop (~> 1.4.8)
63
+ metaclass (0.0.1)
64
+ mime-types (1.17.2)
65
+ mocha (0.10.4)
66
+ metaclass (~> 0.0.1)
67
+ mongo (1.3.1)
68
+ bson (>= 1.3.1)
69
+ mongoid (2.4.4)
70
+ activemodel (~> 3.1)
71
+ mongo (~> 1.3)
72
+ tzinfo (~> 0.3.22)
73
+ multi_json (1.0.4)
74
+ multipart-post (1.1.5)
75
+ nokogiri (1.5.0)
76
+ oauth2 (0.5.2)
77
+ faraday (~> 0.7)
78
+ multi_json (~> 1.0)
79
+ omniauth (1.0.2)
80
+ hashie (~> 1.2)
81
+ rack
82
+ omniauth-facebook (1.2.0)
83
+ omniauth-oauth2 (~> 1.0.0)
84
+ omniauth-oauth2 (1.0.0)
85
+ oauth2 (~> 0.5.0)
86
+ omniauth (~> 1.0)
87
+ omniauth-openid (1.0.1)
88
+ omniauth (~> 1.0)
89
+ rack-openid (~> 1.3.1)
90
+ orm_adapter (0.0.6)
91
+ polyglot (0.3.3)
92
+ rack (1.3.6)
93
+ rack-cache (1.1)
94
+ rack (>= 0.4)
95
+ rack-mount (0.8.3)
96
+ rack (>= 1.0.0)
97
+ rack-openid (1.3.1)
98
+ rack (>= 1.1.0)
99
+ ruby-openid (>= 2.1.8)
100
+ rack-ssl (1.3.2)
101
+ rack
102
+ rack-test (0.6.1)
103
+ rack (>= 1.0)
104
+ rails (3.1.3)
105
+ actionmailer (= 3.1.3)
106
+ actionpack (= 3.1.3)
107
+ activerecord (= 3.1.3)
108
+ activeresource (= 3.1.3)
109
+ activesupport (= 3.1.3)
110
+ bundler (~> 1.0)
111
+ railties (= 3.1.3)
112
+ railties (3.1.3)
113
+ actionpack (= 3.1.3)
114
+ activesupport (= 3.1.3)
115
+ rack-ssl (~> 1.3.2)
116
+ rake (>= 0.8.7)
117
+ rdoc (~> 3.4)
118
+ thor (~> 0.14.6)
119
+ rake (0.9.2.2)
120
+ rbx-require-relative (0.0.5)
121
+ rdoc (3.12)
122
+ json (~> 1.4)
123
+ ruby-debug (0.10.4)
124
+ columnize (>= 0.1)
125
+ ruby-debug-base (~> 0.10.4.0)
126
+ ruby-debug-base (0.10.4)
127
+ linecache (>= 0.3)
128
+ ruby-openid (2.1.8)
129
+ sprockets (2.0.3)
130
+ hike (~> 1.2)
131
+ rack (~> 1.0)
132
+ tilt (~> 1.1, != 1.3.0)
133
+ sqlite3 (1.3.5)
134
+ sqlite3-ruby (1.3.3)
135
+ sqlite3 (>= 1.3.3)
136
+ thor (0.14.6)
137
+ tilt (1.3.3)
138
+ treetop (1.4.10)
139
+ polyglot
140
+ polyglot (>= 0.3.1)
141
+ tzinfo (0.3.31)
142
+ warden (1.1.1)
143
+ rack (>= 1.0)
144
+ webrat (0.7.2)
145
+ nokogiri (>= 1.2.0)
146
+ rack (>= 1.0)
147
+ rack-test (>= 0.5.3)
148
+
149
+ PLATFORMS
150
+ ruby
151
+
152
+ DEPENDENCIES
153
+ activerecord-jdbc-adapter
154
+ activerecord-jdbcsqlite3-adapter
155
+ bson_ext (~> 1.3.0)
156
+ devise!
157
+ jruby-openssl
158
+ mocha
159
+ mongo (~> 1.3.0)
160
+ mongoid (~> 2.0)
161
+ omniauth (~> 1.0.0)
162
+ omniauth-facebook
163
+ omniauth-oauth2 (~> 1.0.0)
164
+ omniauth-openid (~> 1.0.1)
165
+ rails (~> 3.1.0)
166
+ rdoc
167
+ ruby-debug (>= 0.10.3)
168
+ sqlite3-ruby
169
+ webrat (= 0.7.2)
@@ -10,7 +10,6 @@ module Devise
10
10
  autoload :FailureApp, 'devise/failure_app'
11
11
  autoload :OmniAuth, 'devise/omniauth'
12
12
  autoload :ParamFilter, 'devise/param_filter'
13
- autoload :PathChecker, 'devise/path_checker'
14
13
  autoload :Schema, 'devise/schema'
15
14
  autoload :TestHelpers, 'devise/test_helpers'
16
15
 
@@ -63,8 +62,8 @@ module Devise
63
62
  }
64
63
 
65
64
  # Custom domain for cookies. Not set by default
66
- mattr_accessor :cookie_options
67
- @@cookie_options = {}
65
+ mattr_accessor :rememberable_options
66
+ @@rememberable_options = {}
68
67
 
69
68
  # The number of times to encrypt password.
70
69
  mattr_accessor :stretches
@@ -244,6 +243,11 @@ module Devise
244
243
  Devise.allow_unconfirmed_access_for = value
245
244
  end
246
245
 
246
+ def self.cookie_options=(value)
247
+ warn "\n[DEVISE] Devise.cookie_options= is deprecated. Please set Devise.rememberable_options= instead.\n"
248
+ Devise.rememberable_options = value
249
+ end
250
+
247
251
  def self.stateless_token=(value)
248
252
  warn "\n[DEVISE] Devise.stateless_token= is deprecated. Please append :token_auth to Devise.skip_session_storage " \
249
253
  "instead, for example: Devise.skip_session_storage << :token_auth\n"
@@ -126,7 +126,8 @@ module Devise
126
126
  end
127
127
 
128
128
  # Sign out a given user or scope. This helper is useful for signing out a user
129
- # after deleting accounts.
129
+ # after deleting accounts. Returns true if there was a logout and false if there is no user logged in
130
+ # on the referred scope
130
131
  #
131
132
  # Examples:
132
133
  #
@@ -136,19 +137,26 @@ module Devise
136
137
  def sign_out(resource_or_scope=nil)
137
138
  return sign_out_all_scopes unless resource_or_scope
138
139
  scope = Devise::Mapping.find_scope!(resource_or_scope)
139
- warden.user(scope) # Without loading user here, before_logout hook is not called
140
+ user = warden.user(:scope => scope, :run_callbacks => false) # If there is no user
141
+
140
142
  warden.raw_session.inspect # Without this inspect here. The session does not clear.
141
143
  warden.logout(scope)
142
144
  instance_variable_set(:"@current_#{scope}", nil)
145
+
146
+ !!user
143
147
  end
144
148
 
145
149
  # Sign out all active users or scopes. This helper is useful for signing out all roles
146
- # in one click. This signs out ALL scopes in warden.
150
+ # in one click. This signs out ALL scopes in warden. Returns true if there was at least one logout
151
+ # and false if there was no user logged in on all scopes.
147
152
  def sign_out_all_scopes
148
- Devise.mappings.keys.each { |s| warden.user(s) }
153
+ users = Devise.mappings.keys.map { |s| warden.user(:scope => s, :run_callbacks => false) }
154
+
149
155
  warden.raw_session.inspect
150
156
  warden.logout
151
157
  expire_devise_cached_variables!
158
+
159
+ users.any?
152
160
  end
153
161
 
154
162
  # Returns and delete the url stored in the session for the given scope. Useful
@@ -36,7 +36,7 @@ module Devise
36
36
  protected
37
37
 
38
38
  def forget_cookie_values(resource)
39
- Devise::Controllers::Rememberable.cookie_values.merge!(resource.cookie_options)
39
+ Devise::Controllers::Rememberable.cookie_values.merge!(resource.rememberable_options)
40
40
  end
41
41
 
42
42
  def remember_cookie_values(resource)
@@ -10,11 +10,8 @@ Warden::Manager.after_set_user do |record, warden, options|
10
10
  last_request_at = warden.session(scope)['last_request_at']
11
11
 
12
12
  if record.timedout?(last_request_at)
13
- path_checker = Devise::PathChecker.new(warden.env, scope)
14
- unless path_checker.signing_out?
15
- warden.logout(scope)
16
- throw :warden, :scope => scope, :message => :timeout
17
- end
13
+ warden.logout(scope)
14
+ throw :warden, :scope => scope, :message => :timeout
18
15
  end
19
16
 
20
17
  unless warden.request.env['devise.skip_trackable']
@@ -1,5 +1,4 @@
1
1
  require 'devise/hooks/activatable'
2
- require 'devise/models/serializable'
3
2
 
4
3
  module Devise
5
4
  module Models
@@ -52,7 +51,10 @@ module Devise
52
51
  module Authenticatable
53
52
  extend ActiveSupport::Concern
54
53
 
55
- include Devise::Models::Serializable
54
+ BLACKLIST_FOR_SERIALIZATION = [:encrypted_password, :reset_password_token, :reset_password_sent_at,
55
+ :remember_created_at, :sign_in_count, :current_sign_in_at, :last_sign_in_at, :current_sign_in_ip,
56
+ :last_sign_in_ip, :password_salt, :confirmation_token, :confirmed_at, :confirmation_sent_at,
57
+ :unconfirmed_email, :failed_attempts, :unlock_token, :locked_at, :authentication_token]
56
58
 
57
59
  included do
58
60
  class_attribute :devise_modules, :instance_writer => false
@@ -99,6 +101,31 @@ module Devise
99
101
  (self.class.strip_whitespace_keys || []).each { |k| self[k].try(:strip!) }
100
102
  end
101
103
 
104
+ array = %w(serializable_hash)
105
+ # to_xml does not call serializable_hash on 3.1
106
+ array << "to_xml" if Rails::VERSION::STRING[0,3] == "3.1"
107
+
108
+ array.each do |method|
109
+ class_eval <<-RUBY, __FILE__, __LINE__
110
+ # Redefine to_xml and serializable_hash in models for more secure defaults.
111
+ # By default, it removes from the serializable model all attributes that
112
+ # are *not* accessible. You can remove this default by using :force_except
113
+ # and passing a new list of attributes you want to exempt. All attributes
114
+ # given to :except will simply add names to exempt to Devise internal list.
115
+ def #{method}(options=nil)
116
+ options ||= {}
117
+ options[:except] = Array(options[:except])
118
+
119
+ if options[:force_except]
120
+ options[:except].concat Array(options[:force_except])
121
+ else
122
+ options[:except].concat BLACKLIST_FOR_SERIALIZATION
123
+ end
124
+ super(options)
125
+ end
126
+ RUBY
127
+ end
128
+
102
129
  module ClassMethods
103
130
  Devise::Models.config(self, :authentication_keys, :request_keys, :strip_whitespace_keys,
104
131
  :case_insensitive_keys, :http_authenticatable, :params_authenticatable, :skip_session_storage)
@@ -44,6 +44,7 @@ module Devise
44
44
  # Generate a new remember token and save the record without validations
45
45
  # unless remember_across_browsers is true and the user already has a valid token.
46
46
  def remember_me!(extend_period=false)
47
+ self.remember_token = self.class.remember_token if generate_remember_token?
47
48
  self.remember_created_at = Time.now.utc if generate_remember_timestamp?(extend_period)
48
49
  save(:validate => false)
49
50
  end
@@ -51,11 +52,10 @@ module Devise
51
52
  # If the record is persisted, remove the remember token (but only if
52
53
  # it exists), and save the record without validations.
53
54
  def forget_me!
54
- if persisted?
55
- self.remember_token = nil if respond_to?(:remember_token=)
56
- self.remember_created_at = nil
57
- save(:validate => false)
58
- end
55
+ return unless persisted?
56
+ self.remember_token = nil if respond_to?(:remember_token=)
57
+ self.remember_created_at = nil
58
+ save(:validate => false)
59
59
  end
60
60
 
61
61
  # Remember token should be expired if expiration time not overpass now.
@@ -69,21 +69,28 @@ module Devise
69
69
  end
70
70
 
71
71
  def rememberable_value
72
- if salt = authenticatable_salt
72
+ if respond_to?(:remember_token)
73
+ remember_token
74
+ elsif salt = authenticatable_salt
73
75
  salt
74
76
  else
75
77
  raise "authenticable_salt returned nil for the #{self.class.name} model. " \
76
78
  "In order to use rememberable, you must ensure a password is always set " \
77
- "or implement rememberable_value in your model with your own logic."
79
+ "or have a remember_token column in your model or implement your own " \
80
+ "rememberable_value in the model with custom logic."
78
81
  end
79
82
  end
80
83
 
81
- def cookie_options
82
- self.class.cookie_options
84
+ def rememberable_options
85
+ self.class.rememberable_options
83
86
  end
84
87
 
85
88
  protected
86
89
 
90
+ def generate_remember_token?
91
+ respond_to?(:remember_token) && remember_expired?
92
+ end
93
+
87
94
  # Generate a timestamp if extend_remember_period is true, if no remember_token
88
95
  # exists, or if an existing remember token has expired.
89
96
  def generate_remember_timestamp?(extend_period) #:nodoc:
@@ -107,7 +114,7 @@ module Devise
107
114
  generate_token(:remember_token)
108
115
  end
109
116
 
110
- Devise::Models.config(self, :remember_for, :extend_remember_period, :cookie_options)
117
+ Devise::Models.config(self, :remember_for, :extend_remember_period, :rememberable_options)
111
118
  end
112
119
  end
113
120
  end
@@ -5,10 +5,10 @@ module ActionDispatch::Routing
5
5
  # Ensure Devise modules are included only after loading routes, because we
6
6
  # need devise_for mappings already declared to create filters and helpers.
7
7
  def finalize_with_devise!
8
- finalize_without_devise!
8
+ result = finalize_without_devise!
9
9
 
10
10
  @devise_finalized ||= begin
11
- if Devise.router_name.nil? && self != Rails.application.try(:routes)
11
+ if Devise.router_name.nil? && defined?(@devise_finalized) && self != Rails.application.try(:routes)
12
12
  warn "[DEVISE] We have detected that you are using devise_for inside engine routes. " \
13
13
  "In this case, you probably want to set Devise.router_name = MOUNT_POINT, where " \
14
14
  "MOUNT_POINT is a symbol representing where this engine will be mounted at. For " \
@@ -20,6 +20,8 @@ module ActionDispatch::Routing
20
20
  Devise.regenerate_helpers!
21
21
  true
22
22
  end
23
+
24
+ result
23
25
  end
24
26
  alias_method_chain :finalize!, :devise
25
27
  end
@@ -1,3 +1,3 @@
1
1
  module Devise
2
- VERSION = "2.0.2".freeze
2
+ VERSION = "2.0.4".freeze
3
3
  end
@@ -141,7 +141,7 @@ class ControllerAuthenticatableTest < ActionController::TestCase
141
141
 
142
142
  test 'sign out clears up any signed in user by scope' do
143
143
  user = User.new
144
- @mock_warden.expects(:user).with(:user).returns(user)
144
+ @mock_warden.expects(:user).with(:scope => :user, :run_callbacks => false).returns(user)
145
145
  @mock_warden.expects(:logout).with(:user).returns(true)
146
146
  @controller.instance_variable_set(:@current_user, user)
147
147
  @controller.sign_out(:user)
@@ -149,13 +149,13 @@ class ControllerAuthenticatableTest < ActionController::TestCase
149
149
  end
150
150
 
151
151
  test 'sign out proxy to logout on warden' do
152
- @mock_warden.expects(:user).with(:user).returns(true)
152
+ @mock_warden.expects(:user).with(:scope => :user, :run_callbacks => false).returns(true)
153
153
  @mock_warden.expects(:logout).with(:user).returns(true)
154
154
  @controller.sign_out(:user)
155
155
  end
156
156
 
157
157
  test 'sign out accepts a resource as argument' do
158
- @mock_warden.expects(:user).with(:user).returns(true)
158
+ @mock_warden.expects(:user).with(:scope => :user, :run_callbacks => false).returns(true)
159
159
  @mock_warden.expects(:logout).with(:user).returns(true)
160
160
  @controller.sign_out(User.new)
161
161
  end
@@ -230,7 +230,7 @@ class ControllerAuthenticatableTest < ActionController::TestCase
230
230
 
231
231
  test 'sign out and redirect uses the configured after sign out path when signing out only the current scope' do
232
232
  swap Devise, :sign_out_all_scopes => false do
233
- @mock_warden.expects(:user).with(:admin).returns(true)
233
+ @mock_warden.expects(:user).with(:scope => :admin, :run_callbacks => false).returns(true)
234
234
  @mock_warden.expects(:logout).with(:admin).returns(true)
235
235
  @controller.expects(:redirect_to).with(admin_root_path)
236
236
  @controller.instance_eval "def after_sign_out_path_for(resource); admin_root_path; end"
@@ -51,7 +51,7 @@ class RememberMeTest < ActionController::IntegrationTest
51
51
  # We test this by asserting the cookie is not sent after the redirect
52
52
  # since we changed the domain. This is the only difference with the
53
53
  # previous test.
54
- swap Devise, :cookie_options => { :domain => "omg.somewhere.com" } do
54
+ swap Devise, :rememberable_options => { :domain => "omg.somewhere.com" } do
55
55
  user = sign_in_as_user :remember_me => true
56
56
  assert_nil request.cookies["remember_user_token"]
57
57
  end
@@ -50,10 +50,12 @@ class SessionTimeoutTest < ActionController::IntegrationTest
50
50
  get expire_user_path(user)
51
51
 
52
52
  get destroy_user_session_path
53
+
53
54
  assert_response :redirect
54
55
  assert_redirected_to root_path
55
56
 
56
57
  follow_redirect!
58
+
57
59
  assert_contain 'Signed out successfully'
58
60
  end
59
61
 
@@ -6,8 +6,8 @@ class SerializableTest < ActiveSupport::TestCase
6
6
  end
7
7
 
8
8
  test 'should not include unsafe keys on XML' do
9
- assert_match /email/, @user.to_xml
10
- assert_no_match /confirmation-token/, @user.to_xml
9
+ assert_match /email/, @user.to_xml
10
+ assert_no_match /confirmation-token/, @user.to_xml
11
11
  end
12
12
 
13
13
  test 'should not include unsafe keys on XML even if a new except is provided' do
@@ -21,18 +21,28 @@ class SerializableTest < ActiveSupport::TestCase
21
21
  end
22
22
 
23
23
  test 'should not include unsafe keys on JSON' do
24
- assert_match /"email":/, @user.to_json
25
- assert_no_match /"confirmation_token":/, @user.to_json
24
+ assert_equal %w(created_at email facebook_token id updated_at username), from_json().keys.sort
26
25
  end
27
26
 
28
27
  test 'should not include unsafe keys on JSON even if a new except is provided' do
29
- assert_no_match /"email":/, @user.to_json(:except => :email)
30
- assert_no_match /"confirmation_token":/, @user.to_json(:except => :email)
28
+ assert_no_key "email", from_json(:except => :email)
29
+ assert_no_key "confirmation_token", from_json(:except => :email)
31
30
  end
32
31
 
33
32
  test 'should include unsafe keys on JSON if a force_except is provided' do
34
- assert_no_match /"email":/, @user.to_json(:force_except => :email)
35
- assert_match /"confirmation_token":/, @user.to_json(:force_except => :email)
33
+ assert_no_key "email", from_json(:force_except => :email)
34
+ assert_key "confirmation_token", from_json(:force_except => :email)
36
35
  end
37
36
 
37
+ def assert_key(key, subject)
38
+ assert subject.key?(key), "Expected #{subject.inspect} to have key #{key.inspect}"
39
+ end
40
+
41
+ def assert_no_key(key, subject)
42
+ assert !subject.key?(key), "Expected #{subject.inspect} to not have key #{key.inspect}"
43
+ end
44
+
45
+ def from_json(options=nil)
46
+ ActiveSupport::JSON.decode(@user.to_json(options))["user"]
47
+ end
38
48
  end
@@ -3,6 +3,6 @@
3
3
 
4
4
  class ApplicationController < ActionController::Base
5
5
  protect_from_forgery
6
- before_filter :current_user
6
+ before_filter :current_user, :unless => :devise_controller?
7
7
  before_filter :authenticate_user!, :if => :devise_controller?
8
8
  end
metadata CHANGED
@@ -1,94 +1,67 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: devise
3
- version: !ruby/object:Gem::Version
4
- hash: 11
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.4
5
5
  prerelease:
6
- segments:
7
- - 2
8
- - 0
9
- - 2
10
- version: 2.0.2
11
6
  platform: ruby
12
- authors:
13
- - "Jos\xC3\xA9 Valim"
14
- - "Carlos Ant\xC3\xB4nio"
7
+ authors:
8
+ - José Valim
9
+ - Carlos Antônio
15
10
  autorequire:
16
11
  bindir: bin
17
12
  cert_chain: []
18
-
19
- date: 2012-02-15 00:00:00 +01:00
20
- default_executable:
21
- dependencies:
22
- - !ruby/object:Gem::Dependency
13
+ date: 2012-02-17 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
23
16
  name: warden
24
- prerelease: false
25
- requirement: &id001 !ruby/object:Gem::Requirement
17
+ requirement: &2156392360 !ruby/object:Gem::Requirement
26
18
  none: false
27
- requirements:
19
+ requirements:
28
20
  - - ~>
29
- - !ruby/object:Gem::Version
30
- hash: 13
31
- segments:
32
- - 1
33
- - 1
34
- version: "1.1"
21
+ - !ruby/object:Gem::Version
22
+ version: 1.1.1
35
23
  type: :runtime
36
- version_requirements: *id001
37
- - !ruby/object:Gem::Dependency
38
- name: orm_adapter
39
24
  prerelease: false
40
- requirement: &id002 !ruby/object:Gem::Requirement
25
+ version_requirements: *2156392360
26
+ - !ruby/object:Gem::Dependency
27
+ name: orm_adapter
28
+ requirement: &2156391100 !ruby/object:Gem::Requirement
41
29
  none: false
42
- requirements:
30
+ requirements:
43
31
  - - ~>
44
- - !ruby/object:Gem::Version
45
- hash: 25
46
- segments:
47
- - 0
48
- - 0
49
- - 3
32
+ - !ruby/object:Gem::Version
50
33
  version: 0.0.3
51
34
  type: :runtime
52
- version_requirements: *id002
53
- - !ruby/object:Gem::Dependency
54
- name: bcrypt-ruby
55
35
  prerelease: false
56
- requirement: &id003 !ruby/object:Gem::Requirement
36
+ version_requirements: *2156391100
37
+ - !ruby/object:Gem::Dependency
38
+ name: bcrypt-ruby
39
+ requirement: &2156389800 !ruby/object:Gem::Requirement
57
40
  none: false
58
- requirements:
41
+ requirements:
59
42
  - - ~>
60
- - !ruby/object:Gem::Version
61
- hash: 7
62
- segments:
63
- - 3
64
- - 0
65
- version: "3.0"
43
+ - !ruby/object:Gem::Version
44
+ version: '3.0'
66
45
  type: :runtime
67
- version_requirements: *id003
68
- - !ruby/object:Gem::Dependency
69
- name: railties
70
46
  prerelease: false
71
- requirement: &id004 !ruby/object:Gem::Requirement
47
+ version_requirements: *2156389800
48
+ - !ruby/object:Gem::Dependency
49
+ name: railties
50
+ requirement: &2156387120 !ruby/object:Gem::Requirement
72
51
  none: false
73
- requirements:
52
+ requirements:
74
53
  - - ~>
75
- - !ruby/object:Gem::Version
76
- hash: 5
77
- segments:
78
- - 3
79
- - 1
80
- version: "3.1"
54
+ - !ruby/object:Gem::Version
55
+ version: '3.1'
81
56
  type: :runtime
82
- version_requirements: *id004
57
+ prerelease: false
58
+ version_requirements: *2156387120
83
59
  description: Flexible authentication solution for Rails with Warden
84
60
  email: contact@plataformatec.com.br
85
61
  executables: []
86
-
87
62
  extensions: []
88
-
89
63
  extra_rdoc_files: []
90
-
91
- files:
64
+ files:
92
65
  - .gitignore
93
66
  - .travis.yml
94
67
  - CHANGELOG.rdoc
@@ -121,6 +94,7 @@ files:
121
94
  - config/locales/en.yml
122
95
  - devise.gemspec
123
96
  - gemfiles/Gemfile.rails-3.1.x
97
+ - gemfiles/Gemfile.rails-3.1.x.lock
124
98
  - lib/devise.rb
125
99
  - lib/devise/controllers/helpers.rb
126
100
  - lib/devise/controllers/rememberable.rb
@@ -151,7 +125,6 @@ files:
151
125
  - lib/devise/models/recoverable.rb
152
126
  - lib/devise/models/registerable.rb
153
127
  - lib/devise/models/rememberable.rb
154
- - lib/devise/models/serializable.rb
155
128
  - lib/devise/models/timeoutable.rb
156
129
  - lib/devise/models/token_authenticatable.rb
157
130
  - lib/devise/models/trackable.rb
@@ -163,7 +136,6 @@ files:
163
136
  - lib/devise/orm/active_record.rb
164
137
  - lib/devise/orm/mongoid.rb
165
138
  - lib/devise/param_filter.rb
166
- - lib/devise/path_checker.rb
167
139
  - lib/devise/rails.rb
168
140
  - lib/devise/rails/routes.rb
169
141
  - lib/devise/rails/warden_compat.rb
@@ -242,7 +214,6 @@ files:
242
214
  - test/omniauth/url_helpers_test.rb
243
215
  - test/orm/active_record.rb
244
216
  - test/orm/mongoid.rb
245
- - test/path_checker_test.rb
246
217
  - test/rails_app/Rakefile
247
218
  - test/rails_app/app/active_record/admin.rb
248
219
  - test/rails_app/app/active_record/shim.rb
@@ -301,41 +272,31 @@ files:
301
272
  - test/support/webrat/integrations/rails.rb
302
273
  - test/test_helper.rb
303
274
  - test/test_helpers_test.rb
304
- has_rdoc: true
305
275
  homepage: http://github.com/plataformatec/devise
306
276
  licenses: []
307
-
308
277
  post_install_message:
309
278
  rdoc_options: []
310
-
311
- require_paths:
279
+ require_paths:
312
280
  - lib
313
- required_ruby_version: !ruby/object:Gem::Requirement
281
+ required_ruby_version: !ruby/object:Gem::Requirement
314
282
  none: false
315
- requirements:
316
- - - ">="
317
- - !ruby/object:Gem::Version
318
- hash: 3
319
- segments:
320
- - 0
321
- version: "0"
322
- required_rubygems_version: !ruby/object:Gem::Requirement
283
+ requirements:
284
+ - - ! '>='
285
+ - !ruby/object:Gem::Version
286
+ version: '0'
287
+ required_rubygems_version: !ruby/object:Gem::Requirement
323
288
  none: false
324
- requirements:
325
- - - ">="
326
- - !ruby/object:Gem::Version
327
- hash: 3
328
- segments:
329
- - 0
330
- version: "0"
289
+ requirements:
290
+ - - ! '>='
291
+ - !ruby/object:Gem::Version
292
+ version: '0'
331
293
  requirements: []
332
-
333
294
  rubyforge_project: devise
334
- rubygems_version: 1.5.3
295
+ rubygems_version: 1.8.15
335
296
  signing_key:
336
297
  specification_version: 3
337
298
  summary: Flexible authentication solution for Rails with Warden
338
- test_files:
299
+ test_files:
339
300
  - test/controllers/helpers_test.rb
340
301
  - test/controllers/internal_helpers_test.rb
341
302
  - test/controllers/sessions_controller_test.rb
@@ -383,7 +344,6 @@ test_files:
383
344
  - test/omniauth/url_helpers_test.rb
384
345
  - test/orm/active_record.rb
385
346
  - test/orm/mongoid.rb
386
- - test/path_checker_test.rb
387
347
  - test/rails_app/Rakefile
388
348
  - test/rails_app/app/active_record/admin.rb
389
349
  - test/rails_app/app/active_record/shim.rb
@@ -1,46 +0,0 @@
1
- module Devise
2
- module Models
3
- # This module redefine to_xml and serializable_hash in models for more
4
- # secure defaults. By default, it removes from the serializable model
5
- # all attributes that are *not* accessible. You can remove this default
6
- # by using :force_except and passing a new list of attributes you want
7
- # to exempt. All attributes given to :except will simply add names to
8
- # exempt to Devise internal list.
9
- module Serializable
10
- extend ActiveSupport::Concern
11
-
12
- array = %w(serializable_hash)
13
- # to_xml does not call serializable_hash on 3.1
14
- array << "to_xml" if Rails::VERSION::STRING[0,3] == "3.1"
15
-
16
- array.each do |method|
17
- class_eval <<-RUBY, __FILE__, __LINE__
18
- def #{method}(options=nil)
19
- options ||= {}
20
- if options.key?(:force_except)
21
- options[:except] = options.delete(:force_except)
22
- super(options)
23
- elsif self.class.blacklist_keys?
24
- except = Array(options[:except])
25
- super(options.merge(:except => except + self.class.blacklist_keys))
26
- else
27
- super
28
- end
29
- end
30
- RUBY
31
- end
32
-
33
- module ClassMethods
34
- # Return true if we can retrieve blacklist keys from the record.
35
- def blacklist_keys?
36
- @has_except_keys ||= respond_to?(:accessible_attributes) && !accessible_attributes.to_a.empty?
37
- end
38
-
39
- # Returns keys that should be removed when serializing the record.
40
- def blacklist_keys
41
- @blacklist_keys ||= to_adapter.column_names.map(&:to_s) - accessible_attributes.to_a.map(&:to_s)
42
- end
43
- end
44
- end
45
- end
46
- end
@@ -1,23 +0,0 @@
1
- module Devise
2
- class PathChecker
3
- include Rails.application.routes.url_helpers
4
-
5
- def self.default_url_options(*args)
6
- if defined?(ApplicationController)
7
- ApplicationController.default_url_options(*args)
8
- else
9
- {}
10
- end
11
- end
12
-
13
- def initialize(env, scope)
14
- @current_path = "/#{env["SCRIPT_NAME"]}/#{env["PATH_INFO"]}".squeeze("/")
15
- @scope = scope
16
- end
17
-
18
- def signing_out?
19
- route = "destroy_#{@scope}_session_path"
20
- respond_to?(route) && @current_path == send(route)
21
- end
22
- end
23
- end
@@ -1,21 +0,0 @@
1
- require 'test_helper'
2
-
3
- class PathCheckerTest < ActiveSupport::TestCase
4
- test 'check if sign out path matches' do
5
- path_checker = Devise::PathChecker.new({"PATH_INFO" => "/users/sign_out"}, :user)
6
- assert path_checker.signing_out?
7
-
8
- path_checker = Devise::PathChecker.new({"PATH_INFO" => "/users/sign_in"}, :user)
9
- assert_not path_checker.signing_out?
10
- end
11
-
12
- test 'considers script name' do
13
- path_checker = Devise::PathChecker.new({"SCRIPT_NAME" => "/users", "PATH_INFO" => "/sign_out"}, :user)
14
- assert path_checker.signing_out?
15
- end
16
-
17
- test 'ignores invalid routes' do
18
- path_checker = Devise::PathChecker.new({"PATH_INFO" => "/users/sign_in"}, :omg)
19
- assert_not path_checker.signing_out?
20
- end
21
- end