shingara-devise 0.4.3
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.rdoc +119 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +253 -0
- data/Rakefile +45 -0
- data/TODO +5 -0
- data/app/controllers/confirmations_controller.rb +33 -0
- data/app/controllers/passwords_controller.rb +41 -0
- data/app/controllers/sessions_controller.rb +33 -0
- data/app/models/devise_mailer.rb +53 -0
- data/app/views/confirmations/new.html.erb +16 -0
- data/app/views/devise_mailer/confirmation_instructions.html.erb +5 -0
- data/app/views/devise_mailer/reset_password_instructions.html.erb +8 -0
- data/app/views/passwords/edit.html.erb +20 -0
- data/app/views/passwords/new.html.erb +16 -0
- data/app/views/sessions/new.html.erb +23 -0
- data/generators/devise/USAGE +5 -0
- data/generators/devise/devise_generator.rb +25 -0
- data/generators/devise/lib/route_devise.rb +32 -0
- data/generators/devise/templates/README +22 -0
- data/generators/devise/templates/migration.rb +20 -0
- data/generators/devise/templates/model.rb +5 -0
- data/generators/devise_install/USAGE +3 -0
- data/generators/devise_install/devise_install_generator.rb +9 -0
- data/generators/devise_install/templates/devise.rb +47 -0
- data/generators/devise_views/USAGE +3 -0
- data/generators/devise_views/devise_views_generator.rb +24 -0
- data/init.rb +2 -0
- data/lib/devise/controllers/filters.rb +111 -0
- data/lib/devise/controllers/helpers.rb +130 -0
- data/lib/devise/controllers/url_helpers.rb +49 -0
- data/lib/devise/encryptors/authlogic_sha512.rb +28 -0
- data/lib/devise/encryptors/clearance_sha1.rb +26 -0
- data/lib/devise/encryptors/restful_authentication_sha1.rb +29 -0
- data/lib/devise/encryptors/sha1.rb +34 -0
- data/lib/devise/encryptors/sha512.rb +34 -0
- data/lib/devise/failure.rb +36 -0
- data/lib/devise/hooks/confirmable.rb +11 -0
- data/lib/devise/hooks/rememberable.rb +27 -0
- data/lib/devise/locales/en.yml +18 -0
- data/lib/devise/mapping.rb +120 -0
- data/lib/devise/migrations.rb +57 -0
- data/lib/devise/models/authenticatable.rb +87 -0
- data/lib/devise/models/confirmable.rb +156 -0
- data/lib/devise/models/recoverable.rb +88 -0
- data/lib/devise/models/rememberable.rb +95 -0
- data/lib/devise/models/validatable.rb +36 -0
- data/lib/devise/models.rb +110 -0
- data/lib/devise/orm/mongo_mapper.rb +26 -0
- data/lib/devise/rails/routes.rb +109 -0
- data/lib/devise/rails/warden_compat.rb +26 -0
- data/lib/devise/rails.rb +17 -0
- data/lib/devise/strategies/authenticatable.rb +46 -0
- data/lib/devise/strategies/base.rb +24 -0
- data/lib/devise/strategies/rememberable.rb +35 -0
- data/lib/devise/version.rb +3 -0
- data/lib/devise/warden.rb +20 -0
- data/lib/devise.rb +130 -0
- data/test/controllers/filters_test.rb +103 -0
- data/test/controllers/helpers_test.rb +55 -0
- data/test/controllers/url_helpers_test.rb +47 -0
- data/test/devise_test.rb +72 -0
- data/test/encryptors_test.rb +28 -0
- data/test/failure_test.rb +34 -0
- data/test/integration/authenticatable_test.rb +195 -0
- data/test/integration/confirmable_test.rb +89 -0
- data/test/integration/recoverable_test.rb +131 -0
- data/test/integration/rememberable_test.rb +65 -0
- data/test/mailers/confirmation_instructions_test.rb +59 -0
- data/test/mailers/reset_password_instructions_test.rb +62 -0
- data/test/mapping_test.rb +101 -0
- data/test/models/authenticatable_test.rb +130 -0
- data/test/models/confirmable_test.rb +237 -0
- data/test/models/recoverable_test.rb +141 -0
- data/test/models/rememberable_test.rb +130 -0
- data/test/models/validatable_test.rb +99 -0
- data/test/models_test.rb +111 -0
- data/test/rails_app/app/controllers/admins_controller.rb +6 -0
- data/test/rails_app/app/controllers/application_controller.rb +10 -0
- data/test/rails_app/app/controllers/home_controller.rb +4 -0
- data/test/rails_app/app/controllers/users_controller.rb +7 -0
- data/test/rails_app/app/helpers/application_helper.rb +3 -0
- data/test/rails_app/app/models/account.rb +3 -0
- data/test/rails_app/app/models/admin.rb +3 -0
- data/test/rails_app/app/models/organizer.rb +3 -0
- data/test/rails_app/app/models/user.rb +3 -0
- data/test/rails_app/config/boot.rb +110 -0
- data/test/rails_app/config/environment.rb +41 -0
- data/test/rails_app/config/environments/development.rb +17 -0
- data/test/rails_app/config/environments/production.rb +28 -0
- data/test/rails_app/config/environments/test.rb +28 -0
- data/test/rails_app/config/initializers/new_rails_defaults.rb +21 -0
- data/test/rails_app/config/initializers/session_store.rb +15 -0
- data/test/rails_app/config/routes.rb +18 -0
- data/test/routes_test.rb +79 -0
- data/test/support/assertions_helper.rb +22 -0
- data/test/support/integration_tests_helper.rb +66 -0
- data/test/support/model_tests_helper.rb +51 -0
- data/test/test_helper.rb +40 -0
- metadata +161 -0
@@ -0,0 +1,103 @@
|
|
1
|
+
require 'test/test_helper'
|
2
|
+
require 'ostruct'
|
3
|
+
|
4
|
+
class MockController < ApplicationController
|
5
|
+
attr_accessor :env
|
6
|
+
|
7
|
+
def request
|
8
|
+
self
|
9
|
+
end
|
10
|
+
|
11
|
+
def path
|
12
|
+
''
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class ControllerAuthenticableTest < ActionController::TestCase
|
17
|
+
|
18
|
+
def setup
|
19
|
+
@controller = MockController.new
|
20
|
+
@mock_warden = OpenStruct.new
|
21
|
+
@controller.env = { 'warden' => @mock_warden }
|
22
|
+
end
|
23
|
+
|
24
|
+
test 'setup warden' do
|
25
|
+
assert_not_nil @controller.warden
|
26
|
+
end
|
27
|
+
|
28
|
+
test 'provide access to warden instance' do
|
29
|
+
assert_equal @controller.warden, @controller.env['warden']
|
30
|
+
end
|
31
|
+
|
32
|
+
test 'run authenticate? with scope on warden' do
|
33
|
+
@mock_warden.expects(:authenticated?).with(:my_scope)
|
34
|
+
@controller.signed_in?(:my_scope)
|
35
|
+
end
|
36
|
+
|
37
|
+
test 'proxy signed_in? to authenticated' do
|
38
|
+
@mock_warden.expects(:authenticated?).with(:my_scope)
|
39
|
+
@controller.signed_in?(:my_scope)
|
40
|
+
end
|
41
|
+
|
42
|
+
test 'run user with scope on warden' do
|
43
|
+
@mock_warden.expects(:user).with(:admin).returns(true)
|
44
|
+
@controller.current_admin
|
45
|
+
|
46
|
+
@mock_warden.expects(:user).with(:user).returns(true)
|
47
|
+
@controller.current_user
|
48
|
+
end
|
49
|
+
|
50
|
+
test 'proxy logout to warden' do
|
51
|
+
@mock_warden.expects(:user).with(:user).returns(true)
|
52
|
+
@mock_warden.expects(:logout).with(:user).returns(true)
|
53
|
+
@controller.sign_out(:user)
|
54
|
+
end
|
55
|
+
|
56
|
+
test 'proxy user_authenticate! to authenticate with user scope' do
|
57
|
+
@mock_warden.expects(:authenticate!).with(:scope => :user)
|
58
|
+
@controller.authenticate_user!
|
59
|
+
end
|
60
|
+
|
61
|
+
test 'proxy admin_authenticate! to authenticate with admin scope' do
|
62
|
+
@mock_warden.expects(:authenticate!).with(:scope => :admin)
|
63
|
+
@controller.authenticate_admin!
|
64
|
+
end
|
65
|
+
|
66
|
+
test 'proxy user_authenticated? to authenticate with user scope' do
|
67
|
+
@mock_warden.expects(:authenticated?).with(:user)
|
68
|
+
@controller.user_signed_in?
|
69
|
+
end
|
70
|
+
|
71
|
+
test 'proxy admin_authenticated? to authenticate with admin scope' do
|
72
|
+
@mock_warden.expects(:authenticated?).with(:admin)
|
73
|
+
@controller.admin_signed_in?
|
74
|
+
end
|
75
|
+
|
76
|
+
test 'proxy user_session to session scope in warden' do
|
77
|
+
@mock_warden.expects(:session).with(:user).returns({})
|
78
|
+
@controller.user_session
|
79
|
+
end
|
80
|
+
|
81
|
+
test 'proxy admin_session to session scope in warden' do
|
82
|
+
@mock_warden.expects(:session).with(:admin).returns({})
|
83
|
+
@controller.admin_session
|
84
|
+
end
|
85
|
+
|
86
|
+
test 'sign in automatically proxy to set user on warden' do
|
87
|
+
@mock_warden.expects(:set_user).with(user = mock, :scope => :user).returns(true)
|
88
|
+
@controller.sign_in(:user, user)
|
89
|
+
end
|
90
|
+
|
91
|
+
test 'is not a devise controller' do
|
92
|
+
assert_not @controller.devise_controller?
|
93
|
+
end
|
94
|
+
|
95
|
+
test 'default url options are retrieved from devise' do
|
96
|
+
begin
|
97
|
+
Devise.default_url_options {{ :locale => I18n.locale }}
|
98
|
+
assert_equal({ :locale => :en }, @controller.send(:default_url_options))
|
99
|
+
ensure
|
100
|
+
Devise.default_url_options {{ }}
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'test/test_helper'
|
2
|
+
|
3
|
+
class MyController < ApplicationController
|
4
|
+
include Devise::Controllers::Helpers
|
5
|
+
end
|
6
|
+
|
7
|
+
class HelpersTest < ActionController::TestCase
|
8
|
+
tests MyController
|
9
|
+
|
10
|
+
test 'get resource name from request path' do
|
11
|
+
@request.path = '/users/session'
|
12
|
+
assert_equal :user, @controller.resource_name
|
13
|
+
end
|
14
|
+
|
15
|
+
test 'get resource name from specific request path' do
|
16
|
+
@request.path = '/admin_area/session'
|
17
|
+
assert_equal :admin, @controller.resource_name
|
18
|
+
end
|
19
|
+
|
20
|
+
test 'get resource class from request path' do
|
21
|
+
@request.path = '/users/session'
|
22
|
+
assert_equal User, @controller.resource_class
|
23
|
+
end
|
24
|
+
|
25
|
+
test 'get resource instance variable from request path' do
|
26
|
+
@request.path = '/admin_area/session'
|
27
|
+
@controller.instance_variable_set(:@admin, admin = Admin.new)
|
28
|
+
assert_equal admin, @controller.resource
|
29
|
+
end
|
30
|
+
|
31
|
+
test 'set resource instance variable from request path' do
|
32
|
+
@request.path = '/admin_area/session'
|
33
|
+
|
34
|
+
admin = @controller.send(:resource_class).new
|
35
|
+
@controller.send(:resource=, admin)
|
36
|
+
|
37
|
+
assert_equal admin, @controller.send(:resource)
|
38
|
+
assert_equal admin, @controller.instance_variable_get(:@admin)
|
39
|
+
end
|
40
|
+
|
41
|
+
test 'resources methods are not controller actions' do
|
42
|
+
assert @controller.class.action_methods.empty?
|
43
|
+
end
|
44
|
+
|
45
|
+
test 'require no authentication tests current mapping' do
|
46
|
+
@controller.expects(:resource_name).returns(:user).twice
|
47
|
+
@mock_warden.expects(:authenticated?).with(:user).returns(true)
|
48
|
+
@controller.expects(:redirect_to).with(root_path)
|
49
|
+
@controller.send :require_no_authentication
|
50
|
+
end
|
51
|
+
|
52
|
+
test 'is a devise controller' do
|
53
|
+
assert @controller.devise_controller?
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'test/test_helper'
|
2
|
+
|
3
|
+
class RoutesTest < ActionController::TestCase
|
4
|
+
tests ApplicationController
|
5
|
+
|
6
|
+
def test_path_and_url(name, prepend_path=nil)
|
7
|
+
@request.path = '/users/session'
|
8
|
+
prepend_path = "#{prepend_path}_" if prepend_path
|
9
|
+
|
10
|
+
# Resource param
|
11
|
+
assert_equal @controller.send(:"#{prepend_path}#{name}_path", :user),
|
12
|
+
send(:"#{prepend_path}user_#{name}_path")
|
13
|
+
assert_equal @controller.send(:"#{prepend_path}#{name}_url", :user),
|
14
|
+
send(:"#{prepend_path}user_#{name}_url")
|
15
|
+
|
16
|
+
# Default url params
|
17
|
+
assert_equal @controller.send(:"#{prepend_path}#{name}_path", :user, :param => 123),
|
18
|
+
send(:"#{prepend_path}user_#{name}_path", :param => 123)
|
19
|
+
assert_equal @controller.send(:"#{prepend_path}#{name}_url", :user, :param => 123),
|
20
|
+
send(:"#{prepend_path}user_#{name}_url", :param => 123)
|
21
|
+
|
22
|
+
@request.path = nil
|
23
|
+
# With an AR object
|
24
|
+
assert_equal @controller.send(:"#{prepend_path}#{name}_path", User.new),
|
25
|
+
send(:"#{prepend_path}user_#{name}_path")
|
26
|
+
assert_equal @controller.send(:"#{prepend_path}#{name}_url", User.new),
|
27
|
+
send(:"#{prepend_path}user_#{name}_url")
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
test 'should alias session to mapped user session' do
|
32
|
+
test_path_and_url :session
|
33
|
+
test_path_and_url :session, :new
|
34
|
+
test_path_and_url :session, :destroy
|
35
|
+
end
|
36
|
+
|
37
|
+
test 'should alias password to mapped user password' do
|
38
|
+
test_path_and_url :password
|
39
|
+
test_path_and_url :password, :new
|
40
|
+
test_path_and_url :password, :edit
|
41
|
+
end
|
42
|
+
|
43
|
+
test 'should alias confirmation to mapped user confirmation' do
|
44
|
+
test_path_and_url :confirmation
|
45
|
+
test_path_and_url :confirmation, :new
|
46
|
+
end
|
47
|
+
end
|
data/test/devise_test.rb
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'test/test_helper'
|
2
|
+
|
3
|
+
module Devise
|
4
|
+
def self.clean_warden_config!
|
5
|
+
@warden_config = nil
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
class DeviseTest < ActiveSupport::TestCase
|
10
|
+
class MockManager
|
11
|
+
attr_accessor :failure_app
|
12
|
+
attr_reader :default_strategies, :silence_missing_strategies
|
13
|
+
|
14
|
+
def silence_missing_strategies!
|
15
|
+
@silence_missing_strategies = true
|
16
|
+
end
|
17
|
+
|
18
|
+
def default_strategies(*args)
|
19
|
+
if args.empty?
|
20
|
+
@default_strategies
|
21
|
+
else
|
22
|
+
@default_strategies = args
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
test 'DeviseMailer.sender can be configured through Devise' do
|
28
|
+
swap DeviseMailer, :sender => "foo@bar" do
|
29
|
+
assert_equal "foo@bar", DeviseMailer.sender
|
30
|
+
Devise.mailer_sender = "bar@foo"
|
31
|
+
assert_equal "bar@foo", DeviseMailer.sender
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
test 'model options can be configured through Devise' do
|
36
|
+
swap Devise, :confirm_within => 113, :pepper => "foo" do
|
37
|
+
assert_equal 113, Devise.confirm_within
|
38
|
+
assert_equal "foo", Devise.pepper
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
test 'setup block yields self' do
|
43
|
+
Devise.setup do |config|
|
44
|
+
assert_equal Devise, config
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
test 'warden manager configuration' do
|
49
|
+
manager = MockManager.new
|
50
|
+
Devise.configure_warden_manager(manager)
|
51
|
+
|
52
|
+
assert_equal Devise::Failure, manager.failure_app
|
53
|
+
assert_equal [:rememberable, :authenticatable], manager.default_strategies
|
54
|
+
assert manager.silence_missing_strategies
|
55
|
+
end
|
56
|
+
|
57
|
+
test 'warden manager user configuration through a block' do
|
58
|
+
begin
|
59
|
+
@executed = false
|
60
|
+
Devise.warden do |manager|
|
61
|
+
@executed = true
|
62
|
+
assert_kind_of MockManager, manager
|
63
|
+
end
|
64
|
+
|
65
|
+
manager = MockManager.new
|
66
|
+
Devise.configure_warden_manager(manager)
|
67
|
+
assert @executed
|
68
|
+
ensure
|
69
|
+
Devise.clean_warden_config!
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
class Encryptors < ActiveSupport::TestCase
|
2
|
+
|
3
|
+
test 'should match a password created by authlogic' do
|
4
|
+
authlogic = "b623c3bc9c775b0eb8edb218a382453396fec4146422853e66ecc4b6bc32d7162ee42074dcb5f180a770dc38b5df15812f09bbf497a4a1b95fe5e7d2b8eb7eb4"
|
5
|
+
encryptor = Devise::Encryptors::AuthlogicSha512.digest('123mudar', 20, 'usZK_z_EAaF61Gwkw-ed', '')
|
6
|
+
assert_equal authlogic, encryptor
|
7
|
+
end
|
8
|
+
|
9
|
+
test 'should match a password created by restful_authentication' do
|
10
|
+
restful_authentication = "93110f71309ce91366375ea44e2a6f5cc73fa8d4"
|
11
|
+
encryptor = Devise::Encryptors::RestfulAuthenticationSha1.digest('123mudar', 10, '48901d2b247a54088acb7f8ea3e695e50fe6791b', 'fee9a51ec0a28d11be380ca6dee6b4b760c1a3bf')
|
12
|
+
assert_equal restful_authentication, encryptor
|
13
|
+
end
|
14
|
+
|
15
|
+
test 'should match a password created by clearance' do
|
16
|
+
clearance = "0f40bbae18ddefd7066276c3ef209d40729b0378"
|
17
|
+
encryptor = Devise::Encryptors::ClearanceSha1.digest('123mudar', nil, '65c58472c207c829f28c68619d3e3aefed18ab3f', nil)
|
18
|
+
assert_equal clearance, encryptor
|
19
|
+
end
|
20
|
+
|
21
|
+
Devise::ENCRYPTORS_LENGTH.each do |key, value|
|
22
|
+
test "should have length #{value} for #{key.inspect}" do
|
23
|
+
swap Devise, :encryptor => key do
|
24
|
+
assert_equal value, Devise.encryptor.digest('a', 2, 'b', 'c').size
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'test/test_helper'
|
2
|
+
|
3
|
+
class FailureTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
def call_failure(env_params={})
|
6
|
+
env = {'warden.options' => {:scope => :user}.update(env_params)}
|
7
|
+
Devise::Failure.call(env)
|
8
|
+
end
|
9
|
+
|
10
|
+
test 'return 302 status' do
|
11
|
+
assert_equal 302, call_failure.first
|
12
|
+
end
|
13
|
+
|
14
|
+
test 'return redirect location based on mapping with params' do
|
15
|
+
assert_equal '/users/sign_in', call_failure.second['Location']
|
16
|
+
end
|
17
|
+
|
18
|
+
test 'add params to redirect location' do
|
19
|
+
location = call_failure(:params => {:test => true}).second['Location']
|
20
|
+
assert_equal '/users/sign_in?test=true', location
|
21
|
+
end
|
22
|
+
|
23
|
+
test 'set content type to default text/plain' do
|
24
|
+
assert_equal 'text/plain', call_failure.second['Content-Type']
|
25
|
+
end
|
26
|
+
|
27
|
+
test 'setup a default message' do
|
28
|
+
assert_equal ['You are being redirected to /users/sign_in'], call_failure.last
|
29
|
+
end
|
30
|
+
|
31
|
+
test 'pass in a different message' do
|
32
|
+
assert_equal ['Hello world'], call_failure(:message => 'Hello world').last
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,195 @@
|
|
1
|
+
require 'test/test_helper'
|
2
|
+
|
3
|
+
class AuthenticationTest < ActionController::IntegrationTest
|
4
|
+
|
5
|
+
test 'home should be accessible without signed in' do
|
6
|
+
visit '/'
|
7
|
+
assert_response :success
|
8
|
+
assert_template 'home/index'
|
9
|
+
end
|
10
|
+
|
11
|
+
test 'sign in as user should not authenticate admin scope' do
|
12
|
+
sign_in_as_user
|
13
|
+
|
14
|
+
assert warden.authenticated?(:user)
|
15
|
+
assert_not warden.authenticated?(:admin)
|
16
|
+
end
|
17
|
+
|
18
|
+
test 'sign in as admin should not authenticate user scope' do
|
19
|
+
sign_in_as_admin
|
20
|
+
|
21
|
+
assert warden.authenticated?(:admin)
|
22
|
+
assert_not warden.authenticated?(:user)
|
23
|
+
end
|
24
|
+
|
25
|
+
test 'sign in as both user and admin at same time' do
|
26
|
+
sign_in_as_user
|
27
|
+
sign_in_as_admin
|
28
|
+
|
29
|
+
assert warden.authenticated?(:user)
|
30
|
+
assert warden.authenticated?(:admin)
|
31
|
+
end
|
32
|
+
|
33
|
+
test 'sign out as user should not touch admin authentication' do
|
34
|
+
sign_in_as_user
|
35
|
+
sign_in_as_admin
|
36
|
+
|
37
|
+
get destroy_user_session_path
|
38
|
+
assert_not warden.authenticated?(:user)
|
39
|
+
assert warden.authenticated?(:admin)
|
40
|
+
end
|
41
|
+
|
42
|
+
test 'sign out as admin should not touch user authentication' do
|
43
|
+
sign_in_as_user
|
44
|
+
sign_in_as_admin
|
45
|
+
|
46
|
+
get destroy_admin_session_path
|
47
|
+
assert_not warden.authenticated?(:admin)
|
48
|
+
assert warden.authenticated?(:user)
|
49
|
+
end
|
50
|
+
|
51
|
+
test 'not signed in as admin should not be able to access admins actions' do
|
52
|
+
get admins_path
|
53
|
+
|
54
|
+
assert_redirected_to new_admin_session_path(:unauthenticated => true)
|
55
|
+
assert_not warden.authenticated?(:admin)
|
56
|
+
end
|
57
|
+
|
58
|
+
test 'signed in as user should not be able to access admins actions' do
|
59
|
+
sign_in_as_user
|
60
|
+
assert warden.authenticated?(:user)
|
61
|
+
assert_not warden.authenticated?(:admin)
|
62
|
+
|
63
|
+
get admins_path
|
64
|
+
assert_redirected_to new_admin_session_path(:unauthenticated => true)
|
65
|
+
end
|
66
|
+
|
67
|
+
test 'signed in as admin should be able to access admin actions' do
|
68
|
+
sign_in_as_admin
|
69
|
+
assert warden.authenticated?(:admin)
|
70
|
+
assert_not warden.authenticated?(:user)
|
71
|
+
|
72
|
+
get admins_path
|
73
|
+
|
74
|
+
assert_response :success
|
75
|
+
assert_template 'admins/index'
|
76
|
+
assert_contain 'Welcome Admin'
|
77
|
+
end
|
78
|
+
|
79
|
+
test 'admin signing in with invalid email should return to sign in form with error message' do
|
80
|
+
sign_in_as_admin do
|
81
|
+
fill_in 'email', :with => 'wrongemail@test.com'
|
82
|
+
end
|
83
|
+
|
84
|
+
assert_contain 'Invalid email or password'
|
85
|
+
assert_not warden.authenticated?(:admin)
|
86
|
+
end
|
87
|
+
|
88
|
+
test 'admin signing in with invalid pasword should return to sign in form with error message' do
|
89
|
+
sign_in_as_admin do
|
90
|
+
fill_in 'password', :with => 'abcdef'
|
91
|
+
end
|
92
|
+
|
93
|
+
assert_contain 'Invalid email or password'
|
94
|
+
assert_not warden.authenticated?(:admin)
|
95
|
+
end
|
96
|
+
|
97
|
+
test 'error message is configurable by resource name' do
|
98
|
+
begin
|
99
|
+
I18n.backend.store_translations(:en, :devise => { :sessions =>
|
100
|
+
{ :admin => { :invalid => "Invalid credentials" } } })
|
101
|
+
|
102
|
+
sign_in_as_admin do
|
103
|
+
fill_in 'password', :with => 'abcdef'
|
104
|
+
end
|
105
|
+
|
106
|
+
assert_contain 'Invalid credentials'
|
107
|
+
ensure
|
108
|
+
I18n.reload!
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
test 'authenticated admin should not be able to sign as admin again' do
|
113
|
+
sign_in_as_admin
|
114
|
+
get new_admin_session_path
|
115
|
+
|
116
|
+
assert_response :redirect
|
117
|
+
assert_redirected_to admin_root_path
|
118
|
+
assert warden.authenticated?(:admin)
|
119
|
+
end
|
120
|
+
|
121
|
+
test 'authenticated admin should be able to sign out' do
|
122
|
+
sign_in_as_admin
|
123
|
+
assert warden.authenticated?(:admin)
|
124
|
+
|
125
|
+
get destroy_admin_session_path
|
126
|
+
assert_response :redirect
|
127
|
+
assert_redirected_to root_path
|
128
|
+
|
129
|
+
get root_path
|
130
|
+
assert_contain 'Signed out successfully'
|
131
|
+
assert_not warden.authenticated?(:admin)
|
132
|
+
end
|
133
|
+
|
134
|
+
test 'unauthenticated admin does not set message on sign out' do
|
135
|
+
get destroy_admin_session_path
|
136
|
+
assert_response :redirect
|
137
|
+
assert_redirected_to root_path
|
138
|
+
|
139
|
+
get root_path
|
140
|
+
assert_not_contain 'Signed out successfully'
|
141
|
+
end
|
142
|
+
|
143
|
+
test 'redirect from warden shows sign in or sign up message' do
|
144
|
+
get admins_path
|
145
|
+
|
146
|
+
warden_path = new_admin_session_path(:unauthenticated => true)
|
147
|
+
assert_redirected_to warden_path
|
148
|
+
|
149
|
+
get warden_path
|
150
|
+
assert_contain 'You need to sign in or sign up before continuing.'
|
151
|
+
end
|
152
|
+
|
153
|
+
test 'render 404 on roles without permission' do
|
154
|
+
get 'admin_area/password/new'
|
155
|
+
assert_response :not_found
|
156
|
+
assert_not_contain 'Send me reset password instructions'
|
157
|
+
end
|
158
|
+
|
159
|
+
test 'return to default url if no other was requested' do
|
160
|
+
sign_in_as_user
|
161
|
+
|
162
|
+
assert_template 'home/index'
|
163
|
+
assert_nil session[:return_to]
|
164
|
+
end
|
165
|
+
|
166
|
+
test 'return to given url after sign in' do
|
167
|
+
get users_path
|
168
|
+
assert_redirected_to new_user_session_path(:unauthenticated => true)
|
169
|
+
assert_equal users_path, session[:"user.return_to"]
|
170
|
+
follow_redirect!
|
171
|
+
|
172
|
+
sign_in_as_user :visit => false
|
173
|
+
assert_template 'users/index'
|
174
|
+
assert_nil session[:"user.return_to"]
|
175
|
+
end
|
176
|
+
|
177
|
+
test 'return to configured home path after sign in' do
|
178
|
+
sign_in_as_admin
|
179
|
+
assert_equal "/admin_area/home", @request.path
|
180
|
+
end
|
181
|
+
|
182
|
+
test 'allows session to be set by a given scope' do
|
183
|
+
sign_in_as_user
|
184
|
+
visit 'users/index'
|
185
|
+
assert_equal "Cart", @controller.user_session[:cart]
|
186
|
+
end
|
187
|
+
|
188
|
+
test 'destroyed account is logged out' do
|
189
|
+
sign_in_as_user
|
190
|
+
visit 'users/index'
|
191
|
+
User.destroy_all
|
192
|
+
visit 'users/index'
|
193
|
+
assert_redirected_to '/users/sign_in?unauthenticated=true'
|
194
|
+
end
|
195
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'test/test_helper'
|
2
|
+
|
3
|
+
class ConfirmationTest < ActionController::IntegrationTest
|
4
|
+
|
5
|
+
def visit_user_confirmation_with_token(confirmation_token)
|
6
|
+
visit user_confirmation_path(:confirmation_token => confirmation_token)
|
7
|
+
end
|
8
|
+
|
9
|
+
test 'user should be able to request a new confirmation' do
|
10
|
+
user = create_user(:confirm => false)
|
11
|
+
ActionMailer::Base.deliveries.clear
|
12
|
+
|
13
|
+
visit new_user_session_path
|
14
|
+
click_link 'Didn\'t receive confirmation instructions?'
|
15
|
+
|
16
|
+
fill_in 'email', :with => user.email
|
17
|
+
click_button 'Resend confirmation instructions'
|
18
|
+
|
19
|
+
assert_template 'sessions/new'
|
20
|
+
assert_contain 'You will receive an email with instructions about how to confirm your account in a few minutes'
|
21
|
+
assert_equal 1, ActionMailer::Base.deliveries.size
|
22
|
+
end
|
23
|
+
|
24
|
+
test 'user with invalid confirmation token should not be able to confirm an account' do
|
25
|
+
visit_user_confirmation_with_token('invalid_confirmation')
|
26
|
+
|
27
|
+
assert_response :success
|
28
|
+
assert_template 'confirmations/new'
|
29
|
+
assert_have_selector '#errorExplanation'
|
30
|
+
assert_contain 'Confirmation token is invalid'
|
31
|
+
end
|
32
|
+
|
33
|
+
test 'user with valid confirmation token should be able to confirm an account' do
|
34
|
+
user = create_user(:confirm => false)
|
35
|
+
assert_not user.confirmed?
|
36
|
+
|
37
|
+
visit_user_confirmation_with_token(user.confirmation_token)
|
38
|
+
|
39
|
+
assert_template 'home/index'
|
40
|
+
assert_contain 'Your account was successfully confirmed.'
|
41
|
+
|
42
|
+
assert user.reload.confirmed?
|
43
|
+
end
|
44
|
+
|
45
|
+
test 'user already confirmed user should not be able to confirm the account again' do
|
46
|
+
user = create_user
|
47
|
+
visit_user_confirmation_with_token(user.confirmation_token)
|
48
|
+
|
49
|
+
assert_template 'confirmations/new'
|
50
|
+
assert_have_selector '#errorExplanation'
|
51
|
+
assert_contain 'already confirmed'
|
52
|
+
end
|
53
|
+
|
54
|
+
test 'sign in user automatically after confirming it\'s email' do
|
55
|
+
user = create_user(:confirm => false)
|
56
|
+
visit_user_confirmation_with_token(user.confirmation_token)
|
57
|
+
|
58
|
+
assert warden.authenticated?(:user)
|
59
|
+
end
|
60
|
+
|
61
|
+
test 'not confirmed user and setup to block without confirmation should not be able to sign in' do
|
62
|
+
Devise.confirm_within = 0
|
63
|
+
user = sign_in_as_user(:confirm => false)
|
64
|
+
|
65
|
+
assert_redirected_to new_user_session_path(:unconfirmed => true)
|
66
|
+
assert_not warden.authenticated?(:user)
|
67
|
+
end
|
68
|
+
|
69
|
+
test 'not confirmed user but configured with some days to confirm should be able to sign in' do
|
70
|
+
Devise.confirm_within = 1
|
71
|
+
user = sign_in_as_user(:confirm => false)
|
72
|
+
|
73
|
+
assert_response :success
|
74
|
+
assert warden.authenticated?(:user)
|
75
|
+
end
|
76
|
+
|
77
|
+
test 'error message is configurable by resource name' do
|
78
|
+
begin
|
79
|
+
I18n.backend.store_translations(:en, :devise => { :sessions =>
|
80
|
+
{ :admin => { :unconfirmed => "Not confirmed user" } } })
|
81
|
+
|
82
|
+
get new_admin_session_path(:unconfirmed => true)
|
83
|
+
|
84
|
+
assert_contain 'Not confirmed user'
|
85
|
+
ensure
|
86
|
+
I18n.reload!
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|