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,49 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
class SerializableTest < ActiveSupport::TestCase
|
5
|
+
setup do
|
6
|
+
@user = create_user
|
7
|
+
end
|
8
|
+
|
9
|
+
test 'should not include unsafe keys on XML' do
|
10
|
+
assert_match /email/, @user.to_xml
|
11
|
+
assert_no_match /confirmation-token/, @user.to_xml
|
12
|
+
end
|
13
|
+
|
14
|
+
test 'should not include unsafe keys on XML even if a new except is provided' do
|
15
|
+
assert_no_match /email/, @user.to_xml(:except => :email)
|
16
|
+
assert_no_match /confirmation-token/, @user.to_xml(:except => :email)
|
17
|
+
end
|
18
|
+
|
19
|
+
test 'should include unsafe keys on XML if a force_except is provided' do
|
20
|
+
assert_no_match /<email/, @user.to_xml(:force_except => :email)
|
21
|
+
assert_match /confirmation-token/, @user.to_xml(:force_except => :email)
|
22
|
+
end
|
23
|
+
|
24
|
+
test 'should not include unsafe keys on JSON' do
|
25
|
+
assert_equal %w(created_at email facebook_token id updated_at username), from_json().keys.sort
|
26
|
+
end
|
27
|
+
|
28
|
+
test 'should not include unsafe keys on JSON even if a new except is provided' do
|
29
|
+
assert_no_key "email", from_json(:except => :email)
|
30
|
+
assert_no_key "confirmation_token", from_json(:except => :email)
|
31
|
+
end
|
32
|
+
|
33
|
+
test 'should include unsafe keys on JSON if a force_except is provided' do
|
34
|
+
assert_no_key "email", from_json(:force_except => :email)
|
35
|
+
assert_key "confirmation_token", from_json(:force_except => :email)
|
36
|
+
end
|
37
|
+
|
38
|
+
def assert_key(key, subject)
|
39
|
+
assert subject.key?(key), "Expected #{subject.inspect} to have key #{key.inspect}"
|
40
|
+
end
|
41
|
+
|
42
|
+
def assert_no_key(key, subject)
|
43
|
+
assert !subject.key?(key), "Expected #{subject.inspect} to not have key #{key.inspect}"
|
44
|
+
end
|
45
|
+
|
46
|
+
def from_json(options=nil)
|
47
|
+
ActiveSupport::JSON.decode(@user.to_json(options))["user"]
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
class TimeoutableTest < ActiveSupport::TestCase
|
5
|
+
|
6
|
+
test 'should be expired' do
|
7
|
+
assert new_user.timedout?(31.minutes.ago)
|
8
|
+
end
|
9
|
+
|
10
|
+
test 'should not be expired' do
|
11
|
+
assert_not new_user.timedout?(29.minutes.ago)
|
12
|
+
end
|
13
|
+
|
14
|
+
test 'should not be expired when params is nil' do
|
15
|
+
assert_not new_user.timedout?(nil)
|
16
|
+
end
|
17
|
+
|
18
|
+
test 'should use timeout_in method' do
|
19
|
+
user = new_user
|
20
|
+
user.instance_eval { def timeout_in; 10.minutes end }
|
21
|
+
|
22
|
+
assert user.timedout?(12.minutes.ago)
|
23
|
+
assert_not user.timedout?(8.minutes.ago)
|
24
|
+
end
|
25
|
+
|
26
|
+
test 'should not be expired when timeout_in method returns nil' do
|
27
|
+
user = new_user
|
28
|
+
user.instance_eval { def timeout_in; nil end }
|
29
|
+
assert_not user.timedout?(10.hours.ago)
|
30
|
+
end
|
31
|
+
|
32
|
+
test 'fallback to Devise config option' do
|
33
|
+
swap Devise, :timeout_in => 1.minute do
|
34
|
+
user = new_user
|
35
|
+
assert user.timedout?(2.minutes.ago)
|
36
|
+
assert_not user.timedout?(30.seconds.ago)
|
37
|
+
|
38
|
+
Devise.timeout_in = 5.minutes
|
39
|
+
assert_not user.timedout?(2.minutes.ago)
|
40
|
+
assert user.timedout?(6.minutes.ago)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
test 'required_fields should contain the fields that Devise uses' do
|
45
|
+
assert_same_content Devise::Models::Timeoutable.required_fields(User), []
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
class TokenAuthenticatableTest < ActiveSupport::TestCase
|
5
|
+
|
6
|
+
test 'should reset authentication token' do
|
7
|
+
user = new_user
|
8
|
+
user.reset_authentication_token
|
9
|
+
previous_token = user.authentication_token
|
10
|
+
user.reset_authentication_token
|
11
|
+
assert_not_equal previous_token, user.authentication_token
|
12
|
+
end
|
13
|
+
|
14
|
+
test 'should ensure authentication token' do
|
15
|
+
user = new_user
|
16
|
+
user.ensure_authentication_token
|
17
|
+
previous_token = user.authentication_token
|
18
|
+
user.ensure_authentication_token
|
19
|
+
assert_equal previous_token, user.authentication_token
|
20
|
+
end
|
21
|
+
|
22
|
+
test 'should authenticate a valid user with authentication token and return it' do
|
23
|
+
user = create_user
|
24
|
+
user.ensure_authentication_token!
|
25
|
+
user.confirm!
|
26
|
+
authenticated_user = User.find_for_token_authentication(:auth_token => user.authentication_token)
|
27
|
+
assert_equal authenticated_user, user
|
28
|
+
end
|
29
|
+
|
30
|
+
test 'should return nil when authenticating an invalid user by authentication token' do
|
31
|
+
user = create_user
|
32
|
+
user.ensure_authentication_token!
|
33
|
+
user.confirm!
|
34
|
+
authenticated_user = User.find_for_token_authentication(:auth_token => user.authentication_token.reverse)
|
35
|
+
assert_nil authenticated_user
|
36
|
+
end
|
37
|
+
|
38
|
+
test 'should not be subject to injection' do
|
39
|
+
user1 = create_user
|
40
|
+
user1.ensure_authentication_token!
|
41
|
+
user1.confirm!
|
42
|
+
|
43
|
+
user2 = create_user
|
44
|
+
user2.ensure_authentication_token!
|
45
|
+
user2.confirm!
|
46
|
+
|
47
|
+
user = User.find_for_token_authentication(:auth_token => {'$ne' => user1.authentication_token})
|
48
|
+
assert_nil user
|
49
|
+
end
|
50
|
+
|
51
|
+
test 'required_fields should contain the fields that Devise uses' do
|
52
|
+
assert_same_content Devise::Models::TokenAuthenticatable.required_fields(User), [
|
53
|
+
:authentication_token
|
54
|
+
]
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
class TrackableTest < ActiveSupport::TestCase
|
5
|
+
test 'required_fields should contain the fields that Devise uses' do
|
6
|
+
assert_same_content Devise::Models::Trackable.required_fields(User), [
|
7
|
+
:current_sign_in_at,
|
8
|
+
:current_sign_in_ip,
|
9
|
+
:last_sign_in_at,
|
10
|
+
:last_sign_in_ip,
|
11
|
+
:sign_in_count
|
12
|
+
]
|
13
|
+
end
|
14
|
+
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,180 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
class Configurable < User
|
5
|
+
devise :database_authenticatable, :confirmable, :rememberable, :timeoutable, :lockable,
|
6
|
+
:stretches => 15, :pepper => 'abcdef', :allow_unconfirmed_access_for => 5.days,
|
7
|
+
:remember_for => 7.days, :timeout_in => 15.minutes, :unlock_in => 10.days
|
8
|
+
end
|
9
|
+
|
10
|
+
class WithValidation < Admin
|
11
|
+
devise :database_authenticatable, :validatable, :password_length => 2..6
|
12
|
+
end
|
13
|
+
|
14
|
+
class UserWithValidation < User
|
15
|
+
validates_presence_of :username
|
16
|
+
end
|
17
|
+
|
18
|
+
class Several < Admin
|
19
|
+
devise :validatable
|
20
|
+
devise :lockable
|
21
|
+
end
|
22
|
+
|
23
|
+
class Inheritable < Admin
|
24
|
+
end
|
25
|
+
|
26
|
+
class ActiveRecordTest < ActiveSupport::TestCase
|
27
|
+
def include_module?(klass, mod)
|
28
|
+
klass.devise_modules.include?(mod) &&
|
29
|
+
klass.included_modules.include?(Devise::Models::const_get(mod.to_s.classify))
|
30
|
+
end
|
31
|
+
|
32
|
+
def assert_include_modules(klass, *modules)
|
33
|
+
modules.each do |mod|
|
34
|
+
assert include_module?(klass, mod)
|
35
|
+
end
|
36
|
+
|
37
|
+
(Devise::ALL - modules).each do |mod|
|
38
|
+
assert_not include_module?(klass, mod)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
test 'can cherry pick modules' do
|
43
|
+
assert_include_modules Admin, :database_authenticatable, :registerable, :timeoutable, :recoverable, :lockable, :confirmable
|
44
|
+
end
|
45
|
+
|
46
|
+
test 'validations options are not applied too late' do
|
47
|
+
validators = WithValidation.validators_on :password
|
48
|
+
length = validators.find { |v| v.kind == :length }
|
49
|
+
assert_equal 2, length.options[:minimum]
|
50
|
+
assert_equal 6, length.options[:maximum]
|
51
|
+
end
|
52
|
+
|
53
|
+
test 'validations are applied just once' do
|
54
|
+
validators = Several.validators_on :password
|
55
|
+
assert_equal 1, validators.select{ |v| v.kind == :length }.length
|
56
|
+
end
|
57
|
+
|
58
|
+
test 'chosen modules are inheritable' do
|
59
|
+
assert_include_modules Inheritable, :database_authenticatable, :registerable, :timeoutable, :recoverable, :lockable, :confirmable
|
60
|
+
end
|
61
|
+
|
62
|
+
test 'order of module inclusion' do
|
63
|
+
correct_module_order = [:database_authenticatable, :recoverable, :registerable, :confirmable, :lockable, :timeoutable]
|
64
|
+
incorrect_module_order = [:database_authenticatable, :timeoutable, :registerable, :recoverable, :lockable, :confirmable]
|
65
|
+
|
66
|
+
assert_include_modules Admin, *incorrect_module_order
|
67
|
+
|
68
|
+
# get module constants from symbol list
|
69
|
+
module_constants = correct_module_order.collect { |mod| Devise::Models::const_get(mod.to_s.classify) }
|
70
|
+
|
71
|
+
# confirm that they adhere to the order in ALL
|
72
|
+
# get included modules, filter out the noise, and reverse the order
|
73
|
+
assert_equal module_constants, (Admin.included_modules & module_constants).reverse
|
74
|
+
end
|
75
|
+
|
76
|
+
test 'raise error on invalid module' do
|
77
|
+
assert_raise NameError do
|
78
|
+
# Mix valid an invalid modules.
|
79
|
+
Configurable.class_eval { devise :database_authenticatable, :doesnotexit }
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
test 'set a default value for stretches' do
|
84
|
+
assert_equal 15, Configurable.stretches
|
85
|
+
end
|
86
|
+
|
87
|
+
test 'set a default value for pepper' do
|
88
|
+
assert_equal 'abcdef', Configurable.pepper
|
89
|
+
end
|
90
|
+
|
91
|
+
test 'set a default value for allow_unconfirmed_access_for' do
|
92
|
+
assert_equal 5.days, Configurable.allow_unconfirmed_access_for
|
93
|
+
end
|
94
|
+
|
95
|
+
test 'set a default value for remember_for' do
|
96
|
+
assert_equal 7.days, Configurable.remember_for
|
97
|
+
end
|
98
|
+
|
99
|
+
test 'set a default value for timeout_in' do
|
100
|
+
assert_equal 15.minutes, Configurable.timeout_in
|
101
|
+
end
|
102
|
+
|
103
|
+
test 'set a default value for unlock_in' do
|
104
|
+
assert_equal 10.days, Configurable.unlock_in
|
105
|
+
end
|
106
|
+
|
107
|
+
test 'set null fields on migrations' do
|
108
|
+
Admin.create!
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
class CheckFieldsTest < ActiveSupport::TestCase
|
113
|
+
test 'checks if the class respond_to the required fields' do
|
114
|
+
Player = Class.new do
|
115
|
+
extend Devise::Models
|
116
|
+
|
117
|
+
def self.before_validation(instance)
|
118
|
+
end
|
119
|
+
|
120
|
+
devise :database_authenticatable
|
121
|
+
|
122
|
+
attr_accessor :encrypted_password, :email
|
123
|
+
end
|
124
|
+
|
125
|
+
assert_nothing_raised Devise::Models::MissingAttribute do
|
126
|
+
Devise::Models.check_fields!(Player)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
test 'raises Devise::Models::MissingAtrribute and shows the missing attribute if the class doesn\'t respond_to one of the attributes' do
|
131
|
+
Clown = Class.new do
|
132
|
+
extend Devise::Models
|
133
|
+
|
134
|
+
def self.before_validation(instance)
|
135
|
+
end
|
136
|
+
|
137
|
+
devise :database_authenticatable
|
138
|
+
|
139
|
+
attr_accessor :encrypted_password
|
140
|
+
end
|
141
|
+
|
142
|
+
assert_raise_with_message Devise::Models::MissingAttribute, "The following attribute(s) is (are) missing on your model: email" do
|
143
|
+
Devise::Models.check_fields!(Clown)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
test 'raises Devise::Models::MissingAtrribute with all the missing attributes if there is more than one' do
|
148
|
+
Magician = Class.new do
|
149
|
+
extend Devise::Models
|
150
|
+
|
151
|
+
def self.before_validation(instance)
|
152
|
+
end
|
153
|
+
|
154
|
+
devise :database_authenticatable
|
155
|
+
end
|
156
|
+
|
157
|
+
assert_raise_with_message Devise::Models::MissingAttribute, "The following attribute(s) is (are) missing on your model: encrypted_password, email" do
|
158
|
+
Devise::Models.check_fields!(Magician)
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
test "doesn't raise a NoMethodError exception when the module doesn't have a required_field(klass) class method" do
|
163
|
+
driver = Class.new do
|
164
|
+
extend Devise::Models
|
165
|
+
|
166
|
+
def self.before_validation(instance)
|
167
|
+
end
|
168
|
+
|
169
|
+
attr_accessor :encrypted_password, :email
|
170
|
+
|
171
|
+
devise :database_authenticatable
|
172
|
+
end
|
173
|
+
|
174
|
+
swap_module_method_existence Devise::Models::DatabaseAuthenticatable, :required_fields do
|
175
|
+
assert_deprecated do
|
176
|
+
Devise::Models.check_fields!(driver)
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
class OmniAuthConfigTest < ActiveSupport::TestCase
|
5
|
+
class MyStrategy
|
6
|
+
include OmniAuth::Strategy
|
7
|
+
end
|
8
|
+
|
9
|
+
test 'strategy_name returns provider if no options given' do
|
10
|
+
config = Devise::OmniAuth::Config.new :facebook, [{}]
|
11
|
+
assert_equal :facebook, config.strategy_name
|
12
|
+
end
|
13
|
+
|
14
|
+
test 'strategy_name returns provider if no name option are given' do
|
15
|
+
config = Devise::OmniAuth::Config.new :facebook, [{ :other => :option }]
|
16
|
+
assert_equal :facebook, config.strategy_name
|
17
|
+
end
|
18
|
+
|
19
|
+
test 'returns name option when have a name' do
|
20
|
+
config = Devise::OmniAuth::Config.new :facebook, [{ :name => :github }]
|
21
|
+
assert_equal :github, config.strategy_name
|
22
|
+
end
|
23
|
+
|
24
|
+
test "finds contrib strategies" do
|
25
|
+
config = Devise::OmniAuth::Config.new :facebook, [{}]
|
26
|
+
assert_equal OmniAuth::Strategies::Facebook, config.strategy_class
|
27
|
+
end
|
28
|
+
|
29
|
+
test "finds the strategy in OmniAuth's list by name" do
|
30
|
+
NamedTestStrategy = Class.new
|
31
|
+
NamedTestStrategy.send :include, OmniAuth::Strategy
|
32
|
+
NamedTestStrategy.option :name, :the_one
|
33
|
+
|
34
|
+
config = Devise::OmniAuth::Config.new :the_one, [{}]
|
35
|
+
assert_equal NamedTestStrategy, config.strategy_class
|
36
|
+
end
|
37
|
+
|
38
|
+
test "finds the strategy in OmniAuth's list by class name" do
|
39
|
+
UnNamedTestStrategy = Class.new
|
40
|
+
UnNamedTestStrategy.send :include, OmniAuth::Strategy
|
41
|
+
|
42
|
+
config = Devise::OmniAuth::Config.new :un_named_test_strategy, [{}]
|
43
|
+
assert_equal UnNamedTestStrategy, config.strategy_class
|
44
|
+
end
|
45
|
+
|
46
|
+
test 'raises an error if strategy cannot be found' do
|
47
|
+
config = Devise::OmniAuth::Config.new :my_other_strategy, [{}]
|
48
|
+
assert_raise Devise::OmniAuth::StrategyNotFound do
|
49
|
+
config.strategy_class
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
test 'allows the user to define a custom require path' do
|
54
|
+
config = Devise::OmniAuth::Config.new :my_strategy, [{:strategy_class => MyStrategy}]
|
55
|
+
config_class = config.strategy_class
|
56
|
+
assert_equal MyStrategy, config_class
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
class OmniAuthRoutesTest < ActionController::TestCase
|
5
|
+
tests ApplicationController
|
6
|
+
|
7
|
+
def assert_path(action, provider, with_param=true)
|
8
|
+
# Resource param
|
9
|
+
assert_equal @controller.send(action, :user, provider),
|
10
|
+
@controller.send("user_#{action}", provider)
|
11
|
+
|
12
|
+
# With an object
|
13
|
+
assert_equal @controller.send(action, User.new, provider),
|
14
|
+
@controller.send("user_#{action}", provider)
|
15
|
+
|
16
|
+
if with_param
|
17
|
+
# Default url params
|
18
|
+
assert_equal @controller.send(action, :user, provider, :param => 123),
|
19
|
+
@controller.send("user_#{action}", provider, :param => 123)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
test 'should alias omniauth_callback to mapped user auth_callback' do
|
24
|
+
assert_path :omniauth_callback_path, :facebook
|
25
|
+
end
|
26
|
+
|
27
|
+
test 'should alias omniauth_authorize to mapped user auth_authorize' do
|
28
|
+
assert_path :omniauth_authorize_path, :facebook, false
|
29
|
+
end
|
30
|
+
|
31
|
+
test 'should generate authorization path' do
|
32
|
+
assert_match "/users/auth/facebook", @controller.omniauth_authorize_path(:user, :facebook)
|
33
|
+
|
34
|
+
assert_raise ActionController::RoutingError do
|
35
|
+
@controller.omniauth_authorize_path(:user, :github)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
test 'should generate authorization path for named open_id omniauth' do
|
40
|
+
assert_match "/users/auth/google", @controller.omniauth_authorize_path(:user, :google)
|
41
|
+
end
|
42
|
+
|
43
|
+
test 'should generate authorization path with params' do
|
44
|
+
assert_match "/users/auth/openid?openid_url=http%3A%2F%2Fyahoo.com",
|
45
|
+
@controller.omniauth_authorize_path(:user, :openid, :openid_url => "http://yahoo.com")
|
46
|
+
end
|
47
|
+
|
48
|
+
test 'should not add a "?" if no param was sent' do
|
49
|
+
assert_equal "/users/auth/openid",
|
50
|
+
@controller.omniauth_authorize_path(:user, :openid)
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
ActiveRecord::Migration.verbose = false
|
3
|
+
ActiveRecord::Base.logger = Logger.new(nil)
|
4
|
+
|
5
|
+
ActiveRecord::Migrator.migrate(File.expand_path("../../rails_app/db/migrate/", __FILE__))
|
6
|
+
|
7
|
+
class ActiveSupport::TestCase
|
8
|
+
self.use_transactional_fixtures = true
|
9
|
+
self.use_instantiated_fixtures = false
|
10
|
+
end
|
data/test/orm/mongoid.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'mongoid/version'
|
3
|
+
|
4
|
+
Mongoid.configure do |config|
|
5
|
+
config.master = Mongo::Connection.new('127.0.0.1', 27017).db("devise-test-suite")
|
6
|
+
config.use_utc = true
|
7
|
+
config.include_root_in_json = true
|
8
|
+
end
|
9
|
+
|
10
|
+
class ActiveSupport::TestCase
|
11
|
+
setup do
|
12
|
+
User.delete_all
|
13
|
+
Admin.delete_all
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
2
|
+
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
3
|
+
|
4
|
+
require File.expand_path('../config/application', __FILE__)
|
5
|
+
|
6
|
+
require 'rake'
|
7
|
+
require 'rake/testtask'
|
8
|
+
require 'rake/rdoctask'
|
9
|
+
|
10
|
+
Rails.application.load_tasks
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
class AdminsController < ApplicationController
|
3
|
+
before_filter :authenticate_admin!
|
4
|
+
|
5
|
+
def index
|
6
|
+
end
|
7
|
+
|
8
|
+
def expire
|
9
|
+
admin_session['last_request_at'] = 31.minutes.ago.utc
|
10
|
+
render :text => 'Admin will be expired on next request'
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
# Filters added to this controller apply to all controllers in the application.
|
3
|
+
# Likewise, all the methods added will be available for all controllers.
|
4
|
+
|
5
|
+
class ApplicationController < ActionController::Base
|
6
|
+
protect_from_forgery
|
7
|
+
before_filter :current_user, :unless => :devise_controller?
|
8
|
+
before_filter :authenticate_user!, :if => :devise_controller?
|
9
|
+
end
|