devise_token_auth 0.1.43.beta1 → 0.1.43
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of devise_token_auth might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/README.md +4 -0
- data/Rakefile +1 -0
- data/app/controllers/devise_token_auth/application_controller.rb +18 -2
- data/app/controllers/devise_token_auth/concerns/resource_finder.rb +5 -0
- data/app/controllers/devise_token_auth/concerns/set_user_by_token.rb +51 -38
- data/app/controllers/devise_token_auth/confirmations_controller.rb +3 -11
- data/app/controllers/devise_token_auth/omniauth_callbacks_controller.rb +3 -14
- data/app/controllers/devise_token_auth/passwords_controller.rb +34 -55
- data/app/controllers/devise_token_auth/registrations_controller.rb +34 -46
- data/app/controllers/devise_token_auth/sessions_controller.rb +15 -24
- data/app/controllers/devise_token_auth/token_validations_controller.rb +2 -5
- data/app/controllers/devise_token_auth/unlocks_controller.rb +11 -27
- data/app/models/devise_token_auth/concerns/user.rb +60 -85
- data/app/models/devise_token_auth/concerns/user_omniauth_callbacks.rb +2 -1
- data/config/initializers/devise.rb +4 -4
- data/config/locales/pl.yml +10 -10
- data/config/locales/uk.yml +59 -0
- data/config/locales/vi.yml +50 -0
- data/lib/devise_token_auth/controllers/helpers.rb +1 -1
- data/lib/devise_token_auth/engine.rb +3 -1
- data/lib/devise_token_auth/version.rb +1 -1
- data/lib/generators/devise_token_auth/templates/user.rb +3 -3
- data/test/controllers/demo_user_controller_test.rb +56 -0
- data/test/controllers/devise_token_auth/omniauth_callbacks_controller_test.rb +10 -6
- data/test/controllers/devise_token_auth/passwords_controller_test.rb +103 -1
- data/test/controllers/devise_token_auth/sessions_controller_test.rb +24 -1
- data/test/dummy/app/controllers/overrides/confirmations_controller.rb +1 -11
- data/test/dummy/app/controllers/overrides/passwords_controller.rb +1 -9
- data/test/dummy/app/controllers/overrides/sessions_controller.rb +1 -8
- data/test/models/user_test.rb +11 -1
- data/test/test_helper.rb +9 -0
- metadata +8 -6
@@ -2,7 +2,8 @@ module DeviseTokenAuth::Concerns::UserOmniauthCallbacks
|
|
2
2
|
extend ActiveSupport::Concern
|
3
3
|
|
4
4
|
included do
|
5
|
-
validates :email, presence: true,
|
5
|
+
validates :email, presence: true,if: :email_provider?
|
6
|
+
validates :email, email: true, allow_nil: true, allow_blank: true, if: :email_provider?
|
6
7
|
validates_presence_of :uid, unless: :email_provider?
|
7
8
|
|
8
9
|
# only validate unique emails among email registration users
|
@@ -86,15 +86,15 @@ Devise.setup do |config|
|
|
86
86
|
# config.clean_up_csrf_token_on_authentication = true
|
87
87
|
|
88
88
|
# ==> Configuration for :database_authenticatable
|
89
|
-
# For bcrypt, this is the cost for hashing the password and defaults to
|
90
|
-
# using other
|
89
|
+
# For bcrypt, this is the cost for hashing the password and defaults to 11. If
|
90
|
+
# using other algorithms, it sets how many times you want the password to be hashed.
|
91
91
|
#
|
92
92
|
# Limiting the stretches to just one in testing will increase the performance of
|
93
93
|
# your test suite dramatically. However, it is STRONGLY RECOMMENDED to not use
|
94
94
|
# a value less than 10 in other environments. Note that, for bcrypt (the default
|
95
|
-
#
|
95
|
+
# algorithm), the cost increases exponentially with the number of stretches (e.g.
|
96
96
|
# a value of 20 is already extremely slow: approx. 60 seconds for 1 calculation).
|
97
|
-
config.stretches = Rails.env.test? ? 1 :
|
97
|
+
config.stretches = Rails.env.test? ? 1 : 11
|
98
98
|
|
99
99
|
# Setup a pepper to generate the encrypted password.
|
100
100
|
# config.pepper = '8ff086600aff82d68ff1e00d23c99c821e66652ec8c2a5b48f58de4a56b325cb532f6db660cf58fc5ecb473b9d851be8cd1badff0a1053bc9dc045f78b6e6772'
|
data/config/locales/pl.yml
CHANGED
@@ -30,19 +30,19 @@ pl:
|
|
30
30
|
devise:
|
31
31
|
mailer:
|
32
32
|
confirmation_instructions:
|
33
|
-
subject: "
|
34
|
-
confirm_link_msg: "Możesz potwierdzić swój e-mail
|
33
|
+
subject: "Instrukcja potwierdzania"
|
34
|
+
confirm_link_msg: "Możesz potwierdzić swój e-mail poprzez link poniżej:"
|
35
35
|
confirm_account_link: "Potwierdź swoje konto"
|
36
36
|
reset_password_instructions:
|
37
37
|
subject: "Instrukcje resetowania hasła"
|
38
|
-
request_reset_link_msg: "
|
38
|
+
request_reset_link_msg: "Otrzymaliśmy prośbę o zmianę Twojego hasła. Możesz tego dokonać poprzez link poniżej:"
|
39
39
|
password_change_link: "Zmień hasło"
|
40
|
-
ignore_mail_msg: "Jeśli
|
41
|
-
no_changes_msg: "Twoje hasło nie zmieni
|
40
|
+
ignore_mail_msg: "Jeśli to nie Ty próbowałeś zmienić swoje hasło to zignoruj ten email."
|
41
|
+
no_changes_msg: "Twoje hasło nie zmieni się do momentu ustawienia nowego."
|
42
42
|
unlock_instructions:
|
43
43
|
subject: "Instrukcje do odblokowania"
|
44
|
-
account_lock_msg: "Twoje konto zostało zablokowane z powodu zbyt dużej liczby nieudanych
|
45
|
-
unlock_link_msg: "Kliknij poniższy link, aby odblokować konto
|
46
|
-
unlock_link: "
|
47
|
-
hello: "
|
48
|
-
welcome: "
|
44
|
+
account_lock_msg: "Twoje konto zostało zablokowane z powodu zbyt dużej liczby nieudanych prób logowania."
|
45
|
+
unlock_link_msg: "Kliknij poniższy link, aby odblokować konto:"
|
46
|
+
unlock_link: "Odblokuj konto"
|
47
|
+
hello: "Witaj"
|
48
|
+
welcome: "Witaj"
|
@@ -0,0 +1,59 @@
|
|
1
|
+
uk:
|
2
|
+
devise_token_auth:
|
3
|
+
sessions:
|
4
|
+
not_confirmed: "Будь ласка підтвердіть реєстрацію згідно інструкціям як ми вислали на Вашу пошту %{email}"
|
5
|
+
bad_credentials: "Логін або пароль введені невірно. Будь ласка, спробуйте ще"
|
6
|
+
not_supported: "Використовуйте POST /sign_in для входу. GET запити не пітримуються."
|
7
|
+
user_not_found: "Користувач не знайдений або не увійшов в систему"
|
8
|
+
token_validations:
|
9
|
+
invalid: "Помилкові дані"
|
10
|
+
registrations:
|
11
|
+
missing_confirm_success_url: "Немає параметру 'confirm_success_url'"
|
12
|
+
redirect_url_not_allowed: "Перенаправлення до '%{redirect_url}' не дозволено."
|
13
|
+
email_already_exists: "Акаунт для емейлу '%{email}' вже існує"
|
14
|
+
account_with_uid_destroyed: "Акаунт з UID '%{uid}' було видалено."
|
15
|
+
account_to_destroy_not_found: "Неможливо знайти акаунт для видалення."
|
16
|
+
user_not_found: "Користувача не знайдено"
|
17
|
+
passwords:
|
18
|
+
missing_email: "Ви маєте ввести email адресу."
|
19
|
+
missing_redirect_url: "Немає URL для перенаправлення."
|
20
|
+
not_allowed_redirect_url: "Перенаправлення до '%{redirect_url}' не дозволено."
|
21
|
+
sended: "Лист з інструкціями для скидання паролю відправлено на '%{email}'."
|
22
|
+
user_not_found: "Неможливо знайти користувача по email '%{email}'."
|
23
|
+
password_not_required: "Цей акаунт не потребує паролю. Увійдіть використовуючи натомість акаунт провайдера '%{provider}'."
|
24
|
+
missing_passwords: "Ви маєте заповнити поля з назвами 'Пароль' та 'Підтвердження паролю'."
|
25
|
+
successfully_updated: "Ваш пароль було успішно оновлено."
|
26
|
+
unlocks:
|
27
|
+
missing_email: "Ви маєте вказати адресу електронної пошти."
|
28
|
+
missing_redirect_url: "Відсутня адреса переадресації."
|
29
|
+
not_allowed_redirect_url: "Переадресація до %{redirect_url} не дозволена."
|
30
|
+
sended: "Інструкція по відновленню паролю відправлена на Вашу електронну адресу."
|
31
|
+
user_not_found: "Не виходить знайти користувача з електронною адресою %{email}."
|
32
|
+
password_not_required: "Цей обліковий запис не потребує паролю. Увійдіть використовуючи обліковий запис '%{provider}'."
|
33
|
+
missing_passwords: "Ви маєте заповнити поля 'пароль' і 'підтвердіть пароль'."
|
34
|
+
successfully_updated: "Ваш пароль успішно оновлено."
|
35
|
+
errors:
|
36
|
+
messages:
|
37
|
+
validate_sign_up_params: "Будь ласка, відправте вірні дані для реєстрації в тілі запиту."
|
38
|
+
validate_account_update_params: "Будь ласка, відправте вірні дані для оновлення акаунту в тілі запиту."
|
39
|
+
not_email: "не є електронною адресою"
|
40
|
+
devise:
|
41
|
+
mailer:
|
42
|
+
confirmation_instructions:
|
43
|
+
subject: "Інструкції підтвердження"
|
44
|
+
confirm_link_msg: "Ви можете підтвердити вашу адресу електронної пошти через посилання нижче:"
|
45
|
+
confirm_account_link: "Підтвердіть свій обліковий запис"
|
46
|
+
reset_password_instructions:
|
47
|
+
subject: "Інструкція по скиданню паролю"
|
48
|
+
request_reset_link_msg: "Хтось зробив запит на зміну паролю. Ви можете зробити це через посилання нижче."
|
49
|
+
password_change_link: "Змінити пароль"
|
50
|
+
ignore_mail_msg: "Якщо Ви не робили запит на це, Ви можете проігнорувати цей лист."
|
51
|
+
no_changes_msg: "Ваш пароль не зміниться, доки Ви не відкриєте посилання вище і не створите новий пароль."
|
52
|
+
unlock_instructions:
|
53
|
+
subject: "Інструкції з розблокування"
|
54
|
+
account_lock_msg: "Ваш акаунт було заблоковано через надмірну кількість невдалих спроб входу."
|
55
|
+
unlock_link_msg: "Перейдіть за посиланням нижче, щоб розблокувати свій акаунт:"
|
56
|
+
unlock_link: "Розблокувати мій обліковий запис"
|
57
|
+
hello: "привіт"
|
58
|
+
welcome: "вітаємо"
|
59
|
+
|
@@ -0,0 +1,50 @@
|
|
1
|
+
vi:
|
2
|
+
devise_token_auth:
|
3
|
+
sessions:
|
4
|
+
not_confirmed: "Mail xác nhận tài khoản đã được gửi tới tài khoản của bạn tại '%{email}'. Bận cần phải làm theo những hướng dẫn trong email để tài khoản có thể xác nhận"
|
5
|
+
bad_credentials: "Thông tin đăng nhập không hợp lệ. Xin thử lại."
|
6
|
+
not_supported: "Sử dụng POST /sign_in để đăng nhập. Phương thức GET không được hỗ trợ."
|
7
|
+
user_not_found: "Người dùng đã không được tìm thấy hoặc không đăng nhập."
|
8
|
+
token_validations:
|
9
|
+
invalid: "Thông tin đăng nhập không hợp lệ."
|
10
|
+
registrations:
|
11
|
+
missing_confirm_success_url: "Thiếu 'confirm_success_url' tham số."
|
12
|
+
redirect_url_not_allowed: "Chuyển hướng tới '%{redirect_url}' không được phép."
|
13
|
+
email_already_exists: "Tài khoản đã tồn tại của '%{email}'"
|
14
|
+
account_with_uid_destroyed: "Tài khoản với UID '%{uid}' vừa bị phá hủy."
|
15
|
+
account_to_destroy_not_found: "Không thể xác định tài khoản cho việc phá hủy."
|
16
|
+
user_not_found: "Người dùng không tìm thấy."
|
17
|
+
passwords:
|
18
|
+
missing_email: "Bạn cần cung cấp địa chỉ email."
|
19
|
+
missing_redirect_url: "Thiếu đường đẫn URL."
|
20
|
+
not_allowed_redirect_url: "Chuyển hướng tới '%{redirect_url}' không được phép."
|
21
|
+
sended: "Mail đã được gửi tới '%{email}' tiếp tục làm theo những hướng dẫn để khởi tạo lại mật khẩu."
|
22
|
+
user_not_found: "Không thể tìm ra người dùng với email '%{email}'."
|
23
|
+
password_not_required: "Tài khoản này không yêu cầu mật khẩu. Thay thế đăng nhập bằng cách sử dụng '%{provider}' của tài khoản ."
|
24
|
+
missing_passwords: "Bạn cần điền đủ những trường như 'mật khẩu' và 'xác nhận mật khẩu'."
|
25
|
+
successfully_updated: "Mật khẩu của bạn vừa được cập nhật thành công."
|
26
|
+
unlocks:
|
27
|
+
missing_email: "Bạn cần phải cung cấp địa chỉ email."
|
28
|
+
sended: "Mail đã được gửi tới '%{email}' tiếp tục làm theo những hướng đẫn để mở khóa tài khoản."
|
29
|
+
user_not_found: "Không thể tìm ra người dùng với email '%{email}'."
|
30
|
+
errors:
|
31
|
+
messages:
|
32
|
+
validate_sign_up_params: "Vui lòng gửi đúng dữ liệu đăng ký trong phần dữ liệu gửi lên."
|
33
|
+
validate_account_update_params: "Vui lòng gửi đúng dữ liệu cập nhật tài khoản trong phần dữ liệu gửi lên ."
|
34
|
+
not_email: "không phải là email"
|
35
|
+
devise:
|
36
|
+
mailer:
|
37
|
+
confirmation_instructions:
|
38
|
+
confirm_link_msg: "Bạn có thể xác nhận tài khoản email bằng đường link dưới đây:"
|
39
|
+
confirm_account_link: "Xác nhận tài khoản"
|
40
|
+
reset_password_instructions:
|
41
|
+
request_reset_link_msg: "Ai đó đã gửi yêu cầu để đổi mật khẩu của bạn. Bạn có thể thực hiện điều này thông qua đường dẫn bên dưới."
|
42
|
+
password_change_link: "Đổi mật khẩu của tôi"
|
43
|
+
ignore_mail_msg: "Nếu bạn đã không gửi yêu cầu này, thì vui lòng bỏ qua email này."
|
44
|
+
no_changes_msg: "Mật khẩu của bạn sẽ không thay đổi cho đến khi bạn truy cập liên kết ở trên và tạo một mật khẩu mới."
|
45
|
+
unlock_instructions:
|
46
|
+
account_lock_msg: "Tài khoản của bạn đã bị khóa do có quá nhiều lần đăng nhập không thành công."
|
47
|
+
unlock_link_msg: "Chọn vào đường dẫn bên dưới để mở khóa tài khoản:"
|
48
|
+
unlock_link: "Mở khóa tài khoản"
|
49
|
+
hello: "xin chào"
|
50
|
+
welcome: "chào mừng"
|
@@ -21,7 +21,8 @@ module DeviseTokenAuth
|
|
21
21
|
:enable_standard_devise_support,
|
22
22
|
:remove_tokens_after_password_reset,
|
23
23
|
:default_callbacks,
|
24
|
-
:headers_names
|
24
|
+
:headers_names,
|
25
|
+
:bypass_sign_in
|
25
26
|
|
26
27
|
self.change_headers_on_each_request = true
|
27
28
|
self.max_number_of_devices = 10
|
@@ -40,6 +41,7 @@ module DeviseTokenAuth
|
|
40
41
|
:'expiry' => 'expiry',
|
41
42
|
:'uid' => 'uid',
|
42
43
|
:'token-type' => 'token-type' }
|
44
|
+
self.bypass_sign_in = true
|
43
45
|
|
44
46
|
def self.setup(&block)
|
45
47
|
yield self
|
@@ -1,7 +1,7 @@
|
|
1
1
|
class <%= user_class.capitalize %> < ActiveRecord::Base
|
2
|
-
# Include default devise modules.
|
2
|
+
# Include default devise modules. Others available are:
|
3
|
+
# :confirmable, :lockable, :timeoutable and :omniauthable
|
3
4
|
devise :database_authenticatable, :registerable,
|
4
|
-
|
5
|
-
:confirmable, :omniauthable
|
5
|
+
:recoverable, :rememberable, :trackable, :validatable
|
6
6
|
include DeviseTokenAuth::Concerns::User
|
7
7
|
end
|
@@ -409,6 +409,62 @@ class DemoUserControllerTest < ActionDispatch::IntegrationTest
|
|
409
409
|
end
|
410
410
|
end
|
411
411
|
|
412
|
+
describe 'bypass_sign_in' do
|
413
|
+
before do
|
414
|
+
@resource = users(:unconfirmed_email_user)
|
415
|
+
@resource.save!
|
416
|
+
|
417
|
+
@auth_headers = @resource.create_new_auth_token
|
418
|
+
|
419
|
+
@token = @auth_headers['access-token']
|
420
|
+
@client_id = @auth_headers['client']
|
421
|
+
@expiry = @auth_headers['expiry']
|
422
|
+
end
|
423
|
+
describe 'is default value (true)' do
|
424
|
+
before do
|
425
|
+
age_token(@resource, @client_id)
|
426
|
+
|
427
|
+
get '/demo/members_only', params: {}, headers: @auth_headers
|
428
|
+
|
429
|
+
@access_token = response.headers['access-token']
|
430
|
+
@response_status = response.status
|
431
|
+
end
|
432
|
+
|
433
|
+
it 'should allow the request through' do
|
434
|
+
assert_equal 200, @response_status
|
435
|
+
end
|
436
|
+
|
437
|
+
it 'should return auth headers' do
|
438
|
+
assert @access_token
|
439
|
+
end
|
440
|
+
|
441
|
+
it 'should set current user' do
|
442
|
+
assert_equal @controller.current_user, @resource
|
443
|
+
end
|
444
|
+
end
|
445
|
+
describe 'is false' do
|
446
|
+
before do
|
447
|
+
DeviseTokenAuth.bypass_sign_in = false
|
448
|
+
age_token(@resource, @client_id)
|
449
|
+
|
450
|
+
get '/demo/members_only', params: {}, headers: @auth_headers
|
451
|
+
|
452
|
+
@access_token = response.headers['access-token']
|
453
|
+
@response_status = response.status
|
454
|
+
|
455
|
+
DeviseTokenAuth.bypass_sign_in = true
|
456
|
+
end
|
457
|
+
|
458
|
+
it 'should not allow the request through' do
|
459
|
+
refute_equal 200, @response_status
|
460
|
+
end
|
461
|
+
|
462
|
+
it 'should not return auth headers from the first request' do
|
463
|
+
assert_nil @access_token
|
464
|
+
end
|
465
|
+
end
|
466
|
+
end
|
467
|
+
|
412
468
|
describe 'enable_standard_devise_support' do
|
413
469
|
before do
|
414
470
|
@resource = users(:confirmed_email_user)
|
@@ -276,11 +276,13 @@ class OmniauthTest < ActionDispatch::IntegrationTest
|
|
276
276
|
end
|
277
277
|
|
278
278
|
test 'renders expected data' do
|
279
|
-
|
280
|
-
|
281
|
-
|
279
|
+
silence_omniauth do
|
280
|
+
get '/auth/facebook',
|
281
|
+
params: { auth_origin_url: @redirect_url,
|
282
|
+
omniauth_window_type: 'newWindow' }
|
282
283
|
|
283
|
-
|
284
|
+
follow_all_redirects!
|
285
|
+
end
|
284
286
|
|
285
287
|
assert_equal 200, response.status
|
286
288
|
|
@@ -290,8 +292,10 @@ class OmniauthTest < ActionDispatch::IntegrationTest
|
|
290
292
|
end
|
291
293
|
|
292
294
|
test 'renders something with no auth_origin_url' do
|
293
|
-
|
294
|
-
|
295
|
+
silence_omniauth do
|
296
|
+
get '/auth/facebook'
|
297
|
+
follow_all_redirects!
|
298
|
+
end
|
295
299
|
assert_equal 200, response.status
|
296
300
|
assert_select 'body', 'invalid_credentials'
|
297
301
|
end
|
@@ -166,7 +166,7 @@ class DeviseTokenAuth::PasswordsControllerTest < ActionController::TestCase
|
|
166
166
|
@uid = @qs['uid']
|
167
167
|
end
|
168
168
|
|
169
|
-
test '
|
169
|
+
test 'response should have success redirect status' do
|
170
170
|
assert_equal 302, response.status
|
171
171
|
end
|
172
172
|
|
@@ -208,6 +208,108 @@ class DeviseTokenAuth::PasswordsControllerTest < ActionController::TestCase
|
|
208
208
|
assert_equal 404, response.status
|
209
209
|
end
|
210
210
|
end
|
211
|
+
|
212
|
+
describe 'Cheking reset_password_token' do
|
213
|
+
before do
|
214
|
+
post :create, params: {
|
215
|
+
email: @resource.email,
|
216
|
+
redirect_url: @redirect_url
|
217
|
+
}
|
218
|
+
|
219
|
+
@mail = ActionMailer::Base.deliveries.last
|
220
|
+
@mail_redirect_url = CGI.unescape(@mail.body.match(/redirect_url=([^&]*)&/)[1])
|
221
|
+
@mail_reset_token = @mail.body.match(/reset_password_token=(.*)\"/)[1]
|
222
|
+
|
223
|
+
@resource.reload
|
224
|
+
end
|
225
|
+
|
226
|
+
describe 'reset_password_token is valid' do
|
227
|
+
|
228
|
+
test 'mail_reset_token should be the same as reset_password_token' do
|
229
|
+
assert_equal Devise.token_generator.digest(self, :reset_password_token, @mail_reset_token), @resource.reset_password_token
|
230
|
+
end
|
231
|
+
|
232
|
+
test 'reset_password_token should be rewritten by origin mail_reset_token' do
|
233
|
+
get :edit, params: {
|
234
|
+
reset_password_token: @mail_reset_token,
|
235
|
+
redirect_url: @mail_redirect_url
|
236
|
+
}
|
237
|
+
@resource.reload
|
238
|
+
|
239
|
+
assert_equal @mail_reset_token, @resource.reset_password_token
|
240
|
+
end
|
241
|
+
|
242
|
+
test 'response should return success status' do
|
243
|
+
get :edit, params: {
|
244
|
+
reset_password_token: @mail_reset_token,
|
245
|
+
redirect_url: @mail_redirect_url
|
246
|
+
}
|
247
|
+
|
248
|
+
assert_equal 302, response.status
|
249
|
+
end
|
250
|
+
|
251
|
+
test 'reset_password_token should be valid only one first time' do
|
252
|
+
get :edit, params: {
|
253
|
+
reset_password_token: @mail_reset_token,
|
254
|
+
redirect_url: @mail_redirect_url
|
255
|
+
}
|
256
|
+
|
257
|
+
@resource.reload
|
258
|
+
assert_equal @mail_reset_token, @resource.reset_password_token
|
259
|
+
|
260
|
+
assert_raises(ActionController::RoutingError) {
|
261
|
+
get :edit, params: {
|
262
|
+
reset_password_token: @mail_reset_token,
|
263
|
+
redirect_url: @mail_redirect_url
|
264
|
+
}
|
265
|
+
}
|
266
|
+
|
267
|
+
@resource.reload
|
268
|
+
assert_equal @mail_reset_token, @resource.reset_password_token
|
269
|
+
end
|
270
|
+
|
271
|
+
test 'reset_password_sent_at should be valid' do
|
272
|
+
assert_equal @resource.reset_password_period_valid?, true
|
273
|
+
|
274
|
+
get :edit, params: {
|
275
|
+
reset_password_token: @mail_reset_token,
|
276
|
+
redirect_url: @mail_redirect_url
|
277
|
+
}
|
278
|
+
|
279
|
+
@resource.reload
|
280
|
+
assert_equal @mail_reset_token, @resource.reset_password_token
|
281
|
+
end
|
282
|
+
|
283
|
+
test 'reset_password_sent_at should be expired' do
|
284
|
+
assert_equal @resource.reset_password_period_valid?, true
|
285
|
+
|
286
|
+
@resource.update reset_password_sent_at: @resource.reset_password_sent_at - Devise.reset_password_within - 1.seconds
|
287
|
+
assert_equal @resource.reset_password_period_valid?, false
|
288
|
+
|
289
|
+
assert_raises(ActionController::RoutingError) {
|
290
|
+
get :edit, params: {
|
291
|
+
reset_password_token: @mail_reset_token,
|
292
|
+
redirect_url: @mail_redirect_url
|
293
|
+
}
|
294
|
+
}
|
295
|
+
end
|
296
|
+
end
|
297
|
+
|
298
|
+
describe 'reset_password_token is not valid' do
|
299
|
+
test 'response should return error status' do
|
300
|
+
@resource.update reset_password_token: 'koskoskoskos'
|
301
|
+
|
302
|
+
assert_not_equal Devise.token_generator.digest(self, :reset_password_token, @mail_reset_token), @resource.reset_password_token
|
303
|
+
|
304
|
+
assert_raises(ActionController::RoutingError) {
|
305
|
+
get :edit, params: {
|
306
|
+
reset_password_token: @mail_reset_token,
|
307
|
+
redirect_url: @mail_redirect_url
|
308
|
+
}
|
309
|
+
}
|
310
|
+
end
|
311
|
+
end
|
312
|
+
end
|
211
313
|
end
|
212
314
|
|
213
315
|
describe 'Using default_password_reset_url' do
|
@@ -239,6 +239,29 @@ class DeviseTokenAuth::SessionsControllerTest < ActionController::TestCase
|
|
239
239
|
assert_equal 401, response.status
|
240
240
|
end
|
241
241
|
end
|
242
|
+
|
243
|
+
describe 'stripping whitespace on email' do
|
244
|
+
before do
|
245
|
+
@resource_class = User
|
246
|
+
@request_params = {
|
247
|
+
# adding whitespace before and after email
|
248
|
+
email: " #{@existing_user.email} ",
|
249
|
+
password: 'secret123'
|
250
|
+
}
|
251
|
+
end
|
252
|
+
|
253
|
+
test 'request should succeed if configured' do
|
254
|
+
@resource_class.strip_whitespace_keys = [:email]
|
255
|
+
post :create, params: @request_params
|
256
|
+
assert_equal 200, response.status
|
257
|
+
end
|
258
|
+
|
259
|
+
test 'request should fail if not configured' do
|
260
|
+
@resource_class.strip_whitespace_keys = []
|
261
|
+
post :create, params: @request_params
|
262
|
+
assert_equal 401, response.status
|
263
|
+
end
|
264
|
+
end
|
242
265
|
end
|
243
266
|
|
244
267
|
describe 'Unconfirmed user' do
|
@@ -427,7 +450,7 @@ class DeviseTokenAuth::SessionsControllerTest < ActionController::TestCase
|
|
427
450
|
|
428
451
|
test 'response should contain errors' do
|
429
452
|
assert @data['errors']
|
430
|
-
assert_equal @data['errors'], [I18n.t('
|
453
|
+
assert_equal @data['errors'], [I18n.t('devise.mailer.unlock_instructions.account_lock_msg')]
|
431
454
|
end
|
432
455
|
end
|
433
456
|
|