loyal_devise 2.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +10 -0
- data/.travis.yml +15 -0
- data/CHANGELOG.rdoc +881 -0
- data/CONTRIBUTING.md +12 -0
- data/Gemfile +31 -0
- data/Gemfile.lock +154 -0
- data/MIT-LICENSE +20 -0
- data/README.md +388 -0
- data/Rakefile +34 -0
- data/app/controllers/devise/confirmations_controller.rb +44 -0
- data/app/controllers/devise/omniauth_callbacks_controller.rb +31 -0
- data/app/controllers/devise/passwords_controller.rb +57 -0
- data/app/controllers/devise/registrations_controller.rb +120 -0
- data/app/controllers/devise/sessions_controller.rb +51 -0
- data/app/controllers/devise/unlocks_controller.rb +45 -0
- data/app/controllers/devise_controller.rb +193 -0
- data/app/helpers/devise_helper.rb +26 -0
- data/app/mailers/devise/mailer.rb +16 -0
- data/app/views/devise/_links.erb +3 -0
- data/app/views/devise/confirmations/new.html.erb +12 -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/devise/mailer/unlock_instructions.html.erb +7 -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 +25 -0
- data/app/views/devise/unlocks/new.html.erb +12 -0
- data/config/locales/en.yml +59 -0
- data/devise.gemspec +26 -0
- data/gemfiles/Gemfile.rails-3.1.x +35 -0
- data/gemfiles/Gemfile.rails-3.1.x.lock +167 -0
- data/lib/devise/controllers/helpers.rb +273 -0
- data/lib/devise/controllers/rememberable.rb +53 -0
- data/lib/devise/controllers/scoped_views.rb +18 -0
- data/lib/devise/controllers/url_helpers.rb +68 -0
- data/lib/devise/delegator.rb +17 -0
- data/lib/devise/failure_app.rb +188 -0
- data/lib/devise/hooks/activatable.rb +12 -0
- data/lib/devise/hooks/forgetable.rb +10 -0
- data/lib/devise/hooks/lockable.rb +8 -0
- data/lib/devise/hooks/rememberable.rb +7 -0
- data/lib/devise/hooks/timeoutable.rb +26 -0
- data/lib/devise/hooks/trackable.rb +10 -0
- data/lib/devise/mailers/helpers.rb +92 -0
- data/lib/devise/mapping.rb +173 -0
- data/lib/devise/models/authenticatable.rb +269 -0
- data/lib/devise/models/confirmable.rb +271 -0
- data/lib/devise/models/database_authenticatable.rb +127 -0
- data/lib/devise/models/lockable.rb +194 -0
- data/lib/devise/models/omniauthable.rb +28 -0
- data/lib/devise/models/recoverable.rb +141 -0
- data/lib/devise/models/registerable.rb +26 -0
- data/lib/devise/models/rememberable.rb +126 -0
- data/lib/devise/models/timeoutable.rb +50 -0
- data/lib/devise/models/token_authenticatable.rb +90 -0
- data/lib/devise/models/trackable.rb +36 -0
- data/lib/devise/models/validatable.rb +67 -0
- data/lib/devise/models.rb +129 -0
- data/lib/devise/modules.rb +30 -0
- data/lib/devise/omniauth/config.rb +46 -0
- data/lib/devise/omniauth/url_helpers.rb +19 -0
- data/lib/devise/omniauth.rb +29 -0
- data/lib/devise/orm/active_record.rb +4 -0
- data/lib/devise/orm/mongoid.rb +4 -0
- data/lib/devise/param_filter.rb +42 -0
- data/lib/devise/rails/routes.rb +447 -0
- data/lib/devise/rails/warden_compat.rb +44 -0
- data/lib/devise/rails.rb +55 -0
- data/lib/devise/strategies/authenticatable.rb +177 -0
- data/lib/devise/strategies/base.rb +21 -0
- data/lib/devise/strategies/database_authenticatable.rb +21 -0
- data/lib/devise/strategies/rememberable.rb +56 -0
- data/lib/devise/strategies/token_authenticatable.rb +57 -0
- data/lib/devise/test_helpers.rb +132 -0
- data/lib/devise/time_inflector.rb +15 -0
- data/lib/devise/version.rb +4 -0
- data/lib/devise.rb +445 -0
- data/lib/generators/active_record/devise_generator.rb +80 -0
- data/lib/generators/active_record/templates/migration.rb +20 -0
- data/lib/generators/active_record/templates/migration_existing.rb +27 -0
- data/lib/generators/devise/devise_generator.rb +25 -0
- data/lib/generators/devise/install_generator.rb +25 -0
- data/lib/generators/devise/orm_helpers.rb +33 -0
- data/lib/generators/devise/views_generator.rb +117 -0
- data/lib/generators/mongoid/devise_generator.rb +58 -0
- data/lib/generators/templates/README +35 -0
- data/lib/generators/templates/devise.rb +241 -0
- data/lib/generators/templates/markerb/confirmation_instructions.markerb +5 -0
- data/lib/generators/templates/markerb/reset_password_instructions.markerb +8 -0
- data/lib/generators/templates/markerb/unlock_instructions.markerb +7 -0
- data/lib/generators/templates/simple_form_for/confirmations/new.html.erb +15 -0
- data/lib/generators/templates/simple_form_for/passwords/edit.html.erb +19 -0
- data/lib/generators/templates/simple_form_for/passwords/new.html.erb +15 -0
- data/lib/generators/templates/simple_form_for/registrations/edit.html.erb +22 -0
- data/lib/generators/templates/simple_form_for/registrations/new.html.erb +17 -0
- data/lib/generators/templates/simple_form_for/sessions/new.html.erb +15 -0
- data/lib/generators/templates/simple_form_for/unlocks/new.html.erb +15 -0
- data/test/controllers/custom_strategy_test.rb +63 -0
- data/test/controllers/helpers_test.rb +254 -0
- data/test/controllers/internal_helpers_test.rb +111 -0
- data/test/controllers/sessions_controller_test.rb +58 -0
- data/test/controllers/url_helpers_test.rb +60 -0
- data/test/delegator_test.rb +20 -0
- data/test/devise_test.rb +73 -0
- data/test/failure_app_test.rb +222 -0
- data/test/generators/active_record_generator_test.rb +76 -0
- data/test/generators/devise_generator_test.rb +40 -0
- data/test/generators/install_generator_test.rb +14 -0
- data/test/generators/mongoid_generator_test.rb +24 -0
- data/test/generators/views_generator_test.rb +53 -0
- data/test/helpers/devise_helper_test.rb +52 -0
- data/test/indifferent_hash.rb +34 -0
- data/test/integration/authenticatable_test.rb +634 -0
- data/test/integration/confirmable_test.rb +299 -0
- data/test/integration/database_authenticatable_test.rb +83 -0
- data/test/integration/http_authenticatable_test.rb +98 -0
- data/test/integration/lockable_test.rb +243 -0
- data/test/integration/omniauthable_test.rb +134 -0
- data/test/integration/recoverable_test.rb +307 -0
- data/test/integration/registerable_test.rb +346 -0
- data/test/integration/rememberable_test.rb +159 -0
- data/test/integration/timeoutable_test.rb +141 -0
- data/test/integration/token_authenticatable_test.rb +162 -0
- data/test/integration/trackable_test.rb +93 -0
- data/test/mailers/confirmation_instructions_test.rb +103 -0
- data/test/mailers/reset_password_instructions_test.rb +84 -0
- data/test/mailers/unlock_instructions_test.rb +78 -0
- data/test/mapping_test.rb +128 -0
- data/test/models/authenticatable_test.rb +8 -0
- data/test/models/confirmable_test.rb +392 -0
- data/test/models/database_authenticatable_test.rb +190 -0
- data/test/models/lockable_test.rb +274 -0
- data/test/models/omniauthable_test.rb +8 -0
- data/test/models/recoverable_test.rb +206 -0
- data/test/models/registerable_test.rb +8 -0
- data/test/models/rememberable_test.rb +175 -0
- data/test/models/serializable_test.rb +49 -0
- data/test/models/timeoutable_test.rb +47 -0
- data/test/models/token_authenticatable_test.rb +56 -0
- data/test/models/trackable_test.rb +14 -0
- data/test/models/validatable_test.rb +117 -0
- data/test/models_test.rb +180 -0
- data/test/omniauth/config_test.rb +58 -0
- data/test/omniauth/url_helpers_test.rb +52 -0
- data/test/orm/active_record.rb +10 -0
- data/test/orm/mongoid.rb +15 -0
- data/test/rails_app/Rakefile +10 -0
- data/test/rails_app/app/active_record/admin.rb +7 -0
- data/test/rails_app/app/active_record/shim.rb +3 -0
- data/test/rails_app/app/active_record/user.rb +7 -0
- data/test/rails_app/app/controllers/admins/sessions_controller.rb +7 -0
- data/test/rails_app/app/controllers/admins_controller.rb +12 -0
- data/test/rails_app/app/controllers/application_controller.rb +9 -0
- data/test/rails_app/app/controllers/home_controller.rb +26 -0
- data/test/rails_app/app/controllers/publisher/registrations_controller.rb +3 -0
- data/test/rails_app/app/controllers/publisher/sessions_controller.rb +3 -0
- data/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb +15 -0
- data/test/rails_app/app/controllers/users_controller.rb +24 -0
- data/test/rails_app/app/helpers/application_helper.rb +4 -0
- data/test/rails_app/app/mailers/users/mailer.rb +9 -0
- data/test/rails_app/app/mongoid/admin.rb +28 -0
- data/test/rails_app/app/mongoid/shim.rb +25 -0
- data/test/rails_app/app/mongoid/user.rb +43 -0
- data/test/rails_app/app/views/admins/index.html.erb +1 -0
- data/test/rails_app/app/views/admins/sessions/new.html.erb +2 -0
- data/test/rails_app/app/views/home/admin_dashboard.html.erb +1 -0
- data/test/rails_app/app/views/home/index.html.erb +1 -0
- data/test/rails_app/app/views/home/join.html.erb +1 -0
- data/test/rails_app/app/views/home/private.html.erb +1 -0
- data/test/rails_app/app/views/home/user_dashboard.html.erb +1 -0
- data/test/rails_app/app/views/layouts/application.html.erb +24 -0
- data/test/rails_app/app/views/users/index.html.erb +1 -0
- data/test/rails_app/app/views/users/mailer/confirmation_instructions.erb +1 -0
- data/test/rails_app/app/views/users/sessions/new.html.erb +1 -0
- data/test/rails_app/config/application.rb +42 -0
- data/test/rails_app/config/boot.rb +9 -0
- data/test/rails_app/config/database.yml +18 -0
- data/test/rails_app/config/environment.rb +6 -0
- data/test/rails_app/config/environments/development.rb +19 -0
- data/test/rails_app/config/environments/production.rb +34 -0
- data/test/rails_app/config/environments/test.rb +34 -0
- data/test/rails_app/config/initializers/backtrace_silencers.rb +8 -0
- data/test/rails_app/config/initializers/devise.rb +179 -0
- data/test/rails_app/config/initializers/inflections.rb +3 -0
- data/test/rails_app/config/initializers/secret_token.rb +3 -0
- data/test/rails_app/config/routes.rb +101 -0
- data/test/rails_app/config.ru +4 -0
- data/test/rails_app/db/migrate/20100401102949_create_tables.rb +75 -0
- data/test/rails_app/db/schema.rb +53 -0
- data/test/rails_app/lib/shared_admin.rb +15 -0
- data/test/rails_app/lib/shared_user.rb +27 -0
- data/test/rails_app/public/404.html +26 -0
- data/test/rails_app/public/422.html +26 -0
- data/test/rails_app/public/500.html +26 -0
- data/test/rails_app/public/favicon.ico +0 -0
- data/test/rails_app/script/rails +10 -0
- data/test/routes_test.rb +249 -0
- data/test/support/assertions.rb +41 -0
- data/test/support/helpers.rb +92 -0
- data/test/support/integration.rb +93 -0
- data/test/support/locale/en.yml +4 -0
- data/test/support/webrat/integrations/rails.rb +25 -0
- data/test/test_helper.rb +28 -0
- data/test/test_helpers_test.rb +152 -0
- metadata +407 -0
@@ -0,0 +1,162 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
class TokenAuthenticationTest < ActionController::IntegrationTest
|
5
|
+
|
6
|
+
test 'authenticate with valid authentication token key and value through params' do
|
7
|
+
swap Devise, :token_authentication_key => :secret_token do
|
8
|
+
sign_in_as_new_user_with_token
|
9
|
+
|
10
|
+
assert_response :success
|
11
|
+
assert_current_url "/users?secret_token=#{VALID_AUTHENTICATION_TOKEN}"
|
12
|
+
assert_contain 'Welcome'
|
13
|
+
assert warden.authenticated?(:user)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
test 'authenticate with valid authentication token key and value through params, when params with the same key as scope exist' do
|
18
|
+
swap Devise, :token_authentication_key => :secret_token do
|
19
|
+
user = create_user_with_authentication_token
|
20
|
+
post exhibit_user_path(user), Devise.token_authentication_key => user.authentication_token, :user => { :some => "data" }
|
21
|
+
|
22
|
+
assert_response :success
|
23
|
+
assert_contain 'User is authenticated'
|
24
|
+
assert warden.authenticated?(:user)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
test 'authenticate with valid authentication token key but does not store if stateless' do
|
29
|
+
swap Devise, :token_authentication_key => :secret_token, :skip_session_storage => [:token_auth] do
|
30
|
+
sign_in_as_new_user_with_token
|
31
|
+
assert warden.authenticated?(:user)
|
32
|
+
|
33
|
+
get users_path
|
34
|
+
assert_redirected_to new_user_session_path
|
35
|
+
assert_not warden.authenticated?(:user)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
test 'authenticate with valid authentication token key and value through http' do
|
40
|
+
swap Devise, :token_authentication_key => :secret_token do
|
41
|
+
sign_in_as_new_user_with_token(:http_auth => true)
|
42
|
+
|
43
|
+
assert_response :success
|
44
|
+
assert_match '<email>user@test.com</email>', response.body
|
45
|
+
assert warden.authenticated?(:user)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
test 'does authenticate with valid authentication token key and value through params if not configured' do
|
50
|
+
swap Devise, :token_authentication_key => :secret_token, :params_authenticatable => [:database] do
|
51
|
+
sign_in_as_new_user_with_token
|
52
|
+
|
53
|
+
assert_contain 'You need to sign in or sign up before continuing'
|
54
|
+
assert_contain 'Sign in'
|
55
|
+
assert_not warden.authenticated?(:user)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
test 'does authenticate with valid authentication token key and value through http if not configured' do
|
60
|
+
swap Devise, :token_authentication_key => :secret_token, :http_authenticatable => [:database] do
|
61
|
+
sign_in_as_new_user_with_token(:http_auth => true)
|
62
|
+
|
63
|
+
assert_response 401
|
64
|
+
assert_contain 'Invalid email or password.'
|
65
|
+
assert_not warden.authenticated?(:user)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
test 'does not authenticate with improper authentication token key' do
|
70
|
+
swap Devise, :token_authentication_key => :donald_duck_token do
|
71
|
+
sign_in_as_new_user_with_token(:auth_token_key => :secret_token)
|
72
|
+
assert_equal new_user_session_path, @request.path
|
73
|
+
|
74
|
+
assert_contain 'You need to sign in or sign up before continuing'
|
75
|
+
assert_contain 'Sign in'
|
76
|
+
assert_not warden.authenticated?(:user)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
test 'does not authenticate with improper authentication token value' do
|
81
|
+
store_translations :en, :devise => {:failure => {:invalid_token => 'LOL, that was not a single character correct.'}} do
|
82
|
+
sign_in_as_new_user_with_token(:auth_token => '*** INVALID TOKEN ***')
|
83
|
+
assert_equal new_user_session_path, @request.path
|
84
|
+
|
85
|
+
assert_contain 'LOL, that was not a single character correct.'
|
86
|
+
assert_contain 'Sign in'
|
87
|
+
assert_not warden.authenticated?(:user)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
test 'authenticate with valid authentication token key and do not store if stateless and timeoutable are enabled' do
|
92
|
+
swap Devise, :token_authentication_key => :secret_token, :skip_session_storage => [:token_auth], :timeout_in => (0.1).second do
|
93
|
+
user = sign_in_as_new_user_with_token
|
94
|
+
assert warden.authenticated?(:user)
|
95
|
+
|
96
|
+
# Expiring does not work because we are setting the session value when accessing it
|
97
|
+
sleep 0.3
|
98
|
+
|
99
|
+
get_users_path_as_existing_user(user)
|
100
|
+
assert warden.authenticated?(:user)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
test 'should reset token and not authenticate when expire_auth_token_on_timeout is set to true, timeoutable is enabled and we have a timed out session' do
|
105
|
+
swap Devise, :token_authentication_key => :secret_token, :expire_auth_token_on_timeout => true, :timeout_in => (-1).minute do
|
106
|
+
user = sign_in_as_new_user_with_token
|
107
|
+
assert warden.authenticated?(:user)
|
108
|
+
token = user.authentication_token
|
109
|
+
|
110
|
+
get_users_path_as_existing_user(user)
|
111
|
+
assert_not warden.authenticated?(:user)
|
112
|
+
user.reload
|
113
|
+
assert_not_equal token, user.authentication_token
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
test 'should not be subject to injection' do
|
118
|
+
swap Devise, :token_authentication_key => :secret_token do
|
119
|
+
user1 = create_user_with_authentication_token()
|
120
|
+
|
121
|
+
# Clean up user cache
|
122
|
+
@user = nil
|
123
|
+
|
124
|
+
user2 = create_user_with_authentication_token(:email => "another@test.com")
|
125
|
+
user2.update_attribute(:authentication_token, "ANOTHERTOKEN")
|
126
|
+
|
127
|
+
assert_not_equal user1, user2
|
128
|
+
visit users_path(Devise.token_authentication_key.to_s + '[$ne]' => user1.authentication_token)
|
129
|
+
assert_nil warden.user(:user)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
private
|
134
|
+
|
135
|
+
def sign_in_as_new_user_with_token(options = {})
|
136
|
+
user = options.delete(:user) || create_user_with_authentication_token(options)
|
137
|
+
|
138
|
+
options[:auth_token_key] ||= Devise.token_authentication_key
|
139
|
+
options[:auth_token] ||= user.authentication_token
|
140
|
+
|
141
|
+
if options[:http_auth]
|
142
|
+
header = "Basic #{Base64.encode64("#{VALID_AUTHENTICATION_TOKEN}:X")}"
|
143
|
+
get users_path(:format => :xml), {}, "HTTP_AUTHORIZATION" => header
|
144
|
+
else
|
145
|
+
visit users_path(options[:auth_token_key].to_sym => options[:auth_token])
|
146
|
+
end
|
147
|
+
|
148
|
+
user
|
149
|
+
end
|
150
|
+
|
151
|
+
def create_user_with_authentication_token(options={})
|
152
|
+
user = create_user(options)
|
153
|
+
user.authentication_token = VALID_AUTHENTICATION_TOKEN
|
154
|
+
user.save
|
155
|
+
user
|
156
|
+
end
|
157
|
+
|
158
|
+
def get_users_path_as_existing_user(user)
|
159
|
+
sign_in_as_new_user_with_token(:user => user)
|
160
|
+
end
|
161
|
+
|
162
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
class TrackableHooksTest < ActionController::IntegrationTest
|
5
|
+
|
6
|
+
test "current and last sign in timestamps are updated on each sign in" do
|
7
|
+
user = create_user
|
8
|
+
assert_nil user.current_sign_in_at
|
9
|
+
assert_nil user.last_sign_in_at
|
10
|
+
|
11
|
+
sign_in_as_user
|
12
|
+
user.reload
|
13
|
+
|
14
|
+
assert_kind_of Time, user.current_sign_in_at
|
15
|
+
assert_kind_of Time, user.last_sign_in_at
|
16
|
+
|
17
|
+
assert_equal user.current_sign_in_at, user.last_sign_in_at
|
18
|
+
assert user.current_sign_in_at >= user.created_at
|
19
|
+
|
20
|
+
visit destroy_user_session_path
|
21
|
+
new_time = 2.seconds.from_now
|
22
|
+
Time.stubs(:now).returns(new_time)
|
23
|
+
|
24
|
+
sign_in_as_user
|
25
|
+
user.reload
|
26
|
+
assert user.current_sign_in_at > user.last_sign_in_at
|
27
|
+
end
|
28
|
+
|
29
|
+
test "current and last sign in remote ip are updated on each sign in" do
|
30
|
+
user = create_user
|
31
|
+
assert_nil user.current_sign_in_ip
|
32
|
+
assert_nil user.last_sign_in_ip
|
33
|
+
|
34
|
+
sign_in_as_user
|
35
|
+
user.reload
|
36
|
+
|
37
|
+
assert_equal "127.0.0.1", user.current_sign_in_ip
|
38
|
+
assert_equal "127.0.0.1", user.last_sign_in_ip
|
39
|
+
end
|
40
|
+
|
41
|
+
test "current remote ip returns original ip behind a non transparent proxy" do
|
42
|
+
user = create_user
|
43
|
+
|
44
|
+
arbitrary_ip = '200.121.1.69'
|
45
|
+
sign_in_as_user do
|
46
|
+
header 'HTTP_X_FORWARDED_FOR', arbitrary_ip
|
47
|
+
end
|
48
|
+
user.reload
|
49
|
+
assert_equal arbitrary_ip, user.current_sign_in_ip
|
50
|
+
end
|
51
|
+
|
52
|
+
test "increase sign in count" do
|
53
|
+
user = create_user
|
54
|
+
assert_equal 0, user.sign_in_count
|
55
|
+
|
56
|
+
sign_in_as_user
|
57
|
+
user.reload
|
58
|
+
assert_equal 1, user.sign_in_count
|
59
|
+
|
60
|
+
visit destroy_user_session_path
|
61
|
+
sign_in_as_user
|
62
|
+
user.reload
|
63
|
+
assert_equal 2, user.sign_in_count
|
64
|
+
end
|
65
|
+
|
66
|
+
test "does not update anything if user has signed out along the way" do
|
67
|
+
swap Devise, :allow_unconfirmed_access_for => 0 do
|
68
|
+
user = create_user(:confirm => false)
|
69
|
+
sign_in_as_user
|
70
|
+
|
71
|
+
user.reload
|
72
|
+
assert_nil user.current_sign_in_at
|
73
|
+
assert_nil user.last_sign_in_at
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
test "do not track if devise.skip_trackable is set" do
|
78
|
+
user = create_user
|
79
|
+
sign_in_as_user do
|
80
|
+
header 'devise.skip_trackable', '1'
|
81
|
+
end
|
82
|
+
user.reload
|
83
|
+
assert_equal 0, user.sign_in_count
|
84
|
+
visit destroy_user_session_path
|
85
|
+
|
86
|
+
sign_in_as_user do
|
87
|
+
header 'devise.skip_trackable', false
|
88
|
+
end
|
89
|
+
user.reload
|
90
|
+
assert_equal 1, user.sign_in_count
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
class ConfirmationInstructionsTest < ActionMailer::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
setup_mailer
|
8
|
+
Devise.mailer = 'Devise::Mailer'
|
9
|
+
Devise.mailer_sender = 'test@example.com'
|
10
|
+
end
|
11
|
+
|
12
|
+
def teardown
|
13
|
+
Devise.mailer = 'Devise::Mailer'
|
14
|
+
Devise.mailer_sender = 'please-change-me@config-initializers-devise.com'
|
15
|
+
end
|
16
|
+
|
17
|
+
def user
|
18
|
+
@user ||= create_user
|
19
|
+
end
|
20
|
+
|
21
|
+
def mail
|
22
|
+
@mail ||= begin
|
23
|
+
user
|
24
|
+
ActionMailer::Base.deliveries.first
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
test 'email sent after creating the user' do
|
29
|
+
assert_not_nil mail
|
30
|
+
end
|
31
|
+
|
32
|
+
test 'content type should be set to html' do
|
33
|
+
assert mail.content_type.include?('text/html')
|
34
|
+
end
|
35
|
+
|
36
|
+
test 'send confirmation instructions to the user email' do
|
37
|
+
mail
|
38
|
+
assert_equal [user.email], mail.to
|
39
|
+
end
|
40
|
+
|
41
|
+
test 'setup sender from configuration' do
|
42
|
+
assert_equal ['test@example.com'], mail.from
|
43
|
+
end
|
44
|
+
|
45
|
+
test 'setup sender from custom mailer defaults' do
|
46
|
+
Devise.mailer = 'Users::Mailer'
|
47
|
+
assert_equal ['custom@example.com'], mail.from
|
48
|
+
end
|
49
|
+
|
50
|
+
test 'setup reply to as copy from sender' do
|
51
|
+
assert_equal ['test@example.com'], mail.reply_to
|
52
|
+
end
|
53
|
+
|
54
|
+
test 'setup reply to as different if set in defaults' do
|
55
|
+
Devise.mailer = 'Users::ReplyToMailer'
|
56
|
+
assert_equal ['custom@example.com'], mail.from
|
57
|
+
assert_equal ['custom_reply_to@example.com'], mail.reply_to
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
test 'setup subject from I18n' do
|
62
|
+
store_translations :en, :devise => { :mailer => { :confirmation_instructions => { :subject => 'Account Confirmation' } } } do
|
63
|
+
assert_equal 'Account Confirmation', mail.subject
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
test 'subject namespaced by model' do
|
68
|
+
store_translations :en, :devise => { :mailer => { :confirmation_instructions => { :user_subject => 'User Account Confirmation' } } } do
|
69
|
+
assert_equal 'User Account Confirmation', mail.subject
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
test 'body should have user info' do
|
74
|
+
assert_match /#{user.email}/, mail.body.encoded
|
75
|
+
end
|
76
|
+
|
77
|
+
test 'body should have link to confirm the account' do
|
78
|
+
host = ActionMailer::Base.default_url_options[:host]
|
79
|
+
confirmation_url_regexp = %r{<a href=\"http://#{host}/users/confirmation\?confirmation_token=#{user.confirmation_token}">}
|
80
|
+
assert_match confirmation_url_regexp, mail.body.encoded
|
81
|
+
end
|
82
|
+
|
83
|
+
test 'renders a scoped if scoped_views is set to true' do
|
84
|
+
swap Devise, :scoped_views => true do
|
85
|
+
assert_equal user.email, mail.body.decoded
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
test 'renders a scoped if scoped_views is set in the mailer class' do
|
90
|
+
begin
|
91
|
+
Devise::Mailer.scoped_views = true
|
92
|
+
assert_equal user.email, mail.body.decoded
|
93
|
+
ensure
|
94
|
+
Devise::Mailer.send :remove_instance_variable, :@scoped_views
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
test 'mailer sender accepts a proc' do
|
99
|
+
swap Devise, :mailer_sender => proc { "another@example.com" } do
|
100
|
+
assert_equal ['another@example.com'], mail.from
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
class ResetPasswordInstructionsTest < ActionMailer::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
setup_mailer
|
8
|
+
Devise.mailer = 'Devise::Mailer'
|
9
|
+
Devise.mailer_sender = 'test@example.com'
|
10
|
+
end
|
11
|
+
|
12
|
+
def teardown
|
13
|
+
Devise.mailer = 'Devise::Mailer'
|
14
|
+
Devise.mailer_sender = 'please-change-me@config-initializers-devise.com'
|
15
|
+
end
|
16
|
+
|
17
|
+
def user
|
18
|
+
@user ||= begin
|
19
|
+
user = create_user
|
20
|
+
user.send_reset_password_instructions
|
21
|
+
user
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def mail
|
26
|
+
@mail ||= begin
|
27
|
+
user
|
28
|
+
ActionMailer::Base.deliveries.last
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
test 'email sent after reseting the user password' do
|
33
|
+
assert_not_nil mail
|
34
|
+
end
|
35
|
+
|
36
|
+
test 'content type should be set to html' do
|
37
|
+
assert mail.content_type.include?('text/html')
|
38
|
+
end
|
39
|
+
|
40
|
+
test 'send confirmation instructions to the user email' do
|
41
|
+
assert_equal [user.email], mail.to
|
42
|
+
end
|
43
|
+
|
44
|
+
test 'setup sender from configuration' do
|
45
|
+
assert_equal ['test@example.com'], mail.from
|
46
|
+
end
|
47
|
+
|
48
|
+
test 'setup sender from custom mailer defaults' do
|
49
|
+
Devise.mailer = 'Users::Mailer'
|
50
|
+
assert_equal ['custom@example.com'], mail.from
|
51
|
+
end
|
52
|
+
|
53
|
+
test 'setup reply to as copy from sender' do
|
54
|
+
assert_equal ['test@example.com'], mail.reply_to
|
55
|
+
end
|
56
|
+
|
57
|
+
test 'setup subject from I18n' do
|
58
|
+
store_translations :en, :devise => { :mailer => { :reset_password_instructions => { :subject => 'Reset instructions' } } } do
|
59
|
+
assert_equal 'Reset instructions', mail.subject
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
test 'subject namespaced by model' do
|
64
|
+
store_translations :en, :devise => { :mailer => { :reset_password_instructions => { :user_subject => 'User Reset Instructions' } } } do
|
65
|
+
assert_equal 'User Reset Instructions', mail.subject
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
test 'body should have user info' do
|
70
|
+
assert_match(/#{user.email}/, mail.body.encoded)
|
71
|
+
end
|
72
|
+
|
73
|
+
test 'body should have link to confirm the account' do
|
74
|
+
host = ActionMailer::Base.default_url_options[:host]
|
75
|
+
reset_url_regexp = %r{<a href=\"http://#{host}/users/password/edit\?reset_password_token=#{user.reset_password_token}">}
|
76
|
+
assert_match reset_url_regexp, mail.body.encoded
|
77
|
+
end
|
78
|
+
|
79
|
+
test 'mailer sender accepts a proc' do
|
80
|
+
swap Devise, :mailer_sender => proc { "another@example.com" } do
|
81
|
+
assert_equal ['another@example.com'], mail.from
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
class UnlockInstructionsTest < ActionMailer::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
setup_mailer
|
8
|
+
Devise.mailer = 'Devise::Mailer'
|
9
|
+
Devise.mailer_sender = 'test@example.com'
|
10
|
+
end
|
11
|
+
|
12
|
+
def teardown
|
13
|
+
Devise.mailer = 'Devise::Mailer'
|
14
|
+
Devise.mailer_sender = 'please-change-me@config-initializers-devise.com'
|
15
|
+
end
|
16
|
+
|
17
|
+
def user
|
18
|
+
@user ||= begin
|
19
|
+
user = create_user
|
20
|
+
user.lock_access!
|
21
|
+
user
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def mail
|
26
|
+
@mail ||= begin
|
27
|
+
user
|
28
|
+
ActionMailer::Base.deliveries.last
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
test 'email sent after locking the user' do
|
33
|
+
assert_not_nil mail
|
34
|
+
end
|
35
|
+
|
36
|
+
test 'content type should be set to html' do
|
37
|
+
assert mail.content_type.include?('text/html')
|
38
|
+
end
|
39
|
+
|
40
|
+
test 'send unlock instructions to the user email' do
|
41
|
+
assert_equal [user.email], mail.to
|
42
|
+
end
|
43
|
+
|
44
|
+
test 'setup sender from configuration' do
|
45
|
+
assert_equal ['test@example.com'], mail.from
|
46
|
+
end
|
47
|
+
|
48
|
+
test 'setup sender from custom mailer defaults' do
|
49
|
+
Devise.mailer = 'Users::Mailer'
|
50
|
+
assert_equal ['custom@example.com'], mail.from
|
51
|
+
end
|
52
|
+
|
53
|
+
test 'setup reply to as copy from sender' do
|
54
|
+
assert_equal ['test@example.com'], mail.reply_to
|
55
|
+
end
|
56
|
+
|
57
|
+
test 'setup subject from I18n' do
|
58
|
+
store_translations :en, :devise => { :mailer => { :unlock_instructions => { :subject => 'Yo unlock instructions' } } } do
|
59
|
+
assert_equal 'Yo unlock instructions', mail.subject
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
test 'subject namespaced by model' do
|
64
|
+
store_translations :en, :devise => { :mailer => { :unlock_instructions => { :user_subject => 'User Unlock Instructions' } } } do
|
65
|
+
assert_equal 'User Unlock Instructions', mail.subject
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
test 'body should have user info' do
|
70
|
+
assert_match(/#{user.email}/, mail.body.encoded)
|
71
|
+
end
|
72
|
+
|
73
|
+
test 'body should have link to unlock the account' do
|
74
|
+
host = ActionMailer::Base.default_url_options[:host]
|
75
|
+
unlock_url_regexp = %r{<a href=\"http://#{host}/users/unlock\?unlock_token=#{user.unlock_token}">}
|
76
|
+
assert_match unlock_url_regexp, mail.body.encoded
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,128 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
class FakeRequest < Struct.new(:path_info, :params)
|
5
|
+
end
|
6
|
+
|
7
|
+
class MappingTest < ActiveSupport::TestCase
|
8
|
+
def fake_request(path, params={})
|
9
|
+
FakeRequest.new(path, params)
|
10
|
+
end
|
11
|
+
|
12
|
+
test 'store options' do
|
13
|
+
mapping = Devise.mappings[:user]
|
14
|
+
assert_equal User, mapping.to
|
15
|
+
assert_equal User.devise_modules, mapping.modules
|
16
|
+
assert_equal "users", mapping.scoped_path
|
17
|
+
assert_equal :user, mapping.singular
|
18
|
+
assert_equal "users", mapping.path
|
19
|
+
assert_equal "/users", mapping.fullpath
|
20
|
+
end
|
21
|
+
|
22
|
+
test 'store options with namespace' do
|
23
|
+
mapping = Devise.mappings[:publisher_account]
|
24
|
+
assert_equal Admin, mapping.to
|
25
|
+
assert_equal "publisher/accounts", mapping.scoped_path
|
26
|
+
assert_equal :publisher_account, mapping.singular
|
27
|
+
assert_equal "accounts", mapping.path
|
28
|
+
assert_equal "/publisher/accounts", mapping.fullpath
|
29
|
+
end
|
30
|
+
|
31
|
+
test 'allows path to be given' do
|
32
|
+
assert_equal "admin_area", Devise.mappings[:admin].path
|
33
|
+
end
|
34
|
+
|
35
|
+
test 'allows to skip all routes' do
|
36
|
+
assert_equal [], Devise.mappings[:skip_admin].used_routes
|
37
|
+
end
|
38
|
+
|
39
|
+
test 'sign_out_via defaults to :get' do
|
40
|
+
assert_equal :get, Devise.mappings[:user].sign_out_via
|
41
|
+
end
|
42
|
+
|
43
|
+
test 'allows custom sign_out_via to be given' do
|
44
|
+
assert_equal :delete, Devise.mappings[:sign_out_via_delete].sign_out_via
|
45
|
+
assert_equal :post, Devise.mappings[:sign_out_via_post].sign_out_via
|
46
|
+
assert_equal [:delete, :post], Devise.mappings[:sign_out_via_delete_or_post].sign_out_via
|
47
|
+
end
|
48
|
+
|
49
|
+
test 'allows custom singular to be given' do
|
50
|
+
assert_equal "accounts", Devise.mappings[:manager].path
|
51
|
+
end
|
52
|
+
|
53
|
+
test 'has strategies depending on the model declaration' do
|
54
|
+
assert_equal [:rememberable, :token_authenticatable, :database_authenticatable], Devise.mappings[:user].strategies
|
55
|
+
assert_equal [:database_authenticatable], Devise.mappings[:admin].strategies
|
56
|
+
end
|
57
|
+
|
58
|
+
test 'has no input strategies depending on the model declaration' do
|
59
|
+
assert_equal [:rememberable, :token_authenticatable], Devise.mappings[:user].no_input_strategies
|
60
|
+
assert_equal [], Devise.mappings[:admin].no_input_strategies
|
61
|
+
end
|
62
|
+
|
63
|
+
test 'find scope for a given object' do
|
64
|
+
assert_equal :user, Devise::Mapping.find_scope!(User)
|
65
|
+
assert_equal :user, Devise::Mapping.find_scope!(:user)
|
66
|
+
assert_equal :user, Devise::Mapping.find_scope!(User.new)
|
67
|
+
end
|
68
|
+
|
69
|
+
test 'find scope works with single table inheritance' do
|
70
|
+
assert_equal :user, Devise::Mapping.find_scope!(Class.new(User))
|
71
|
+
assert_equal :user, Devise::Mapping.find_scope!(Class.new(User).new)
|
72
|
+
end
|
73
|
+
|
74
|
+
test 'find scope raises an error if cannot be found' do
|
75
|
+
assert_raise RuntimeError do
|
76
|
+
Devise::Mapping.find_scope!(String)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
test 'return default path names' do
|
81
|
+
mapping = Devise.mappings[:user]
|
82
|
+
assert_equal 'sign_in', mapping.path_names[:sign_in]
|
83
|
+
assert_equal 'sign_out', mapping.path_names[:sign_out]
|
84
|
+
assert_equal 'password', mapping.path_names[:password]
|
85
|
+
assert_equal 'confirmation', mapping.path_names[:confirmation]
|
86
|
+
assert_equal 'sign_up', mapping.path_names[:sign_up]
|
87
|
+
assert_equal 'unlock', mapping.path_names[:unlock]
|
88
|
+
end
|
89
|
+
|
90
|
+
test 'allow custom path names to be given' do
|
91
|
+
mapping = Devise.mappings[:manager]
|
92
|
+
assert_equal 'login', mapping.path_names[:sign_in]
|
93
|
+
assert_equal 'logout', mapping.path_names[:sign_out]
|
94
|
+
assert_equal 'secret', mapping.path_names[:password]
|
95
|
+
assert_equal 'verification', mapping.path_names[:confirmation]
|
96
|
+
assert_equal 'register', mapping.path_names[:sign_up]
|
97
|
+
assert_equal 'unblock', mapping.path_names[:unlock]
|
98
|
+
end
|
99
|
+
|
100
|
+
test 'magic predicates' do
|
101
|
+
mapping = Devise.mappings[:user]
|
102
|
+
assert mapping.authenticatable?
|
103
|
+
assert mapping.confirmable?
|
104
|
+
assert mapping.recoverable?
|
105
|
+
assert mapping.rememberable?
|
106
|
+
assert mapping.registerable?
|
107
|
+
|
108
|
+
mapping = Devise.mappings[:admin]
|
109
|
+
assert mapping.authenticatable?
|
110
|
+
assert mapping.recoverable?
|
111
|
+
assert mapping.lockable?
|
112
|
+
assert_not mapping.omniauthable?
|
113
|
+
end
|
114
|
+
|
115
|
+
test 'find mapping by path' do
|
116
|
+
assert_raise RuntimeError do
|
117
|
+
Devise::Mapping.find_by_path!('/accounts/facebook/callback')
|
118
|
+
end
|
119
|
+
|
120
|
+
assert_nothing_raised do
|
121
|
+
Devise::Mapping.find_by_path!('/:locale/accounts/login')
|
122
|
+
end
|
123
|
+
|
124
|
+
assert_nothing_raised do
|
125
|
+
Devise::Mapping.find_by_path!('/accounts/facebook/callback', :path)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|