devise 1.0.11 → 1.1.0
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 +59 -13
- data/Gemfile +23 -0
- data/Gemfile.lock +118 -0
- data/README.rdoc +116 -77
- data/Rakefile +4 -2
- data/TODO +3 -2
- data/app/controllers/{confirmations_controller.rb → devise/confirmations_controller.rb} +1 -1
- data/app/controllers/{passwords_controller.rb → devise/passwords_controller.rb} +1 -1
- data/app/controllers/{registrations_controller.rb → devise/registrations_controller.rb} +12 -8
- data/app/controllers/devise/sessions_controller.rb +23 -0
- data/app/controllers/{unlocks_controller.rb → devise/unlocks_controller.rb} +1 -8
- data/app/helpers/devise_helper.rb +17 -0
- data/app/mailers/devise/mailer.rb +71 -0
- data/app/views/devise/confirmations/new.html.erb +12 -0
- data/app/views/devise/passwords/edit.html.erb +16 -0
- data/app/views/devise/passwords/new.html.erb +12 -0
- data/app/views/devise/registrations/edit.html.erb +25 -0
- data/app/views/devise/registrations/new.html.erb +18 -0
- data/app/views/devise/sessions/new.html.erb +17 -0
- data/app/views/devise/shared/_links.erb +19 -0
- data/app/views/devise/unlocks/new.html.erb +12 -0
- data/{lib/devise → config}/locales/en.yml +16 -12
- data/lib/devise/controllers/helpers.rb +57 -52
- data/lib/devise/controllers/internal_helpers.rb +19 -50
- data/lib/devise/controllers/scoped_views.rb +35 -0
- data/lib/devise/controllers/url_helpers.rb +1 -1
- data/lib/devise/encryptors/authlogic_sha512.rb +0 -2
- data/lib/devise/encryptors/base.rb +1 -1
- data/lib/devise/encryptors/bcrypt.rb +2 -4
- data/lib/devise/encryptors/clearance_sha1.rb +0 -2
- data/lib/devise/encryptors/sha1.rb +6 -8
- data/lib/devise/encryptors/sha512.rb +6 -8
- data/lib/devise/failure_app.rb +76 -41
- data/lib/devise/hooks/activatable.rb +6 -10
- data/lib/devise/hooks/forgetable.rb +11 -0
- data/lib/devise/hooks/rememberable.rb +40 -30
- data/lib/devise/hooks/timeoutable.rb +7 -3
- data/lib/devise/hooks/trackable.rb +5 -14
- data/lib/devise/mapping.rb +35 -62
- data/lib/devise/models/authenticatable.rb +126 -0
- data/lib/devise/models/confirmable.rb +19 -22
- data/lib/devise/models/database_authenticatable.rb +26 -60
- data/lib/devise/models/lockable.rb +43 -28
- data/lib/devise/models/recoverable.rb +11 -10
- data/lib/devise/models/rememberable.rb +56 -26
- data/lib/devise/models/timeoutable.rb +1 -3
- data/lib/devise/models/token_authenticatable.rb +14 -43
- data/lib/devise/models/trackable.rb +14 -0
- data/lib/devise/models/validatable.rb +16 -2
- data/lib/devise/models.rb +16 -53
- data/lib/devise/modules.rb +23 -0
- data/lib/devise/orm/active_record.rb +10 -15
- data/lib/devise/orm/mongoid.rb +29 -0
- data/lib/devise/path_checker.rb +18 -0
- data/lib/devise/rails/routes.rb +232 -117
- data/lib/devise/rails/warden_compat.rb +17 -41
- data/lib/devise/rails.rb +64 -9
- data/lib/devise/schema.rb +47 -23
- data/lib/devise/strategies/authenticatable.rb +123 -0
- data/lib/devise/strategies/base.rb +2 -3
- data/lib/devise/strategies/database_authenticatable.rb +7 -22
- data/lib/devise/strategies/rememberable.rb +21 -7
- data/lib/devise/strategies/token_authenticatable.rb +31 -19
- data/lib/devise/test_helpers.rb +6 -6
- data/lib/devise/version.rb +1 -1
- data/lib/devise.rb +174 -157
- data/lib/generators/active_record/devise_generator.rb +28 -0
- data/{generators/devise → lib/generators/active_record}/templates/migration.rb +9 -3
- data/lib/generators/devise/devise_generator.rb +17 -0
- data/lib/generators/devise/install_generator.rb +24 -0
- data/lib/generators/devise/orm_helpers.rb +23 -0
- data/{generators/devise_install → lib/generators/devise}/templates/README +9 -7
- data/lib/generators/devise/templates/devise.rb +142 -0
- data/lib/generators/devise/views_generator.rb +63 -0
- data/lib/generators/devise_install_generator.rb +4 -0
- data/lib/generators/devise_views_generator.rb +4 -0
- data/lib/generators/mongoid/devise_generator.rb +17 -0
- data/test/controllers/helpers_test.rb +48 -19
- data/test/controllers/internal_helpers_test.rb +12 -16
- data/test/controllers/url_helpers_test.rb +21 -10
- data/test/devise_test.rb +16 -25
- data/test/encryptors_test.rb +2 -3
- data/test/failure_app_test.rb +106 -27
- data/test/integration/authenticatable_test.rb +135 -131
- data/test/integration/confirmable_test.rb +22 -15
- data/test/integration/database_authenticatable_test.rb +38 -0
- data/test/integration/http_authenticatable_test.rb +9 -12
- data/test/integration/lockable_test.rb +22 -15
- data/test/integration/recoverable_test.rb +6 -6
- data/test/integration/registerable_test.rb +42 -33
- data/test/integration/rememberable_test.rb +84 -22
- data/test/integration/timeoutable_test.rb +16 -4
- data/test/integration/token_authenticatable_test.rb +45 -12
- data/test/integration/trackable_test.rb +1 -1
- data/test/mailers/confirmation_instructions_test.rb +11 -17
- data/test/mailers/reset_password_instructions_test.rb +7 -7
- data/test/mailers/unlock_instructions_test.rb +7 -7
- data/test/mapping_test.rb +22 -95
- data/test/models/confirmable_test.rb +12 -19
- data/test/models/{authenticatable_test.rb → database_authenticatable_test.rb} +24 -56
- data/test/models/lockable_test.rb +32 -46
- data/test/models/recoverable_test.rb +7 -7
- data/test/models/rememberable_test.rb +118 -35
- data/test/models/timeoutable_test.rb +1 -1
- data/test/models/token_authenticatable_test.rb +5 -19
- data/test/models/trackable_test.rb +1 -1
- data/test/models/validatable_test.rb +20 -27
- data/test/models_test.rb +12 -5
- data/test/orm/active_record.rb +1 -23
- data/test/orm/mongoid.rb +10 -0
- data/test/rails_app/app/active_record/admin.rb +1 -5
- data/test/rails_app/app/active_record/shim.rb +2 -0
- data/test/rails_app/app/active_record/user.rb +3 -3
- data/test/rails_app/app/controllers/application_controller.rb +2 -5
- data/test/rails_app/app/controllers/home_controller.rb +3 -0
- data/test/rails_app/app/controllers/publisher/registrations_controller.rb +2 -0
- data/test/rails_app/app/controllers/publisher/sessions_controller.rb +2 -0
- data/test/rails_app/app/controllers/sessions_controller.rb +6 -0
- data/test/rails_app/app/controllers/users_controller.rb +7 -5
- data/test/rails_app/app/mongoid/admin.rb +6 -0
- data/test/rails_app/app/mongoid/shim.rb +16 -0
- data/test/rails_app/app/mongoid/user.rb +10 -0
- data/test/rails_app/config/application.rb +35 -0
- data/test/rails_app/config/boot.rb +10 -107
- data/test/rails_app/config/environment.rb +4 -41
- data/test/rails_app/config/environments/development.rb +15 -13
- data/test/rails_app/config/environments/production.rb +25 -20
- data/test/rails_app/config/environments/test.rb +33 -28
- data/test/rails_app/config/initializers/backtrace_silencers.rb +7 -0
- data/test/rails_app/config/initializers/devise.rb +95 -38
- data/test/rails_app/config/initializers/secret_token.rb +2 -0
- data/test/rails_app/config/routes.rb +47 -25
- data/test/rails_app/db/migrate/20100401102949_create_tables.rb +27 -0
- data/test/rails_app/db/schema.rb +86 -0
- data/test/routes_test.rb +62 -47
- data/test/support/{assertions_helper.rb → assertions.rb} +2 -15
- data/test/support/{tests_helper.rb → helpers.rb} +18 -3
- data/test/support/{integration_tests_helper.rb → integration.rb} +24 -7
- data/test/support/webrat/integrations/rails.rb +32 -0
- data/test/test_helper.rb +11 -11
- data/test/test_helpers_test.rb +30 -15
- metadata +107 -66
- data/app/controllers/sessions_controller.rb +0 -42
- data/app/models/devise_mailer.rb +0 -68
- data/app/views/confirmations/new.html.erb +0 -12
- data/app/views/passwords/edit.html.erb +0 -16
- data/app/views/passwords/new.html.erb +0 -12
- data/app/views/registrations/edit.html.erb +0 -25
- data/app/views/registrations/new.html.erb +0 -17
- data/app/views/sessions/new.html.erb +0 -17
- data/app/views/shared/_devise_links.erb +0 -19
- data/app/views/unlocks/new.html.erb +0 -12
- data/generators/devise/USAGE +0 -5
- data/generators/devise/devise_generator.rb +0 -15
- data/generators/devise/lib/route_devise.rb +0 -32
- data/generators/devise/templates/model.rb +0 -9
- data/generators/devise_install/USAGE +0 -3
- data/generators/devise_install/devise_install_generator.rb +0 -15
- data/generators/devise_install/templates/devise.rb +0 -105
- data/generators/devise_views/USAGE +0 -3
- data/generators/devise_views/devise_views_generator.rb +0 -21
- data/lib/devise/models/activatable.rb +0 -16
- data/lib/devise/models/http_authenticatable.rb +0 -23
- data/lib/devise/orm/data_mapper.rb +0 -83
- data/lib/devise/orm/mongo_mapper.rb +0 -52
- data/lib/devise/strategies/http_authenticatable.rb +0 -59
- data/rails/init.rb +0 -2
- data/test/integration/rack_middleware_test.rb +0 -47
- data/test/orm/mongo_mapper.rb +0 -20
- data/test/rails_app/app/mongo_mapper/admin.rb +0 -13
- data/test/rails_app/app/mongo_mapper/user.rb +0 -14
- data/test/rails_app/config/initializers/new_rails_defaults.rb +0 -24
- data/test/rails_app/config/initializers/session_store.rb +0 -15
- /data/app/views/{devise_mailer → devise/mailer}/confirmation_instructions.html.erb +0 -0
- /data/app/views/{devise_mailer → devise/mailer}/reset_password_instructions.html.erb +0 -0
- /data/app/views/{devise_mailer → devise/mailer}/unlock_instructions.html.erb +0 -0
data/test/failure_app_test.rb
CHANGED
|
@@ -1,44 +1,123 @@
|
|
|
1
|
-
require '
|
|
1
|
+
require 'test_helper'
|
|
2
2
|
require 'ostruct'
|
|
3
3
|
|
|
4
4
|
class FailureTest < ActiveSupport::TestCase
|
|
5
|
+
def self.context(name, &block)
|
|
6
|
+
instance_eval(&block)
|
|
7
|
+
end
|
|
5
8
|
|
|
6
9
|
def call_failure(env_params={})
|
|
7
|
-
env = {
|
|
8
|
-
|
|
10
|
+
env = {
|
|
11
|
+
'REQUEST_URI' => 'http://test.host/',
|
|
12
|
+
'HTTP_HOST' => 'test.host',
|
|
13
|
+
'REQUEST_METHOD' => 'GET',
|
|
14
|
+
'warden.options' => { :scope => :user },
|
|
15
|
+
'rack.session' => {},
|
|
16
|
+
'action_dispatch.request.formats' => Array(env_params.delete('formats') || :html),
|
|
17
|
+
'rack.input' => "",
|
|
18
|
+
'warden' => OpenStruct.new(:message => nil)
|
|
19
|
+
}.merge!(env_params)
|
|
20
|
+
|
|
21
|
+
@response = Devise::FailureApp.call(env).to_a
|
|
22
|
+
@request = ActionDispatch::Request.new(env)
|
|
9
23
|
end
|
|
10
24
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
25
|
+
context 'When redirecting' do
|
|
26
|
+
test 'return 302 status' do
|
|
27
|
+
call_failure
|
|
28
|
+
assert_equal 302, @response.first
|
|
29
|
+
end
|
|
14
30
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
31
|
+
test 'return to the default redirect location' do
|
|
32
|
+
call_failure
|
|
33
|
+
assert_equal 'You need to sign in or sign up before continuing.', @request.flash[:alert]
|
|
34
|
+
assert_equal 'http://test.host/users/sign_in', @response.second['Location']
|
|
35
|
+
end
|
|
18
36
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
37
|
+
test 'uses the proxy failure message as symbol' do
|
|
38
|
+
call_failure('warden' => OpenStruct.new(:message => :test))
|
|
39
|
+
assert_equal 'test', @request.flash[:alert]
|
|
40
|
+
assert_equal 'http://test.host/users/sign_in', @response.second["Location"]
|
|
41
|
+
end
|
|
24
42
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
43
|
+
test 'uses the proxy failure message as string' do
|
|
44
|
+
call_failure('warden' => OpenStruct.new(:message => 'Hello world'))
|
|
45
|
+
assert_equal 'Hello world', @request.flash[:alert]
|
|
46
|
+
assert_equal 'http://test.host/users/sign_in', @response.second["Location"]
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
test 'set content type to default text/html' do
|
|
50
|
+
call_failure
|
|
51
|
+
assert_equal 'text/html; charset=utf-8', @response.second['Content-Type']
|
|
52
|
+
end
|
|
30
53
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
54
|
+
test 'setup a default message' do
|
|
55
|
+
call_failure
|
|
56
|
+
assert_match /You are being/, @response.last.body
|
|
57
|
+
assert_match /redirected/, @response.last.body
|
|
58
|
+
assert_match /users\/sign_in/, @response.last.body
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
test 'works for any navigational format' do
|
|
62
|
+
swap Devise, :navigational_formats => [:xml] do
|
|
63
|
+
call_failure('formats' => :xml)
|
|
64
|
+
assert_equal 302, @response.first
|
|
65
|
+
end
|
|
66
|
+
end
|
|
35
67
|
end
|
|
36
68
|
|
|
37
|
-
|
|
38
|
-
|
|
69
|
+
context 'For HTTP request' do
|
|
70
|
+
test 'return 401 status' do
|
|
71
|
+
call_failure('formats' => :xml)
|
|
72
|
+
assert_equal 401, @response.first
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
test 'return WWW-authenticate headers' do
|
|
76
|
+
call_failure('formats' => :xml)
|
|
77
|
+
assert_equal 'Basic realm="Application"', @response.second["WWW-Authenticate"]
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
test 'dont return WWW-authenticate on ajax call if http_authenticatable_on_xhr false' do
|
|
81
|
+
swap Devise, :http_authenticatable_on_xhr => false do
|
|
82
|
+
call_failure('formats' => :html, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest')
|
|
83
|
+
assert_equal 302, @response.first
|
|
84
|
+
assert_equal 'http://test.host/users/sign_in', @response.second["Location"]
|
|
85
|
+
assert_nil @response.second['WWW-Authenticate']
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
test 'return WWW-authenticate on ajax call if http_authenticatable_on_xhr true' do
|
|
90
|
+
swap Devise, :http_authenticatable_on_xhr => true do
|
|
91
|
+
call_failure('formats' => :html, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest')
|
|
92
|
+
assert_equal 401, @response.first
|
|
93
|
+
assert_equal 'Basic realm="Application"', @response.second["WWW-Authenticate"]
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
test 'uses the proxy failure message as response body' do
|
|
98
|
+
call_failure('formats' => :xml, 'warden' => OpenStruct.new(:message => :invalid))
|
|
99
|
+
assert_match '<error>Invalid email or password.</error>', @response.third.body
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
test 'works for any non navigational format' do
|
|
103
|
+
swap Devise, :navigational_formats => [] do
|
|
104
|
+
call_failure('formats' => :html)
|
|
105
|
+
assert_equal 401, @response.first
|
|
106
|
+
end
|
|
107
|
+
end
|
|
39
108
|
end
|
|
40
109
|
|
|
41
|
-
|
|
42
|
-
|
|
110
|
+
context 'With recall' do
|
|
111
|
+
test 'calls the original controller' do
|
|
112
|
+
env = {
|
|
113
|
+
"action_dispatch.request.parameters" => { :controller => "devise/sessions" },
|
|
114
|
+
"warden.options" => { :recall => "new", :attempted_path => "/users/sign_in" },
|
|
115
|
+
"devise.mapping" => Devise.mappings[:user],
|
|
116
|
+
"warden" => stub_everything
|
|
117
|
+
}
|
|
118
|
+
call_failure(env)
|
|
119
|
+
assert @response.third.body.include?('<h2>Sign in</h2>')
|
|
120
|
+
assert @response.third.body.include?('Invalid email or password.')
|
|
121
|
+
end
|
|
43
122
|
end
|
|
44
123
|
end
|
|
@@ -1,6 +1,15 @@
|
|
|
1
|
-
require '
|
|
1
|
+
require 'test_helper'
|
|
2
2
|
|
|
3
3
|
class AuthenticationSanityTest < ActionController::IntegrationTest
|
|
4
|
+
|
|
5
|
+
def setup
|
|
6
|
+
Devise.sign_out_all_scopes = false
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def teardown
|
|
10
|
+
Devise.sign_out_all_scopes = false
|
|
11
|
+
end
|
|
12
|
+
|
|
4
13
|
test 'home should be accessible without sign in' do
|
|
5
14
|
visit '/'
|
|
6
15
|
assert_response :success
|
|
@@ -29,7 +38,7 @@ class AuthenticationSanityTest < ActionController::IntegrationTest
|
|
|
29
38
|
assert warden.authenticated?(:admin)
|
|
30
39
|
end
|
|
31
40
|
|
|
32
|
-
test 'sign out as user should not touch admin authentication' do
|
|
41
|
+
test 'sign out as user should not touch admin authentication if sign_out_all_scopes is false' do
|
|
33
42
|
sign_in_as_user
|
|
34
43
|
sign_in_as_admin
|
|
35
44
|
|
|
@@ -38,7 +47,7 @@ class AuthenticationSanityTest < ActionController::IntegrationTest
|
|
|
38
47
|
assert warden.authenticated?(:admin)
|
|
39
48
|
end
|
|
40
49
|
|
|
41
|
-
test 'sign out as admin should not touch user authentication' do
|
|
50
|
+
test 'sign out as admin should not touch user authentication if sign_out_all_scopes is false' do
|
|
42
51
|
sign_in_as_user
|
|
43
52
|
sign_in_as_admin
|
|
44
53
|
|
|
@@ -47,11 +56,59 @@ class AuthenticationSanityTest < ActionController::IntegrationTest
|
|
|
47
56
|
assert warden.authenticated?(:user)
|
|
48
57
|
end
|
|
49
58
|
|
|
59
|
+
test 'sign out as user should also sign out admin if sign_out_all_scopes is true' do
|
|
60
|
+
Devise.sign_out_all_scopes = true
|
|
61
|
+
sign_in_as_user
|
|
62
|
+
sign_in_as_admin
|
|
63
|
+
|
|
64
|
+
get destroy_user_session_path
|
|
65
|
+
assert_not warden.authenticated?(:user)
|
|
66
|
+
assert_not warden.authenticated?(:admin)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
test 'sign out as admin should also sign out user if sign_out_all_scopes is true' do
|
|
70
|
+
Devise.sign_out_all_scopes = true
|
|
71
|
+
sign_in_as_user
|
|
72
|
+
sign_in_as_admin
|
|
73
|
+
|
|
74
|
+
get destroy_admin_session_path
|
|
75
|
+
assert_not warden.authenticated?(:admin)
|
|
76
|
+
assert_not warden.authenticated?(:user)
|
|
77
|
+
end
|
|
78
|
+
|
|
50
79
|
test 'not signed in as admin should not be able to access admins actions' do
|
|
51
80
|
get admins_path
|
|
52
81
|
|
|
53
|
-
assert_redirected_to new_admin_session_path
|
|
82
|
+
assert_redirected_to new_admin_session_path
|
|
83
|
+
assert_not warden.authenticated?(:admin)
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
test 'not signed in as admin should not be able to access private route restricted to admins' do
|
|
87
|
+
get private_path
|
|
88
|
+
|
|
89
|
+
assert_redirected_to new_admin_session_path
|
|
90
|
+
assert_not warden.authenticated?(:admin)
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
test 'signed in as user should not be able to access private route restricted to admins' do
|
|
94
|
+
sign_in_as_user
|
|
95
|
+
assert warden.authenticated?(:user)
|
|
54
96
|
assert_not warden.authenticated?(:admin)
|
|
97
|
+
|
|
98
|
+
get private_path
|
|
99
|
+
assert_redirected_to new_admin_session_path
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
test 'signed in as admin should be able to access private route restricted to admins' do
|
|
103
|
+
sign_in_as_admin
|
|
104
|
+
assert warden.authenticated?(:admin)
|
|
105
|
+
assert_not warden.authenticated?(:user)
|
|
106
|
+
|
|
107
|
+
get private_path
|
|
108
|
+
|
|
109
|
+
assert_response :success
|
|
110
|
+
assert_template 'home/private'
|
|
111
|
+
assert_contain 'Private!'
|
|
55
112
|
end
|
|
56
113
|
|
|
57
114
|
test 'signed in as user should not be able to access admins actions' do
|
|
@@ -60,7 +117,7 @@ class AuthenticationSanityTest < ActionController::IntegrationTest
|
|
|
60
117
|
assert_not warden.authenticated?(:admin)
|
|
61
118
|
|
|
62
119
|
get admins_path
|
|
63
|
-
assert_redirected_to new_admin_session_path
|
|
120
|
+
assert_redirected_to new_admin_session_path
|
|
64
121
|
end
|
|
65
122
|
|
|
66
123
|
test 'signed in as admin should be able to access admin actions' do
|
|
@@ -107,48 +164,11 @@ class AuthenticationSanityTest < ActionController::IntegrationTest
|
|
|
107
164
|
end
|
|
108
165
|
end
|
|
109
166
|
|
|
110
|
-
class
|
|
111
|
-
test 'sign in should not authenticate if not using proper authentication keys' do
|
|
112
|
-
swap Devise, :authentication_keys => [:username] do
|
|
113
|
-
sign_in_as_user
|
|
114
|
-
assert_not warden.authenticated?(:user)
|
|
115
|
-
end
|
|
116
|
-
end
|
|
117
|
-
|
|
118
|
-
test 'sign in with invalid email should return to sign in form with error message' do
|
|
119
|
-
sign_in_as_admin do
|
|
120
|
-
fill_in 'email', :with => 'wrongemail@test.com'
|
|
121
|
-
end
|
|
122
|
-
|
|
123
|
-
assert_contain 'Invalid email or password'
|
|
124
|
-
assert_not warden.authenticated?(:admin)
|
|
125
|
-
end
|
|
126
|
-
|
|
127
|
-
test 'sign in with invalid pasword should return to sign in form with error message' do
|
|
128
|
-
sign_in_as_admin do
|
|
129
|
-
fill_in 'password', :with => 'abcdef'
|
|
130
|
-
end
|
|
131
|
-
|
|
132
|
-
assert_contain 'Invalid email or password'
|
|
133
|
-
assert_not warden.authenticated?(:admin)
|
|
134
|
-
end
|
|
135
|
-
|
|
136
|
-
test 'error message is configurable by resource name' do
|
|
137
|
-
store_translations :en, :devise => {
|
|
138
|
-
:sessions => { :admin => { :invalid => "Invalid credentials" } }
|
|
139
|
-
} do
|
|
140
|
-
sign_in_as_admin do
|
|
141
|
-
fill_in 'password', :with => 'abcdef'
|
|
142
|
-
end
|
|
143
|
-
|
|
144
|
-
assert_contain 'Invalid credentials'
|
|
145
|
-
end
|
|
146
|
-
end
|
|
147
|
-
|
|
167
|
+
class AuthenticationRedirectTest < ActionController::IntegrationTest
|
|
148
168
|
test 'redirect from warden shows sign in or sign up message' do
|
|
149
169
|
get admins_path
|
|
150
170
|
|
|
151
|
-
warden_path = new_admin_session_path
|
|
171
|
+
warden_path = new_admin_session_path
|
|
152
172
|
assert_redirected_to warden_path
|
|
153
173
|
|
|
154
174
|
get warden_path
|
|
@@ -157,78 +177,68 @@ class AuthenticationTest < ActionController::IntegrationTest
|
|
|
157
177
|
|
|
158
178
|
test 'redirect to default url if no other was configured' do
|
|
159
179
|
sign_in_as_user
|
|
160
|
-
|
|
161
180
|
assert_template 'home/index'
|
|
162
|
-
assert_nil session[:"
|
|
181
|
+
assert_nil session[:"user_return_to"]
|
|
163
182
|
end
|
|
164
183
|
|
|
165
184
|
test 'redirect to requested url after sign in' do
|
|
166
185
|
get users_path
|
|
167
|
-
assert_redirected_to new_user_session_path
|
|
168
|
-
assert_equal users_path, session[:"
|
|
186
|
+
assert_redirected_to new_user_session_path
|
|
187
|
+
assert_equal users_path, session[:"user_return_to"]
|
|
169
188
|
|
|
170
189
|
follow_redirect!
|
|
171
190
|
sign_in_as_user :visit => false
|
|
172
191
|
|
|
173
|
-
|
|
174
|
-
assert_nil session[:"
|
|
192
|
+
assert_current_url '/users'
|
|
193
|
+
assert_nil session[:"user_return_to"]
|
|
175
194
|
end
|
|
176
195
|
|
|
177
196
|
test 'redirect to last requested url overwriting the stored return_to option' do
|
|
178
197
|
get expire_user_path(create_user)
|
|
179
|
-
assert_redirected_to new_user_session_path
|
|
180
|
-
assert_equal expire_user_path(create_user), session[:"
|
|
198
|
+
assert_redirected_to new_user_session_path
|
|
199
|
+
assert_equal expire_user_path(create_user), session[:"user_return_to"]
|
|
181
200
|
|
|
182
201
|
get users_path
|
|
183
|
-
assert_redirected_to new_user_session_path
|
|
184
|
-
assert_equal users_path, session[:"
|
|
202
|
+
assert_redirected_to new_user_session_path
|
|
203
|
+
assert_equal users_path, session[:"user_return_to"]
|
|
185
204
|
|
|
186
205
|
follow_redirect!
|
|
187
206
|
sign_in_as_user :visit => false
|
|
188
207
|
|
|
189
|
-
|
|
190
|
-
assert_nil session[:"
|
|
208
|
+
assert_current_url '/users'
|
|
209
|
+
assert_nil session[:"user_return_to"]
|
|
191
210
|
end
|
|
192
211
|
|
|
193
212
|
test 'xml http requests does not store urls for redirect' do
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
sign_in_as_user
|
|
198
|
-
assert_template 'home/index'
|
|
213
|
+
get users_path, {}, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest'
|
|
214
|
+
assert_equal 401, response.status
|
|
215
|
+
assert_nil session[:"user_return_to"]
|
|
199
216
|
end
|
|
200
217
|
|
|
201
218
|
test 'redirect to configured home path for a given scope after sign in' do
|
|
202
219
|
sign_in_as_admin
|
|
203
220
|
assert_equal "/admin_area/home", @request.path
|
|
204
221
|
end
|
|
222
|
+
end
|
|
205
223
|
|
|
224
|
+
class AuthenticationSessionTest < ActionController::IntegrationTest
|
|
206
225
|
test 'destroyed account is signed out' do
|
|
207
226
|
sign_in_as_user
|
|
208
|
-
|
|
227
|
+
get '/users'
|
|
209
228
|
|
|
210
229
|
User.destroy_all
|
|
211
|
-
|
|
212
|
-
assert_redirected_to
|
|
230
|
+
get '/users'
|
|
231
|
+
assert_redirected_to new_user_session_path
|
|
213
232
|
end
|
|
214
233
|
|
|
215
|
-
test 'allows session to be set
|
|
234
|
+
test 'allows session to be set for a given scope' do
|
|
216
235
|
sign_in_as_user
|
|
217
|
-
visit 'users/index'
|
|
218
|
-
assert_equal "Cart", @controller.user_session[:cart]
|
|
219
|
-
end
|
|
220
|
-
|
|
221
|
-
test 'session id is changed on sign in' do
|
|
222
236
|
get '/users'
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
get '/users'
|
|
226
|
-
assert_equal session_id, request.session[:session_id]
|
|
227
|
-
|
|
228
|
-
sign_in_as_user
|
|
229
|
-
assert_not_equal session_id, request.session[:session_id]
|
|
237
|
+
assert_equal "Cart", @controller.user_session[:cart]
|
|
230
238
|
end
|
|
239
|
+
end
|
|
231
240
|
|
|
241
|
+
class AuthenticationWithScopesTest < ActionController::IntegrationTest
|
|
232
242
|
test 'renders the scoped view if turned on and view is available' do
|
|
233
243
|
swap Devise, :scoped_views => true do
|
|
234
244
|
assert_raise Webrat::NotFoundError do
|
|
@@ -240,15 +250,15 @@ class AuthenticationTest < ActionController::IntegrationTest
|
|
|
240
250
|
|
|
241
251
|
test 'renders the scoped view if turned on in an specific controller' do
|
|
242
252
|
begin
|
|
243
|
-
SessionsController.scoped_views = true
|
|
253
|
+
Devise::SessionsController.scoped_views = true
|
|
244
254
|
assert_raise Webrat::NotFoundError do
|
|
245
255
|
sign_in_as_user
|
|
246
256
|
end
|
|
247
257
|
|
|
248
258
|
assert_match /Special user view/, response.body
|
|
249
|
-
assert !PasswordsController.scoped_views
|
|
259
|
+
assert !Devise::PasswordsController.scoped_views?
|
|
250
260
|
ensure
|
|
251
|
-
SessionsController.send :remove_instance_variable, :@scoped_views
|
|
261
|
+
Devise::SessionsController.send :remove_instance_variable, :@scoped_views
|
|
252
262
|
end
|
|
253
263
|
end
|
|
254
264
|
|
|
@@ -268,73 +278,67 @@ class AuthenticationTest < ActionController::IntegrationTest
|
|
|
268
278
|
end
|
|
269
279
|
end
|
|
270
280
|
|
|
271
|
-
test '
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
end
|
|
276
|
-
|
|
277
|
-
test 'render 404 on roles without mapping' do
|
|
278
|
-
get 'sign_in'
|
|
279
|
-
assert_response :not_found
|
|
280
|
-
assert_not_contain 'Sign in'
|
|
281
|
+
test 'uses the mapping from router' do
|
|
282
|
+
sign_in_as_user :visit => "/as/sign_in"
|
|
283
|
+
assert warden.authenticated?(:user)
|
|
284
|
+
assert_not warden.authenticated?(:admin)
|
|
281
285
|
end
|
|
282
286
|
|
|
283
|
-
test 'uses the mapping from
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
assert_contain 'Sign in'
|
|
288
|
-
end
|
|
287
|
+
test 'uses the mapping from nested devise_for call' do
|
|
288
|
+
sign_in_as_user :visit => "/devise_for/sign_in"
|
|
289
|
+
assert warden.authenticated?(:user)
|
|
290
|
+
assert_not warden.authenticated?(:admin)
|
|
289
291
|
end
|
|
290
292
|
end
|
|
291
293
|
|
|
292
|
-
class
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
294
|
+
class AuthenticationOthersTest < ActionController::IntegrationTest
|
|
295
|
+
test 'uses the custom controller with the custom controller view' do
|
|
296
|
+
get '/admin_area/sign_in'
|
|
297
|
+
assert_contain 'Sign in'
|
|
298
|
+
assert_contain 'Welcome to "sessions" controller!'
|
|
299
|
+
assert_contain 'Welcome to "sessions/new" view!'
|
|
297
300
|
end
|
|
298
301
|
|
|
299
|
-
test '
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
assert_not warden.authenticated?(:sign_out_via_delete)
|
|
302
|
+
test 'render 404 on roles without routes' do
|
|
303
|
+
get '/admin_area/password/new'
|
|
304
|
+
assert_equal 404, response.status
|
|
303
305
|
end
|
|
304
306
|
|
|
305
|
-
test '
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
307
|
+
test 'render 404 on roles without mapping' do
|
|
308
|
+
assert_raise AbstractController::ActionNotFound do
|
|
309
|
+
get '/sign_in'
|
|
310
|
+
end
|
|
309
311
|
end
|
|
310
312
|
|
|
311
|
-
test '
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
313
|
+
test 'sign in with script name' do
|
|
314
|
+
assert_nothing_raised do
|
|
315
|
+
get new_user_session_path, {}, "SCRIPT_NAME" => "/omg"
|
|
316
|
+
fill_in "email", "user@test.com"
|
|
317
|
+
end
|
|
315
318
|
end
|
|
316
319
|
|
|
317
|
-
test '
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
320
|
+
test 'registration in xml format' do
|
|
321
|
+
assert_nothing_raised do
|
|
322
|
+
post user_registration_path(:format => 'xml', :user => {:email => "test@example.com", :password => "invalid"} )
|
|
323
|
+
end
|
|
321
324
|
end
|
|
322
325
|
|
|
323
|
-
test '
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
assert_not warden.authenticated?(:sign_out_via_anymethod)
|
|
327
|
-
end
|
|
326
|
+
test 'does not explode when invalid user class is stored in session' do
|
|
327
|
+
klass = User
|
|
328
|
+
paths = ActiveSupport::Dependencies.autoload_paths.dup
|
|
328
329
|
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
330
|
+
begin
|
|
331
|
+
sign_in_as_user
|
|
332
|
+
assert warden.authenticated?(:user)
|
|
333
|
+
|
|
334
|
+
Object.send :remove_const, :User
|
|
335
|
+
ActiveSupport::Dependencies.autoload_paths.clear
|
|
334
336
|
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
337
|
+
visit "/users"
|
|
338
|
+
assert_not warden.authenticated?(:user)
|
|
339
|
+
ensure
|
|
340
|
+
Object.const_set(:User, klass)
|
|
341
|
+
ActiveSupport::Dependencies.autoload_paths.replace(paths)
|
|
342
|
+
end
|
|
339
343
|
end
|
|
340
344
|
end
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require '
|
|
1
|
+
require 'test_helper'
|
|
2
2
|
|
|
3
3
|
class ConfirmationTest < ActionController::IntegrationTest
|
|
4
4
|
|
|
@@ -11,45 +11,52 @@ class ConfirmationTest < ActionController::IntegrationTest
|
|
|
11
11
|
ActionMailer::Base.deliveries.clear
|
|
12
12
|
|
|
13
13
|
visit new_user_session_path
|
|
14
|
-
click_link
|
|
14
|
+
click_link "Didn't receive confirmation instructions?"
|
|
15
15
|
|
|
16
16
|
fill_in 'email', :with => user.email
|
|
17
17
|
click_button 'Resend confirmation instructions'
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
assert_current_url '/users/sign_in'
|
|
20
20
|
assert_contain 'You will receive an email with instructions about how to confirm your account in a few minutes'
|
|
21
21
|
assert_equal 1, ActionMailer::Base.deliveries.size
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
test 'user with invalid confirmation token should not be able to confirm an account' do
|
|
25
25
|
visit_user_confirmation_with_token('invalid_confirmation')
|
|
26
|
-
|
|
27
|
-
assert_response :success
|
|
28
|
-
assert_template 'confirmations/new'
|
|
29
|
-
assert_have_selector '#errorExplanation'
|
|
26
|
+
assert_have_selector '#error_explanation'
|
|
30
27
|
assert_contain /Confirmation token(.*)invalid/
|
|
31
28
|
end
|
|
32
29
|
|
|
33
30
|
test 'user with valid confirmation token should be able to confirm an account' do
|
|
34
31
|
user = create_user(:confirm => false)
|
|
35
32
|
assert_not user.confirmed?
|
|
36
|
-
|
|
37
33
|
visit_user_confirmation_with_token(user.confirmation_token)
|
|
38
34
|
|
|
39
|
-
assert_template 'home/index'
|
|
40
35
|
assert_contain 'Your account was successfully confirmed.'
|
|
41
|
-
|
|
36
|
+
assert_current_url '/'
|
|
42
37
|
assert user.reload.confirmed?
|
|
43
38
|
end
|
|
44
39
|
|
|
45
|
-
test '
|
|
40
|
+
test 'already confirmed user should not be able to confirm the account again' do
|
|
41
|
+
user = create_user(:confirm => false)
|
|
42
|
+
user.confirmed_at = Time.now
|
|
43
|
+
user.save
|
|
44
|
+
visit_user_confirmation_with_token(user.confirmation_token)
|
|
45
|
+
|
|
46
|
+
assert_have_selector '#error_explanation'
|
|
47
|
+
assert_contain 'already confirmed'
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
test 'already confirmed user should not be able to confirm the account again neither request confirmation' do
|
|
46
51
|
user = create_user(:confirm => false)
|
|
47
52
|
user.confirmed_at = Time.now
|
|
48
53
|
user.save
|
|
54
|
+
|
|
49
55
|
visit_user_confirmation_with_token(user.confirmation_token)
|
|
56
|
+
assert_contain 'already confirmed'
|
|
50
57
|
|
|
51
|
-
|
|
52
|
-
|
|
58
|
+
fill_in 'email', :with => user.email
|
|
59
|
+
click_button 'Resend confirmation instructions'
|
|
53
60
|
assert_contain 'already confirmed'
|
|
54
61
|
end
|
|
55
62
|
|
|
@@ -88,9 +95,9 @@ class ConfirmationTest < ActionController::IntegrationTest
|
|
|
88
95
|
|
|
89
96
|
test 'error message is configurable by resource name' do
|
|
90
97
|
store_translations :en, :devise => {
|
|
91
|
-
:
|
|
98
|
+
:failure => { :user => { :unconfirmed => "Not confirmed user" } }
|
|
92
99
|
} do
|
|
93
|
-
|
|
100
|
+
sign_in_as_user(:confirm => false)
|
|
94
101
|
assert_contain 'Not confirmed user'
|
|
95
102
|
end
|
|
96
103
|
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class DatabaseAuthenticationTest < ActionController::IntegrationTest
|
|
4
|
+
test 'sign in should not authenticate if not using proper authentication keys' do
|
|
5
|
+
swap Devise, :authentication_keys => [:username] do
|
|
6
|
+
sign_in_as_user
|
|
7
|
+
assert_not warden.authenticated?(:user)
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
test 'sign in with invalid email should return to sign in form with error message' do
|
|
12
|
+
sign_in_as_admin do
|
|
13
|
+
fill_in 'email', :with => 'wrongemail@test.com'
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
assert_contain 'Invalid email or password'
|
|
17
|
+
assert_not warden.authenticated?(:admin)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
test 'sign in with invalid pasword should return to sign in form with error message' do
|
|
21
|
+
sign_in_as_admin do
|
|
22
|
+
fill_in 'password', :with => 'abcdef'
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
assert_contain 'Invalid email or password'
|
|
26
|
+
assert_not warden.authenticated?(:admin)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
test 'error message is configurable by resource name' do
|
|
30
|
+
store_translations :en, :devise => { :failure => { :admin => { :invalid => "Invalid credentials" } } } do
|
|
31
|
+
sign_in_as_admin do
|
|
32
|
+
fill_in 'password', :with => 'abcdef'
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
assert_contain 'Invalid credentials'
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|