af-devise 2.1.2
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/.gitignore +10 -0
- data/.travis.yml +15 -0
- data/CHANGELOG.rdoc +885 -0
- data/CONTRIBUTING.md +14 -0
- data/Gemfile +29 -0
- data/Gemfile.lock +155 -0
- data/MIT-LICENSE +20 -0
- data/README.md +394 -0
- data/Rakefile +34 -0
- data/app/controllers/devise/confirmations_controller.rb +43 -0
- data/app/controllers/devise/omniauth_callbacks_controller.rb +30 -0
- data/app/controllers/devise/passwords_controller.rb +65 -0
- data/app/controllers/devise/registrations_controller.rb +119 -0
- data/app/controllers/devise/sessions_controller.rb +50 -0
- data/app/controllers/devise/unlocks_controller.rb +44 -0
- data/app/controllers/devise_controller.rb +184 -0
- data/app/helpers/devise_helper.rb +25 -0
- data/app/mailers/devise/mailer.rb +15 -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 +25 -0
- data/gemfiles/Gemfile.rails-3.1.x +35 -0
- data/gemfiles/Gemfile.rails-3.1.x.lock +167 -0
- data/lib/devise.rb +444 -0
- data/lib/devise/controllers/helpers.rb +285 -0
- data/lib/devise/controllers/rememberable.rb +52 -0
- data/lib/devise/controllers/scoped_views.rb +17 -0
- data/lib/devise/controllers/url_helpers.rb +67 -0
- data/lib/devise/delegator.rb +16 -0
- data/lib/devise/failure_app.rb +187 -0
- data/lib/devise/hooks/activatable.rb +11 -0
- data/lib/devise/hooks/forgetable.rb +9 -0
- data/lib/devise/hooks/lockable.rb +7 -0
- data/lib/devise/hooks/rememberable.rb +6 -0
- data/lib/devise/hooks/timeoutable.rb +25 -0
- data/lib/devise/hooks/trackable.rb +9 -0
- data/lib/devise/mailers/helpers.rb +91 -0
- data/lib/devise/mapping.rb +172 -0
- data/lib/devise/models.rb +128 -0
- data/lib/devise/models/authenticatable.rb +268 -0
- data/lib/devise/models/confirmable.rb +270 -0
- data/lib/devise/models/database_authenticatable.rb +127 -0
- data/lib/devise/models/lockable.rb +193 -0
- data/lib/devise/models/omniauthable.rb +27 -0
- data/lib/devise/models/recoverable.rb +140 -0
- data/lib/devise/models/registerable.rb +25 -0
- data/lib/devise/models/rememberable.rb +125 -0
- data/lib/devise/models/timeoutable.rb +49 -0
- data/lib/devise/models/token_authenticatable.rb +89 -0
- data/lib/devise/models/trackable.rb +35 -0
- data/lib/devise/models/validatable.rb +66 -0
- data/lib/devise/modules.rb +29 -0
- data/lib/devise/omniauth.rb +28 -0
- data/lib/devise/omniauth/config.rb +45 -0
- data/lib/devise/omniauth/url_helpers.rb +18 -0
- data/lib/devise/orm/active_record.rb +3 -0
- data/lib/devise/orm/mongoid.rb +3 -0
- data/lib/devise/param_filter.rb +41 -0
- data/lib/devise/rails.rb +54 -0
- data/lib/devise/rails/routes.rb +446 -0
- data/lib/devise/rails/warden_compat.rb +43 -0
- data/lib/devise/strategies/authenticatable.rb +176 -0
- data/lib/devise/strategies/base.rb +20 -0
- data/lib/devise/strategies/database_authenticatable.rb +20 -0
- data/lib/devise/strategies/rememberable.rb +55 -0
- data/lib/devise/strategies/token_authenticatable.rb +56 -0
- data/lib/devise/test_helpers.rb +131 -0
- data/lib/devise/time_inflector.rb +14 -0
- data/lib/devise/version.rb +3 -0
- data/lib/generators/active_record/devise_generator.rb +79 -0
- data/lib/generators/active_record/templates/migration.rb +19 -0
- data/lib/generators/active_record/templates/migration_existing.rb +26 -0
- data/lib/generators/devise/devise_generator.rb +24 -0
- data/lib/generators/devise/install_generator.rb +24 -0
- data/lib/generators/devise/orm_helpers.rb +32 -0
- data/lib/generators/devise/views_generator.rb +116 -0
- data/lib/generators/mongoid/devise_generator.rb +57 -0
- data/lib/generators/templates/README +35 -0
- data/lib/generators/templates/devise.rb +240 -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 +62 -0
- data/test/controllers/helpers_test.rb +253 -0
- data/test/controllers/internal_helpers_test.rb +110 -0
- data/test/controllers/sessions_controller_test.rb +85 -0
- data/test/controllers/url_helpers_test.rb +59 -0
- data/test/delegator_test.rb +19 -0
- data/test/devise_test.rb +72 -0
- data/test/failure_app_test.rb +221 -0
- data/test/generators/active_record_generator_test.rb +75 -0
- data/test/generators/devise_generator_test.rb +39 -0
- data/test/generators/install_generator_test.rb +13 -0
- data/test/generators/mongoid_generator_test.rb +23 -0
- data/test/generators/views_generator_test.rb +52 -0
- data/test/helpers/devise_helper_test.rb +51 -0
- data/test/integration/authenticatable_test.rb +633 -0
- data/test/integration/confirmable_test.rb +298 -0
- data/test/integration/database_authenticatable_test.rb +82 -0
- data/test/integration/http_authenticatable_test.rb +97 -0
- data/test/integration/lockable_test.rb +242 -0
- data/test/integration/omniauthable_test.rb +133 -0
- data/test/integration/recoverable_test.rb +334 -0
- data/test/integration/registerable_test.rb +345 -0
- data/test/integration/rememberable_test.rb +158 -0
- data/test/integration/timeoutable_test.rb +140 -0
- data/test/integration/token_authenticatable_test.rb +161 -0
- data/test/integration/trackable_test.rb +92 -0
- data/test/mailers/confirmation_instructions_test.rb +102 -0
- data/test/mailers/reset_password_instructions_test.rb +83 -0
- data/test/mailers/unlock_instructions_test.rb +77 -0
- data/test/mapping_test.rb +127 -0
- data/test/models/authenticatable_test.rb +7 -0
- data/test/models/confirmable_test.rb +391 -0
- data/test/models/database_authenticatable_test.rb +196 -0
- data/test/models/lockable_test.rb +273 -0
- data/test/models/omniauthable_test.rb +7 -0
- data/test/models/recoverable_test.rb +205 -0
- data/test/models/registerable_test.rb +7 -0
- data/test/models/rememberable_test.rb +174 -0
- data/test/models/serializable_test.rb +49 -0
- data/test/models/timeoutable_test.rb +46 -0
- data/test/models/token_authenticatable_test.rb +55 -0
- data/test/models/trackable_test.rb +13 -0
- data/test/models/validatable_test.rb +117 -0
- data/test/models_test.rb +179 -0
- data/test/omniauth/config_test.rb +57 -0
- data/test/omniauth/url_helpers_test.rb +51 -0
- data/test/orm/active_record.rb +9 -0
- data/test/orm/mongoid.rb +13 -0
- data/test/rails_app/Rakefile +10 -0
- data/test/rails_app/app/active_record/admin.rb +6 -0
- data/test/rails_app/app/active_record/shim.rb +2 -0
- data/test/rails_app/app/active_record/user.rb +6 -0
- data/test/rails_app/app/controllers/admins/sessions_controller.rb +6 -0
- data/test/rails_app/app/controllers/admins_controller.rb +11 -0
- data/test/rails_app/app/controllers/application_controller.rb +8 -0
- data/test/rails_app/app/controllers/home_controller.rb +25 -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/users/omniauth_callbacks_controller.rb +14 -0
- data/test/rails_app/app/controllers/users_controller.rb +23 -0
- data/test/rails_app/app/helpers/application_helper.rb +3 -0
- data/test/rails_app/app/mailers/users/mailer.rb +8 -0
- data/test/rails_app/app/mongoid/admin.rb +29 -0
- data/test/rails_app/app/mongoid/shim.rb +24 -0
- data/test/rails_app/app/mongoid/user.rb +42 -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.ru +4 -0
- data/test/rails_app/config/application.rb +41 -0
- data/test/rails_app/config/boot.rb +8 -0
- data/test/rails_app/config/database.yml +18 -0
- data/test/rails_app/config/environment.rb +5 -0
- data/test/rails_app/config/environments/development.rb +18 -0
- data/test/rails_app/config/environments/production.rb +33 -0
- data/test/rails_app/config/environments/test.rb +33 -0
- data/test/rails_app/config/initializers/backtrace_silencers.rb +7 -0
- data/test/rails_app/config/initializers/devise.rb +178 -0
- data/test/rails_app/config/initializers/inflections.rb +2 -0
- data/test/rails_app/config/initializers/secret_token.rb +2 -0
- data/test/rails_app/config/routes.rb +100 -0
- data/test/rails_app/db/migrate/20100401102949_create_tables.rb +74 -0
- data/test/rails_app/db/schema.rb +52 -0
- data/test/rails_app/lib/shared_admin.rb +14 -0
- data/test/rails_app/lib/shared_user.rb +26 -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 +248 -0
- data/test/support/assertions.rb +40 -0
- data/test/support/helpers.rb +91 -0
- data/test/support/integration.rb +92 -0
- data/test/support/locale/en.yml +4 -0
- data/test/support/webrat/integrations/rails.rb +24 -0
- data/test/test_helper.rb +27 -0
- data/test/test_helpers_test.rb +151 -0
- metadata +421 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class TokenAuthenticatableTest < ActiveSupport::TestCase
|
|
4
|
+
|
|
5
|
+
test 'should reset authentication token' do
|
|
6
|
+
user = new_user
|
|
7
|
+
user.reset_authentication_token
|
|
8
|
+
previous_token = user.authentication_token
|
|
9
|
+
user.reset_authentication_token
|
|
10
|
+
assert_not_equal previous_token, user.authentication_token
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
test 'should ensure authentication token' do
|
|
14
|
+
user = new_user
|
|
15
|
+
user.ensure_authentication_token
|
|
16
|
+
previous_token = user.authentication_token
|
|
17
|
+
user.ensure_authentication_token
|
|
18
|
+
assert_equal previous_token, user.authentication_token
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
test 'should authenticate a valid user with authentication token and return it' do
|
|
22
|
+
user = create_user
|
|
23
|
+
user.ensure_authentication_token!
|
|
24
|
+
user.confirm!
|
|
25
|
+
authenticated_user = User.find_for_token_authentication(:auth_token => user.authentication_token)
|
|
26
|
+
assert_equal authenticated_user, user
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
test 'should return nil when authenticating an invalid user by authentication token' do
|
|
30
|
+
user = create_user
|
|
31
|
+
user.ensure_authentication_token!
|
|
32
|
+
user.confirm!
|
|
33
|
+
authenticated_user = User.find_for_token_authentication(:auth_token => user.authentication_token.reverse)
|
|
34
|
+
assert_nil authenticated_user
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
test 'should not be subject to injection' do
|
|
38
|
+
user1 = create_user
|
|
39
|
+
user1.ensure_authentication_token!
|
|
40
|
+
user1.confirm!
|
|
41
|
+
|
|
42
|
+
user2 = create_user
|
|
43
|
+
user2.ensure_authentication_token!
|
|
44
|
+
user2.confirm!
|
|
45
|
+
|
|
46
|
+
user = User.find_for_token_authentication(:auth_token => {'$ne' => user1.authentication_token})
|
|
47
|
+
assert_nil user
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
test 'required_fields should contain the fields that Devise uses' do
|
|
51
|
+
assert_same_content Devise::Models::TokenAuthenticatable.required_fields(User), [
|
|
52
|
+
:authentication_token
|
|
53
|
+
]
|
|
54
|
+
end
|
|
55
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class TrackableTest < ActiveSupport::TestCase
|
|
4
|
+
test 'required_fields should contain the fields that Devise uses' do
|
|
5
|
+
assert_same_content Devise::Models::Trackable.required_fields(User), [
|
|
6
|
+
:current_sign_in_at,
|
|
7
|
+
:current_sign_in_ip,
|
|
8
|
+
:last_sign_in_at,
|
|
9
|
+
:last_sign_in_ip,
|
|
10
|
+
:sign_in_count
|
|
11
|
+
]
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
# encoding: UTF-8
|
|
2
|
+
require 'test_helper'
|
|
3
|
+
|
|
4
|
+
class ValidatableTest < ActiveSupport::TestCase
|
|
5
|
+
test 'should require email to be set' do
|
|
6
|
+
user = new_user(:email => nil)
|
|
7
|
+
assert user.invalid?
|
|
8
|
+
assert user.errors[:email]
|
|
9
|
+
assert_equal 'can\'t be blank', user.errors[:email].join
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
test 'should require uniqueness of email if email has changed, allowing blank' do
|
|
13
|
+
existing_user = create_user
|
|
14
|
+
|
|
15
|
+
user = new_user(:email => '')
|
|
16
|
+
assert user.invalid?
|
|
17
|
+
assert_no_match(/taken/, user.errors[:email].join)
|
|
18
|
+
|
|
19
|
+
user.email = existing_user.email
|
|
20
|
+
assert user.invalid?
|
|
21
|
+
assert_match(/taken/, user.errors[:email].join)
|
|
22
|
+
|
|
23
|
+
user.save(:validate => false)
|
|
24
|
+
assert user.valid?
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
test 'should require correct email format if email has changed, allowing blank' do
|
|
28
|
+
user = new_user(:email => '')
|
|
29
|
+
assert user.invalid?
|
|
30
|
+
assert_not_equal 'is invalid', user.errors[:email].join
|
|
31
|
+
|
|
32
|
+
%w{invalid_email_format 123 $$$ () ☃ bla@bla.}.each do |email|
|
|
33
|
+
user.email = email
|
|
34
|
+
assert user.invalid?, 'should be invalid with email ' << email
|
|
35
|
+
assert_equal 'is invalid', user.errors[:email].join
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
user.save(:validate => false)
|
|
39
|
+
assert user.valid?
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
test 'should accept valid emails' do
|
|
43
|
+
%w(a.b.c@example.com test_mail@gmail.com any@any.net email@test.br 123@mail.test 1☃3@mail.test).each do |email|
|
|
44
|
+
user = new_user(:email => email)
|
|
45
|
+
assert user.valid?, 'should be valid with email ' << email
|
|
46
|
+
assert_blank user.errors[:email]
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
test 'should require password to be set when creating a new record' do
|
|
51
|
+
user = new_user(:password => '', :password_confirmation => '')
|
|
52
|
+
assert user.invalid?
|
|
53
|
+
assert_equal 'can\'t be blank', user.errors[:password].join
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
test 'should require confirmation to be set when creating a new record' do
|
|
57
|
+
user = new_user(:password => 'new_password', :password_confirmation => 'blabla')
|
|
58
|
+
assert user.invalid?
|
|
59
|
+
assert_equal 'doesn\'t match confirmation', user.errors[:password].join
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
test 'should require password when updating/reseting password' do
|
|
63
|
+
user = create_user
|
|
64
|
+
|
|
65
|
+
user.password = ''
|
|
66
|
+
user.password_confirmation = ''
|
|
67
|
+
|
|
68
|
+
assert user.invalid?
|
|
69
|
+
assert_equal 'can\'t be blank', user.errors[:password].join
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
test 'should require confirmation when updating/reseting password' do
|
|
73
|
+
user = create_user
|
|
74
|
+
user.password_confirmation = 'another_password'
|
|
75
|
+
assert user.invalid?
|
|
76
|
+
assert_equal 'doesn\'t match confirmation', user.errors[:password].join
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
test 'should require a password with minimum of 6 characters' do
|
|
80
|
+
user = new_user(:password => '12345', :password_confirmation => '12345')
|
|
81
|
+
assert user.invalid?
|
|
82
|
+
assert_equal 'is too short (minimum is 6 characters)', user.errors[:password].join
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
test 'should require a password with maximum of 128 characters long' do
|
|
86
|
+
user = new_user(:password => 'x'*129, :password_confirmation => 'x'*129)
|
|
87
|
+
assert user.invalid?
|
|
88
|
+
assert_equal 'is too long (maximum is 128 characters)', user.errors[:password].join
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
test 'should not require password length when it\'s not changed' do
|
|
92
|
+
user = create_user.reload
|
|
93
|
+
user.password = user.password_confirmation = nil
|
|
94
|
+
assert user.valid?
|
|
95
|
+
|
|
96
|
+
user.password_confirmation = 'confirmation'
|
|
97
|
+
assert user.invalid?
|
|
98
|
+
assert_not (user.errors[:password].join =~ /is too long/)
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
test 'should complain about length even if possword is not required' do
|
|
102
|
+
user = new_user(:password => 'x'*129, :password_confirmation => 'x'*129)
|
|
103
|
+
user.stubs(:password_required?).returns(false)
|
|
104
|
+
assert user.invalid?
|
|
105
|
+
assert_equal 'is too long (maximum is 128 characters)', user.errors[:password].join
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
test 'should not be included in objects with invalid API' do
|
|
109
|
+
assert_raise RuntimeError do
|
|
110
|
+
Class.new.send :include, Devise::Models::Validatable
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
test 'required_fields should be an empty array' do
|
|
115
|
+
assert_equal Devise::Models::Validatable.required_fields(User), []
|
|
116
|
+
end
|
|
117
|
+
end
|
data/test/models_test.rb
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class Configurable < User
|
|
4
|
+
devise :database_authenticatable, :confirmable, :rememberable, :timeoutable, :lockable,
|
|
5
|
+
:stretches => 15, :pepper => 'abcdef', :allow_unconfirmed_access_for => 5.days,
|
|
6
|
+
:remember_for => 7.days, :timeout_in => 15.minutes, :unlock_in => 10.days
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
class WithValidation < Admin
|
|
10
|
+
devise :database_authenticatable, :validatable, :password_length => 2..6
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
class UserWithValidation < User
|
|
14
|
+
validates_presence_of :username
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
class Several < Admin
|
|
18
|
+
devise :validatable
|
|
19
|
+
devise :lockable
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
class Inheritable < Admin
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
class ActiveRecordTest < ActiveSupport::TestCase
|
|
26
|
+
def include_module?(klass, mod)
|
|
27
|
+
klass.devise_modules.include?(mod) &&
|
|
28
|
+
klass.included_modules.include?(Devise::Models::const_get(mod.to_s.classify))
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def assert_include_modules(klass, *modules)
|
|
32
|
+
modules.each do |mod|
|
|
33
|
+
assert include_module?(klass, mod)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
(Devise::ALL - modules).each do |mod|
|
|
37
|
+
assert_not include_module?(klass, mod)
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
test 'can cherry pick modules' do
|
|
42
|
+
assert_include_modules Admin, :database_authenticatable, :registerable, :timeoutable, :recoverable, :lockable, :confirmable
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
test 'validations options are not applied too late' do
|
|
46
|
+
validators = WithValidation.validators_on :password
|
|
47
|
+
length = validators.find { |v| v.kind == :length }
|
|
48
|
+
assert_equal 2, length.options[:minimum]
|
|
49
|
+
assert_equal 6, length.options[:maximum]
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
test 'validations are applied just once' do
|
|
53
|
+
validators = Several.validators_on :password
|
|
54
|
+
assert_equal 1, validators.select{ |v| v.kind == :length }.length
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
test 'chosen modules are inheritable' do
|
|
58
|
+
assert_include_modules Inheritable, :database_authenticatable, :registerable, :timeoutable, :recoverable, :lockable, :confirmable
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
test 'order of module inclusion' do
|
|
62
|
+
correct_module_order = [:database_authenticatable, :recoverable, :registerable, :confirmable, :lockable, :timeoutable]
|
|
63
|
+
incorrect_module_order = [:database_authenticatable, :timeoutable, :registerable, :recoverable, :lockable, :confirmable]
|
|
64
|
+
|
|
65
|
+
assert_include_modules Admin, *incorrect_module_order
|
|
66
|
+
|
|
67
|
+
# get module constants from symbol list
|
|
68
|
+
module_constants = correct_module_order.collect { |mod| Devise::Models::const_get(mod.to_s.classify) }
|
|
69
|
+
|
|
70
|
+
# confirm that they adhere to the order in ALL
|
|
71
|
+
# get included modules, filter out the noise, and reverse the order
|
|
72
|
+
assert_equal module_constants, (Admin.included_modules & module_constants).reverse
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
test 'raise error on invalid module' do
|
|
76
|
+
assert_raise NameError do
|
|
77
|
+
# Mix valid an invalid modules.
|
|
78
|
+
Configurable.class_eval { devise :database_authenticatable, :doesnotexit }
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
test 'set a default value for stretches' do
|
|
83
|
+
assert_equal 15, Configurable.stretches
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
test 'set a default value for pepper' do
|
|
87
|
+
assert_equal 'abcdef', Configurable.pepper
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
test 'set a default value for allow_unconfirmed_access_for' do
|
|
91
|
+
assert_equal 5.days, Configurable.allow_unconfirmed_access_for
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
test 'set a default value for remember_for' do
|
|
95
|
+
assert_equal 7.days, Configurable.remember_for
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
test 'set a default value for timeout_in' do
|
|
99
|
+
assert_equal 15.minutes, Configurable.timeout_in
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
test 'set a default value for unlock_in' do
|
|
103
|
+
assert_equal 10.days, Configurable.unlock_in
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
test 'set null fields on migrations' do
|
|
107
|
+
Admin.create!
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
class CheckFieldsTest < ActiveSupport::TestCase
|
|
112
|
+
test 'checks if the class respond_to the required fields' do
|
|
113
|
+
Player = Class.new do
|
|
114
|
+
extend Devise::Models
|
|
115
|
+
|
|
116
|
+
def self.before_validation(instance)
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
devise :database_authenticatable
|
|
120
|
+
|
|
121
|
+
attr_accessor :encrypted_password, :email
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
assert_nothing_raised Devise::Models::MissingAttribute do
|
|
125
|
+
Devise::Models.check_fields!(Player)
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
test 'raises Devise::Models::MissingAtrribute and shows the missing attribute if the class doesn\'t respond_to one of the attributes' do
|
|
130
|
+
Clown = Class.new do
|
|
131
|
+
extend Devise::Models
|
|
132
|
+
|
|
133
|
+
def self.before_validation(instance)
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
devise :database_authenticatable
|
|
137
|
+
|
|
138
|
+
attr_accessor :encrypted_password
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
assert_raise_with_message Devise::Models::MissingAttribute, "The following attribute(s) is (are) missing on your model: email" do
|
|
142
|
+
Devise::Models.check_fields!(Clown)
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
test 'raises Devise::Models::MissingAtrribute with all the missing attributes if there is more than one' do
|
|
147
|
+
Magician = Class.new do
|
|
148
|
+
extend Devise::Models
|
|
149
|
+
|
|
150
|
+
def self.before_validation(instance)
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
devise :database_authenticatable
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
assert_raise_with_message Devise::Models::MissingAttribute, "The following attribute(s) is (are) missing on your model: encrypted_password, email" do
|
|
157
|
+
Devise::Models.check_fields!(Magician)
|
|
158
|
+
end
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
test "doesn't raise a NoMethodError exception when the module doesn't have a required_field(klass) class method" do
|
|
162
|
+
driver = Class.new do
|
|
163
|
+
extend Devise::Models
|
|
164
|
+
|
|
165
|
+
def self.before_validation(instance)
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
attr_accessor :encrypted_password, :email
|
|
169
|
+
|
|
170
|
+
devise :database_authenticatable
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
swap_module_method_existence Devise::Models::DatabaseAuthenticatable, :required_fields do
|
|
174
|
+
assert_deprecated do
|
|
175
|
+
Devise::Models.check_fields!(driver)
|
|
176
|
+
end
|
|
177
|
+
end
|
|
178
|
+
end
|
|
179
|
+
end
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class OmniAuthConfigTest < ActiveSupport::TestCase
|
|
4
|
+
class MyStrategy
|
|
5
|
+
include OmniAuth::Strategy
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
test 'strategy_name returns provider if no options given' do
|
|
9
|
+
config = Devise::OmniAuth::Config.new :facebook, [{}]
|
|
10
|
+
assert_equal :facebook, config.strategy_name
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
test 'strategy_name returns provider if no name option are given' do
|
|
14
|
+
config = Devise::OmniAuth::Config.new :facebook, [{ :other => :option }]
|
|
15
|
+
assert_equal :facebook, config.strategy_name
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
test 'returns name option when have a name' do
|
|
19
|
+
config = Devise::OmniAuth::Config.new :facebook, [{ :name => :github }]
|
|
20
|
+
assert_equal :github, config.strategy_name
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
test "finds contrib strategies" do
|
|
24
|
+
config = Devise::OmniAuth::Config.new :facebook, [{}]
|
|
25
|
+
assert_equal OmniAuth::Strategies::Facebook, config.strategy_class
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
test "finds the strategy in OmniAuth's list by name" do
|
|
29
|
+
NamedTestStrategy = Class.new
|
|
30
|
+
NamedTestStrategy.send :include, OmniAuth::Strategy
|
|
31
|
+
NamedTestStrategy.option :name, :the_one
|
|
32
|
+
|
|
33
|
+
config = Devise::OmniAuth::Config.new :the_one, [{}]
|
|
34
|
+
assert_equal NamedTestStrategy, config.strategy_class
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
test "finds the strategy in OmniAuth's list by class name" do
|
|
38
|
+
UnNamedTestStrategy = Class.new
|
|
39
|
+
UnNamedTestStrategy.send :include, OmniAuth::Strategy
|
|
40
|
+
|
|
41
|
+
config = Devise::OmniAuth::Config.new :un_named_test_strategy, [{}]
|
|
42
|
+
assert_equal UnNamedTestStrategy, config.strategy_class
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
test 'raises an error if strategy cannot be found' do
|
|
46
|
+
config = Devise::OmniAuth::Config.new :my_other_strategy, [{}]
|
|
47
|
+
assert_raise Devise::OmniAuth::StrategyNotFound do
|
|
48
|
+
config.strategy_class
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
test 'allows the user to define a custom require path' do
|
|
53
|
+
config = Devise::OmniAuth::Config.new :my_strategy, [{:strategy_class => MyStrategy}]
|
|
54
|
+
config_class = config.strategy_class
|
|
55
|
+
assert_equal MyStrategy, config_class
|
|
56
|
+
end
|
|
57
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class OmniAuthRoutesTest < ActionController::TestCase
|
|
4
|
+
tests ApplicationController
|
|
5
|
+
|
|
6
|
+
def assert_path(action, provider, with_param=true)
|
|
7
|
+
# Resource param
|
|
8
|
+
assert_equal @controller.send(action, :user, provider),
|
|
9
|
+
@controller.send("user_#{action}", provider)
|
|
10
|
+
|
|
11
|
+
# With an object
|
|
12
|
+
assert_equal @controller.send(action, User.new, provider),
|
|
13
|
+
@controller.send("user_#{action}", provider)
|
|
14
|
+
|
|
15
|
+
if with_param
|
|
16
|
+
# Default url params
|
|
17
|
+
assert_equal @controller.send(action, :user, provider, :param => 123),
|
|
18
|
+
@controller.send("user_#{action}", provider, :param => 123)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
test 'should alias omniauth_callback to mapped user auth_callback' do
|
|
23
|
+
assert_path :omniauth_callback_path, :facebook
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
test 'should alias omniauth_authorize to mapped user auth_authorize' do
|
|
27
|
+
assert_path :omniauth_authorize_path, :facebook, false
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
test 'should generate authorization path' do
|
|
31
|
+
assert_match "/users/auth/facebook", @controller.omniauth_authorize_path(:user, :facebook)
|
|
32
|
+
|
|
33
|
+
assert_raise ActionController::RoutingError do
|
|
34
|
+
@controller.omniauth_authorize_path(:user, :github)
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
test 'should generate authorization path for named open_id omniauth' do
|
|
39
|
+
assert_match "/users/auth/google", @controller.omniauth_authorize_path(:user, :google)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
test 'should generate authorization path with params' do
|
|
43
|
+
assert_match "/users/auth/openid?openid_url=http%3A%2F%2Fyahoo.com",
|
|
44
|
+
@controller.omniauth_authorize_path(:user, :openid, :openid_url => "http://yahoo.com")
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
test 'should not add a "?" if no param was sent' do
|
|
48
|
+
assert_equal "/users/auth/openid",
|
|
49
|
+
@controller.omniauth_authorize_path(:user, :openid)
|
|
50
|
+
end
|
|
51
|
+
end
|