Do not add unlock routes unless unlock strategy is email or both, closes #373
This commit is contained in:
parent
a87bc4a861
commit
2602ef41cf
|
@ -10,6 +10,7 @@
|
||||||
* Fix a bug in Devise::TestHelpers where current_user was returning a Response object for non active accounts
|
* Fix a bug in Devise::TestHelpers where current_user was returning a Response object for non active accounts
|
||||||
* Devise should respect script_name and path_info contracts
|
* Devise should respect script_name and path_info contracts
|
||||||
* Fix a bug when accessing a path with (.:format) (by github.com/klacointe)
|
* Fix a bug when accessing a path with (.:format) (by github.com/klacointe)
|
||||||
|
* Do not add unlock routes unless unlock strategy is email or both
|
||||||
|
|
||||||
* deprecations
|
* deprecations
|
||||||
* use_default_scope is deprecated and has no effect. Use :as or :devise_scope in the router instead
|
* use_default_scope is deprecated and has no effect. Use :as or :devise_scope in the router instead
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
class Devise::UnlocksController < ApplicationController
|
class Devise::UnlocksController < ApplicationController
|
||||||
prepend_before_filter :ensure_email_as_unlock_strategy
|
|
||||||
prepend_before_filter :require_no_authentication
|
prepend_before_filter :require_no_authentication
|
||||||
include Devise::Controllers::InternalHelpers
|
include Devise::Controllers::InternalHelpers
|
||||||
|
|
||||||
|
@ -32,10 +31,4 @@ class Devise::UnlocksController < ApplicationController
|
||||||
render_with_scope :new
|
render_with_scope :new
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
|
||||||
|
|
||||||
def ensure_email_as_unlock_strategy
|
|
||||||
raise ActionController::UnknownAction unless resource_class.unlock_strategy_enabled?(:email)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -220,8 +220,10 @@ module ActionDispatch::Routing
|
||||||
end
|
end
|
||||||
|
|
||||||
def devise_unlock(mapping, controllers) #:nodoc:
|
def devise_unlock(mapping, controllers) #:nodoc:
|
||||||
resource :unlock, :only => [:new, :create, :show],
|
if mapping.to.unlock_strategy_enabled?(:email)
|
||||||
:path => mapping.path_names[:unlock], :controller => controllers[:unlocks]
|
resource :unlock, :only => [:new, :create, :show],
|
||||||
|
:path => mapping.path_names[:unlock], :controller => controllers[:unlocks]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def devise_registration(mapping, controllers) #:nodoc:
|
def devise_registration(mapping, controllers) #:nodoc:
|
||||||
|
|
|
@ -37,27 +37,25 @@ class LockTest < ActionController::IntegrationTest
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'unlocked pages should not be available if email strategy is disabled' do
|
test 'unlocked pages should not be available if email strategy is disabled' do
|
||||||
visit "/users/sign_in"
|
visit "/admins/sign_in"
|
||||||
click_link "Didn't receive unlock instructions?"
|
|
||||||
|
|
||||||
swap Devise, :unlock_strategy => :time do
|
assert_raise Webrat::NotFoundError do
|
||||||
visit "/users/sign_in"
|
click_link "Didn't receive unlock instructions?"
|
||||||
|
|
||||||
assert_raise Webrat::NotFoundError do
|
|
||||||
click_link "Didn't receive unlock instructions?"
|
|
||||||
end
|
|
||||||
|
|
||||||
assert_raise AbstractController::ActionNotFound do
|
|
||||||
visit new_user_unlock_path
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
assert_raise NameError do
|
||||||
|
visit new_admin_unlock_path
|
||||||
|
end
|
||||||
|
|
||||||
|
visit "/admins/unlock/new"
|
||||||
|
assert_response :not_found
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'user with invalid unlock token should not be able to unlock an account' do
|
test 'user with invalid unlock token should not be able to unlock an account' do
|
||||||
visit_user_unlock_with_token('invalid_token')
|
visit_user_unlock_with_token('invalid_token')
|
||||||
|
|
||||||
assert_response :success
|
assert_response :success
|
||||||
assert_template 'unlocks/new'
|
assert_current_url '/users/unlock?unlock_token=invalid_token'
|
||||||
assert_have_selector '#error_explanation'
|
assert_have_selector '#error_explanation'
|
||||||
assert_contain /Unlock token(.*)invalid/
|
assert_contain /Unlock token(.*)invalid/
|
||||||
end
|
end
|
||||||
|
@ -68,7 +66,7 @@ class LockTest < ActionController::IntegrationTest
|
||||||
|
|
||||||
visit_user_unlock_with_token(user.unlock_token)
|
visit_user_unlock_with_token(user.unlock_token)
|
||||||
|
|
||||||
assert_template 'home/index'
|
assert_current_url '/'
|
||||||
assert_contain 'Your account was successfully unlocked.'
|
assert_contain 'Your account was successfully unlocked.'
|
||||||
|
|
||||||
assert_not user.reload.access_locked?
|
assert_not user.reload.access_locked?
|
||||||
|
|
|
@ -78,8 +78,8 @@ class MappingTest < ActiveSupport::TestCase
|
||||||
mapping = Devise.mappings[:admin]
|
mapping = Devise.mappings[:admin]
|
||||||
assert mapping.authenticatable?
|
assert mapping.authenticatable?
|
||||||
assert mapping.recoverable?
|
assert mapping.recoverable?
|
||||||
|
assert mapping.lockable?
|
||||||
assert_not mapping.confirmable?
|
assert_not mapping.confirmable?
|
||||||
assert_not mapping.lockable?
|
|
||||||
assert_not mapping.rememberable?
|
assert_not mapping.rememberable?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -26,16 +26,16 @@ class ActiveRecordTest < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'can cherry pick modules' do
|
test 'can cherry pick modules' do
|
||||||
assert_include_modules Admin, :database_authenticatable, :registerable, :timeoutable, :recoverable
|
assert_include_modules Admin, :database_authenticatable, :registerable, :timeoutable, :recoverable, :lockable
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'chosen modules are inheritable' do
|
test 'chosen modules are inheritable' do
|
||||||
assert_include_modules Inheritable, :database_authenticatable, :registerable, :timeoutable, :recoverable
|
assert_include_modules Inheritable, :database_authenticatable, :registerable, :timeoutable, :recoverable, :lockable
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'order of module inclusion' do
|
test 'order of module inclusion' do
|
||||||
correct_module_order = [:database_authenticatable, :recoverable, :registerable, :timeoutable]
|
correct_module_order = [:database_authenticatable, :recoverable, :registerable, :lockable, :timeoutable]
|
||||||
incorrect_module_order = [:database_authenticatable, :timeoutable, :registerable, :recoverable]
|
incorrect_module_order = [:database_authenticatable, :timeoutable, :registerable, :recoverable, :lockable]
|
||||||
|
|
||||||
assert_include_modules Admin, *incorrect_module_order
|
assert_include_modules Admin, *incorrect_module_order
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
class Admin < ActiveRecord::Base
|
class Admin < ActiveRecord::Base
|
||||||
devise :database_authenticatable, :registerable, :timeoutable, :recoverable
|
devise :database_authenticatable, :registerable, :timeoutable, :recoverable, :lockable, :unlock_strategy => :time
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,5 +2,5 @@ class Admin
|
||||||
include Mongoid::Document
|
include Mongoid::Document
|
||||||
include Shim
|
include Shim
|
||||||
|
|
||||||
devise :database_authenticatable, :timeoutable, :registerable, :recoverable
|
devise :database_authenticatable, :timeoutable, :registerable, :recoverable, :lockable, :unlock_strategy => :time
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue