devise-jdguyot 1.2.rc
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +10 -0
- data/CHANGELOG.rdoc +532 -0
- data/Gemfile +29 -0
- data/Gemfile.lock +152 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +353 -0
- data/Rakefile +36 -0
- data/TODO +4 -0
- data/app/controllers/devise/confirmations_controller.rb +33 -0
- data/app/controllers/devise/omniauth_callbacks_controller.rb +26 -0
- data/app/controllers/devise/passwords_controller.rb +41 -0
- data/app/controllers/devise/registrations_controller.rb +110 -0
- data/app/controllers/devise/sessions_controller.rb +25 -0
- data/app/controllers/devise/unlocks_controller.rb +34 -0
- data/app/helpers/devise_helper.rb +19 -0
- data/app/mailers/devise/mailer.rb +88 -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 +46 -0
- data/devise.gemspec +25 -0
- data/lib/devise/controllers/helpers.rb +227 -0
- data/lib/devise/controllers/internal_helpers.rb +119 -0
- data/lib/devise/controllers/scoped_views.rb +33 -0
- data/lib/devise/controllers/url_helpers.rb +39 -0
- data/lib/devise/encryptors/authlogic_sha512.rb +19 -0
- data/lib/devise/encryptors/base.rb +20 -0
- data/lib/devise/encryptors/clearance_sha1.rb +17 -0
- data/lib/devise/encryptors/restful_authentication_sha1.rb +22 -0
- data/lib/devise/encryptors/sha1.rb +25 -0
- data/lib/devise/encryptors/sha512.rb +25 -0
- data/lib/devise/failure_app.rb +132 -0
- data/lib/devise/hooks/activatable.rb +11 -0
- data/lib/devise/hooks/forgetable.rb +12 -0
- data/lib/devise/hooks/rememberable.rb +48 -0
- data/lib/devise/hooks/timeoutable.rb +22 -0
- data/lib/devise/hooks/trackable.rb +9 -0
- data/lib/devise/mapping.rb +110 -0
- data/lib/devise/models/authenticatable.rb +146 -0
- data/lib/devise/models/confirmable.rb +160 -0
- data/lib/devise/models/database_authenticatable.rb +100 -0
- data/lib/devise/models/encryptable.rb +72 -0
- data/lib/devise/models/lockable.rb +169 -0
- data/lib/devise/models/omniauthable.rb +23 -0
- data/lib/devise/models/recoverable.rb +123 -0
- data/lib/devise/models/registerable.rb +21 -0
- data/lib/devise/models/rememberable.rb +130 -0
- data/lib/devise/models/timeoutable.rb +43 -0
- data/lib/devise/models/token_authenticatable.rb +72 -0
- data/lib/devise/models/trackable.rb +30 -0
- data/lib/devise/models/validatable.rb +65 -0
- data/lib/devise/models.rb +68 -0
- data/lib/devise/modules.rb +30 -0
- data/lib/devise/omniauth/config.rb +30 -0
- data/lib/devise/omniauth/test_helpers.rb +57 -0
- data/lib/devise/omniauth/url_helpers.rb +29 -0
- data/lib/devise/omniauth.rb +47 -0
- data/lib/devise/orm/active_record.rb +38 -0
- data/lib/devise/orm/mongoid.rb +31 -0
- data/lib/devise/path_checker.rb +18 -0
- data/lib/devise/rails/routes.rb +292 -0
- data/lib/devise/rails/warden_compat.rb +125 -0
- data/lib/devise/rails.rb +50 -0
- data/lib/devise/schema.rb +97 -0
- data/lib/devise/strategies/authenticatable.rb +150 -0
- data/lib/devise/strategies/base.rb +15 -0
- data/lib/devise/strategies/database_authenticatable.rb +21 -0
- data/lib/devise/strategies/rememberable.rb +51 -0
- data/lib/devise/strategies/token_authenticatable.rb +53 -0
- data/lib/devise/test_helpers.rb +100 -0
- data/lib/devise/version.rb +3 -0
- data/lib/devise.rb +381 -0
- data/lib/generators/active_record/devise_generator.rb +28 -0
- data/lib/generators/active_record/templates/migration.rb +31 -0
- data/lib/generators/devise/devise_generator.rb +17 -0
- data/lib/generators/devise/install_generator.rb +24 -0
- data/lib/generators/devise/orm_helpers.rb +23 -0
- data/lib/generators/devise/views_generator.rb +106 -0
- data/lib/generators/mongoid/devise_generator.rb +17 -0
- data/lib/generators/templates/README +25 -0
- data/lib/generators/templates/devise.rb +186 -0
- data/test/controllers/helpers_test.rb +237 -0
- data/test/controllers/internal_helpers_test.rb +72 -0
- data/test/controllers/url_helpers_test.rb +59 -0
- data/test/devise_test.rb +65 -0
- data/test/encryptors_test.rb +30 -0
- data/test/failure_app_test.rb +187 -0
- data/test/generators/active_record_generator_test.rb +24 -0
- data/test/generators/install_generator_test.rb +13 -0
- data/test/generators/mongoid_generator_test.rb +22 -0
- data/test/generators/views_generator_test.rb +35 -0
- data/test/indifferent_hash.rb +33 -0
- data/test/integration/authenticatable_test.rb +447 -0
- data/test/integration/confirmable_test.rb +104 -0
- data/test/integration/database_authenticatable_test.rb +60 -0
- data/test/integration/http_authenticatable_test.rb +74 -0
- data/test/integration/lockable_test.rb +109 -0
- data/test/integration/omniauthable_test.rb +107 -0
- data/test/integration/recoverable_test.rb +160 -0
- data/test/integration/registerable_test.rb +179 -0
- data/test/integration/rememberable_test.rb +180 -0
- data/test/integration/timeoutable_test.rb +89 -0
- data/test/integration/token_authenticatable_test.rb +99 -0
- data/test/integration/trackable_test.rb +64 -0
- data/test/mailers/confirmation_instructions_test.rb +84 -0
- data/test/mailers/reset_password_instructions_test.rb +72 -0
- data/test/mailers/unlock_instructions_test.rb +66 -0
- data/test/mapping_test.rb +119 -0
- data/test/models/confirmable_test.rb +221 -0
- data/test/models/database_authenticatable_test.rb +98 -0
- data/test/models/encryptable_test.rb +65 -0
- data/test/models/lockable_test.rb +204 -0
- data/test/models/recoverable_test.rb +190 -0
- data/test/models/rememberable_test.rb +279 -0
- data/test/models/timeoutable_test.rb +28 -0
- data/test/models/token_authenticatable_test.rb +37 -0
- data/test/models/trackable_test.rb +5 -0
- data/test/models/validatable_test.rb +99 -0
- data/test/models_test.rb +84 -0
- data/test/omniauth/url_helpers_test.rb +47 -0
- data/test/orm/active_record.rb +9 -0
- data/test/orm/mongoid.rb +11 -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 +8 -0
- data/test/rails_app/app/controllers/admins/sessions_controller.rb +6 -0
- data/test/rails_app/app/controllers/admins_controller.rb +6 -0
- data/test/rails_app/app/controllers/application_controller.rb +8 -0
- data/test/rails_app/app/controllers/home_controller.rb +16 -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 +7 -0
- data/test/rails_app/app/controllers/users_controller.rb +18 -0
- data/test/rails_app/app/helpers/application_helper.rb +3 -0
- data/test/rails_app/app/mongoid/admin.rb +9 -0
- data/test/rails_app/app/mongoid/shim.rb +29 -0
- data/test/rails_app/app/mongoid/user.rb +10 -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/index.html.erb +1 -0
- data/test/rails_app/app/views/home/private.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 +40 -0
- data/test/rails_app/config/boot.rb +13 -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 +19 -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 +176 -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 +55 -0
- data/test/rails_app/config.ru +4 -0
- data/test/rails_app/db/migrate/20100401102949_create_tables.rb +31 -0
- data/test/rails_app/db/schema.rb +52 -0
- data/test/rails_app/lib/shared_admin.rb +9 -0
- data/test/rails_app/lib/shared_user.rb +23 -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 +179 -0
- data/test/support/assertions.rb +24 -0
- data/test/support/helpers.rb +60 -0
- data/test/support/integration.rb +88 -0
- data/test/support/locale/en.yml +4 -0
- data/test/support/webrat/integrations/rails.rb +24 -0
- data/test/test_helper.rb +29 -0
- data/test/test_helpers_test.rb +118 -0
- metadata +388 -0
@@ -0,0 +1,109 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class LockTest < ActionController::IntegrationTest
|
4
|
+
|
5
|
+
def visit_user_unlock_with_token(unlock_token)
|
6
|
+
visit user_unlock_path(:unlock_token => unlock_token)
|
7
|
+
end
|
8
|
+
|
9
|
+
test 'user should be able to request a new unlock token' do
|
10
|
+
user = create_user(:locked => true)
|
11
|
+
ActionMailer::Base.deliveries.clear
|
12
|
+
|
13
|
+
visit new_user_session_path
|
14
|
+
click_link "Didn't receive unlock instructions?"
|
15
|
+
|
16
|
+
fill_in 'email', :with => user.email
|
17
|
+
click_button 'Resend unlock instructions'
|
18
|
+
|
19
|
+
assert_template 'sessions/new'
|
20
|
+
assert_contain 'You will receive an email with instructions about how to unlock your account in a few minutes'
|
21
|
+
assert_equal 1, ActionMailer::Base.deliveries.size
|
22
|
+
end
|
23
|
+
|
24
|
+
test 'unlocked user should not be able to request a unlock token' do
|
25
|
+
user = create_user(:locked => false)
|
26
|
+
ActionMailer::Base.deliveries.clear
|
27
|
+
|
28
|
+
visit new_user_session_path
|
29
|
+
click_link "Didn't receive unlock instructions?"
|
30
|
+
|
31
|
+
fill_in 'email', :with => user.email
|
32
|
+
click_button 'Resend unlock instructions'
|
33
|
+
|
34
|
+
assert_template 'unlocks/new'
|
35
|
+
assert_contain 'not locked'
|
36
|
+
assert_equal 0, ActionMailer::Base.deliveries.size
|
37
|
+
end
|
38
|
+
|
39
|
+
test 'unlocked pages should not be available if email strategy is disabled' do
|
40
|
+
visit "/admins/sign_in"
|
41
|
+
|
42
|
+
assert_raise Webrat::NotFoundError do
|
43
|
+
click_link "Didn't receive unlock instructions?"
|
44
|
+
end
|
45
|
+
|
46
|
+
assert_raise NameError do
|
47
|
+
visit new_admin_unlock_path
|
48
|
+
end
|
49
|
+
|
50
|
+
visit "/admins/unlock/new"
|
51
|
+
assert_response :not_found
|
52
|
+
end
|
53
|
+
|
54
|
+
test 'user with invalid unlock token should not be able to unlock an account' do
|
55
|
+
visit_user_unlock_with_token('invalid_token')
|
56
|
+
|
57
|
+
assert_response :success
|
58
|
+
assert_current_url '/users/unlock?unlock_token=invalid_token'
|
59
|
+
assert_have_selector '#error_explanation'
|
60
|
+
assert_contain /Unlock token(.*)invalid/
|
61
|
+
end
|
62
|
+
|
63
|
+
test "locked user should be able to unlock account" do
|
64
|
+
user = create_user(:locked => true)
|
65
|
+
assert user.access_locked?
|
66
|
+
|
67
|
+
visit_user_unlock_with_token(user.unlock_token)
|
68
|
+
|
69
|
+
assert_current_url '/'
|
70
|
+
assert_contain 'Your account was successfully unlocked.'
|
71
|
+
|
72
|
+
assert_not user.reload.access_locked?
|
73
|
+
end
|
74
|
+
|
75
|
+
test "sign in user automatically after unlocking it's account" do
|
76
|
+
user = create_user(:locked => true)
|
77
|
+
visit_user_unlock_with_token(user.unlock_token)
|
78
|
+
assert warden.authenticated?(:user)
|
79
|
+
end
|
80
|
+
|
81
|
+
test "user should not be able to sign in when locked" do
|
82
|
+
user = sign_in_as_user(:locked => true)
|
83
|
+
assert_template 'sessions/new'
|
84
|
+
assert_contain 'Your account is locked.'
|
85
|
+
assert_not warden.authenticated?(:user)
|
86
|
+
end
|
87
|
+
|
88
|
+
test "user should not send a new e-mail if already locked" do
|
89
|
+
user = create_user(:locked => true)
|
90
|
+
user.failed_attempts = User.maximum_attempts + 1
|
91
|
+
user.save!
|
92
|
+
|
93
|
+
ActionMailer::Base.deliveries.clear
|
94
|
+
|
95
|
+
sign_in_as_user(:password => "invalid")
|
96
|
+
assert_contain 'Your account is locked.'
|
97
|
+
assert ActionMailer::Base.deliveries.empty?
|
98
|
+
end
|
99
|
+
|
100
|
+
test 'error message is configurable by resource name' do
|
101
|
+
store_translations :en, :devise => {
|
102
|
+
:failure => { :user => { :locked => "You are locked!" } }
|
103
|
+
} do
|
104
|
+
user = sign_in_as_user(:locked => true)
|
105
|
+
assert_contain 'You are locked!'
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class OmniauthableIntegrationTest < ActionController::IntegrationTest
|
4
|
+
FACEBOOK_INFO = {
|
5
|
+
:id => '12345',
|
6
|
+
:link => 'http://facebook.com/josevalim',
|
7
|
+
:email => 'user@example.com',
|
8
|
+
:first_name => 'Jose',
|
9
|
+
:last_name => 'Valim',
|
10
|
+
:website => 'http://blog.plataformatec.com.br'
|
11
|
+
}
|
12
|
+
|
13
|
+
ACCESS_TOKEN = {
|
14
|
+
:access_token => "plataformatec"
|
15
|
+
}
|
16
|
+
|
17
|
+
setup do
|
18
|
+
stub_facebook!
|
19
|
+
Devise::OmniAuth.short_circuit_authorizers!
|
20
|
+
end
|
21
|
+
|
22
|
+
teardown do
|
23
|
+
Devise::OmniAuth.unshort_circuit_authorizers!
|
24
|
+
Devise::OmniAuth.reset_stubs!
|
25
|
+
end
|
26
|
+
|
27
|
+
def stub_facebook!
|
28
|
+
Devise::OmniAuth.stub!(:facebook) do |b|
|
29
|
+
b.post('/oauth/access_token') { [200, {}, ACCESS_TOKEN.to_json] }
|
30
|
+
b.get('/me?access_token=plataformatec') { [200, {}, FACEBOOK_INFO.to_json] }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
test "can access omniauth.auth in the env hash" do
|
35
|
+
visit "/users/sign_in"
|
36
|
+
click_link "Sign in with Facebook"
|
37
|
+
|
38
|
+
json = ActiveSupport::JSON.decode(response.body)
|
39
|
+
|
40
|
+
assert_equal "12345", json["uid"]
|
41
|
+
assert_equal "facebook", json["provider"]
|
42
|
+
assert_equal "josevalim", json["user_info"]["nickname"]
|
43
|
+
assert_equal FACEBOOK_INFO, json["extra"]["user_hash"].symbolize_keys
|
44
|
+
assert_equal "plataformatec", json["credentials"]["token"]
|
45
|
+
end
|
46
|
+
|
47
|
+
test "cleans up session on sign up" do
|
48
|
+
assert_no_difference "User.count" do
|
49
|
+
visit "/users/sign_in"
|
50
|
+
click_link "Sign in with Facebook"
|
51
|
+
end
|
52
|
+
|
53
|
+
assert session["devise.facebook_data"]
|
54
|
+
|
55
|
+
assert_difference "User.count" do
|
56
|
+
visit "/users/sign_up"
|
57
|
+
fill_in "Password", :with => "123456"
|
58
|
+
fill_in "Password confirmation", :with => "123456"
|
59
|
+
click_button "Sign up"
|
60
|
+
end
|
61
|
+
|
62
|
+
assert_current_url "/"
|
63
|
+
assert_contain "You have signed up successfully."
|
64
|
+
assert_contain "Hello User user@example.com"
|
65
|
+
assert_not session["devise.facebook_data"]
|
66
|
+
end
|
67
|
+
|
68
|
+
test "cleans up session on cancel" do
|
69
|
+
assert_no_difference "User.count" do
|
70
|
+
visit "/users/sign_in"
|
71
|
+
click_link "Sign in with Facebook"
|
72
|
+
end
|
73
|
+
|
74
|
+
assert session["devise.facebook_data"]
|
75
|
+
visit "/users/cancel"
|
76
|
+
assert !session["devise.facebook_data"]
|
77
|
+
end
|
78
|
+
|
79
|
+
test "cleans up session on sign in" do
|
80
|
+
assert_no_difference "User.count" do
|
81
|
+
visit "/users/sign_in"
|
82
|
+
click_link "Sign in with Facebook"
|
83
|
+
end
|
84
|
+
|
85
|
+
assert session["devise.facebook_data"]
|
86
|
+
user = sign_in_as_user
|
87
|
+
assert !session["devise.facebook_data"]
|
88
|
+
end
|
89
|
+
|
90
|
+
test "handles callback error parameter according to the specification" do
|
91
|
+
visit "/users/auth/facebook/callback?error=access_denied"
|
92
|
+
assert_current_url "/users/sign_in"
|
93
|
+
assert_contain 'Could not authorize you from Facebook because "Access denied".'
|
94
|
+
end
|
95
|
+
|
96
|
+
test "handles other exceptions from omniauth" do
|
97
|
+
Devise::OmniAuth.stub!(:facebook) do |b|
|
98
|
+
b.post('/oauth/access_token') { [401, {}, {}.to_json] }
|
99
|
+
end
|
100
|
+
|
101
|
+
visit "/users/sign_in"
|
102
|
+
click_link "Sign in with facebook"
|
103
|
+
|
104
|
+
assert_current_url "/users/sign_in"
|
105
|
+
assert_contain 'Could not authorize you from Facebook because "Invalid credentials".'
|
106
|
+
end
|
107
|
+
end
|
@@ -0,0 +1,160 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class PasswordTest < ActionController::IntegrationTest
|
4
|
+
|
5
|
+
def visit_new_password_path
|
6
|
+
visit new_user_session_path
|
7
|
+
click_link 'Forgot your password?'
|
8
|
+
end
|
9
|
+
|
10
|
+
def request_forgot_password(&block)
|
11
|
+
visit_new_password_path
|
12
|
+
assert_response :success
|
13
|
+
assert_not warden.authenticated?(:user)
|
14
|
+
|
15
|
+
fill_in 'email', :with => 'user@test.com'
|
16
|
+
yield if block_given?
|
17
|
+
click_button 'Send me reset password instructions'
|
18
|
+
end
|
19
|
+
|
20
|
+
def reset_password(options={}, &block)
|
21
|
+
visit edit_user_password_path(:reset_password_token => options[:reset_password_token]) unless options[:visit] == false
|
22
|
+
assert_response :success
|
23
|
+
|
24
|
+
fill_in 'New password', :with => '987654321'
|
25
|
+
fill_in 'Confirm new password', :with => '987654321'
|
26
|
+
yield if block_given?
|
27
|
+
click_button 'Change my password'
|
28
|
+
end
|
29
|
+
|
30
|
+
test 'reset password with email of different case should succeed when email is in the list of case insensitive keys' do
|
31
|
+
create_user(:email => 'Foo@Bar.com')
|
32
|
+
|
33
|
+
request_forgot_password do
|
34
|
+
fill_in 'email', :with => 'foo@bar.com'
|
35
|
+
end
|
36
|
+
|
37
|
+
assert_current_url '/users/sign_in'
|
38
|
+
assert_contain 'You will receive an email with instructions about how to reset your password in a few minutes.'
|
39
|
+
end
|
40
|
+
|
41
|
+
test 'reset password with email of different case should fail when email is NOT the list of case insensitive keys' do
|
42
|
+
swap Devise, :case_insensitive_keys => [] do
|
43
|
+
create_user(:email => 'Foo@Bar.com')
|
44
|
+
|
45
|
+
request_forgot_password do
|
46
|
+
fill_in 'email', :with => 'foo@bar.com'
|
47
|
+
end
|
48
|
+
|
49
|
+
assert_response :success
|
50
|
+
assert_current_url '/users/password'
|
51
|
+
assert_have_selector "input[type=email][value='foo@bar.com']"
|
52
|
+
assert_contain 'not found'
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
test 'authenticated user should not be able to visit forgot password page' do
|
57
|
+
sign_in_as_user
|
58
|
+
assert warden.authenticated?(:user)
|
59
|
+
|
60
|
+
get new_user_password_path
|
61
|
+
|
62
|
+
assert_response :redirect
|
63
|
+
assert_redirected_to root_path
|
64
|
+
end
|
65
|
+
|
66
|
+
test 'not authenticated user should be able to request a forgot password' do
|
67
|
+
create_user
|
68
|
+
request_forgot_password
|
69
|
+
|
70
|
+
assert_current_url '/users/sign_in'
|
71
|
+
assert_contain 'You will receive an email with instructions about how to reset your password in a few minutes.'
|
72
|
+
end
|
73
|
+
|
74
|
+
test 'not authenticated user with invalid email should receive an error message' do
|
75
|
+
request_forgot_password do
|
76
|
+
fill_in 'email', :with => 'invalid.test@test.com'
|
77
|
+
end
|
78
|
+
|
79
|
+
assert_response :success
|
80
|
+
assert_current_url '/users/password'
|
81
|
+
assert_have_selector "input[type=email][value='invalid.test@test.com']"
|
82
|
+
assert_contain 'not found'
|
83
|
+
end
|
84
|
+
|
85
|
+
test 'authenticated user should not be able to visit edit password page' do
|
86
|
+
sign_in_as_user
|
87
|
+
get edit_user_password_path
|
88
|
+
assert_response :redirect
|
89
|
+
assert_redirected_to root_path
|
90
|
+
assert warden.authenticated?(:user)
|
91
|
+
end
|
92
|
+
|
93
|
+
test 'not authenticated user with invalid reset password token should not be able to change his password' do
|
94
|
+
user = create_user
|
95
|
+
reset_password :reset_password_token => 'invalid_reset_password'
|
96
|
+
|
97
|
+
assert_response :success
|
98
|
+
assert_current_url '/users/password'
|
99
|
+
assert_have_selector '#error_explanation'
|
100
|
+
assert_contain /Reset password token(.*)invalid/
|
101
|
+
assert_not user.reload.valid_password?('987654321')
|
102
|
+
end
|
103
|
+
|
104
|
+
test 'not authenticated user with valid reset password token but invalid password should not be able to change his password' do
|
105
|
+
user = create_user
|
106
|
+
request_forgot_password
|
107
|
+
reset_password :reset_password_token => user.reload.reset_password_token do
|
108
|
+
fill_in 'Confirm new password', :with => 'other_password'
|
109
|
+
end
|
110
|
+
|
111
|
+
assert_response :success
|
112
|
+
assert_current_url '/users/password'
|
113
|
+
assert_have_selector '#error_explanation'
|
114
|
+
assert_contain 'Password doesn\'t match confirmation'
|
115
|
+
assert_not user.reload.valid_password?('987654321')
|
116
|
+
end
|
117
|
+
|
118
|
+
test 'not authenticated user with valid data should be able to change his password' do
|
119
|
+
user = create_user
|
120
|
+
request_forgot_password
|
121
|
+
reset_password :reset_password_token => user.reload.reset_password_token
|
122
|
+
|
123
|
+
assert_current_url '/'
|
124
|
+
assert_contain 'Your password was changed successfully.'
|
125
|
+
assert user.reload.valid_password?('987654321')
|
126
|
+
end
|
127
|
+
|
128
|
+
test 'after entering invalid data user should still be able to change his password' do
|
129
|
+
user = create_user
|
130
|
+
request_forgot_password
|
131
|
+
reset_password :reset_password_token => user.reload.reset_password_token do
|
132
|
+
fill_in 'Confirm new password', :with => 'other_password'
|
133
|
+
end
|
134
|
+
assert_response :success
|
135
|
+
assert_have_selector '#error_explanation'
|
136
|
+
assert_not user.reload.valid_password?('987654321')
|
137
|
+
|
138
|
+
reset_password :reset_password_token => user.reload.reset_password_token, :visit => false
|
139
|
+
assert_contain 'Your password was changed successfully.'
|
140
|
+
assert user.reload.valid_password?('987654321')
|
141
|
+
end
|
142
|
+
|
143
|
+
test 'sign in user automatically after changing it\'s password' do
|
144
|
+
user = create_user
|
145
|
+
request_forgot_password
|
146
|
+
reset_password :reset_password_token => user.reload.reset_password_token
|
147
|
+
|
148
|
+
assert warden.authenticated?(:user)
|
149
|
+
end
|
150
|
+
|
151
|
+
test 'does not sign in user automatically after changing it\'s password if it\'s not active' do
|
152
|
+
user = create_user(:confirm => false)
|
153
|
+
request_forgot_password
|
154
|
+
reset_password :reset_password_token => user.reload.reset_password_token
|
155
|
+
|
156
|
+
assert_equal new_user_session_path, @request.path
|
157
|
+
assert !warden.authenticated?(:user)
|
158
|
+
end
|
159
|
+
|
160
|
+
end
|
@@ -0,0 +1,179 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class RegistrationTest < ActionController::IntegrationTest
|
4
|
+
|
5
|
+
test 'a guest admin should be able to sign in successfully' do
|
6
|
+
get new_admin_session_path
|
7
|
+
click_link 'Sign up'
|
8
|
+
|
9
|
+
assert_template 'registrations/new'
|
10
|
+
|
11
|
+
fill_in 'email', :with => 'new_user@test.com'
|
12
|
+
fill_in 'password', :with => 'new_user123'
|
13
|
+
fill_in 'password confirmation', :with => 'new_user123'
|
14
|
+
click_button 'Sign up'
|
15
|
+
|
16
|
+
assert_contain 'Welcome! You have signed up successfully.'
|
17
|
+
assert warden.authenticated?(:admin)
|
18
|
+
|
19
|
+
admin = Admin.last :order => "id"
|
20
|
+
assert_equal admin.email, 'new_user@test.com'
|
21
|
+
end
|
22
|
+
|
23
|
+
test 'a guest user should be able to sign up successfully and be blocked by confirmation' do
|
24
|
+
get new_user_registration_path
|
25
|
+
|
26
|
+
fill_in 'email', :with => 'new_user@test.com'
|
27
|
+
fill_in 'password', :with => 'new_user123'
|
28
|
+
fill_in 'password confirmation', :with => 'new_user123'
|
29
|
+
click_button 'Sign up'
|
30
|
+
|
31
|
+
assert_contain 'You have signed up successfully. However, we could not sign you in because your account is unconfirmed.'
|
32
|
+
assert_not_contain 'You have to confirm your account before continuing'
|
33
|
+
|
34
|
+
assert_not warden.authenticated?(:user)
|
35
|
+
|
36
|
+
user = User.last :order => "id"
|
37
|
+
assert_equal user.email, 'new_user@test.com'
|
38
|
+
assert_not user.confirmed?
|
39
|
+
end
|
40
|
+
|
41
|
+
test 'a guest user cannot sign up with invalid information' do
|
42
|
+
get new_user_registration_path
|
43
|
+
|
44
|
+
fill_in 'email', :with => 'invalid_email'
|
45
|
+
fill_in 'password', :with => 'new_user123'
|
46
|
+
fill_in 'password confirmation', :with => 'new_user321'
|
47
|
+
click_button 'Sign up'
|
48
|
+
|
49
|
+
assert_template 'registrations/new'
|
50
|
+
assert_have_selector '#error_explanation'
|
51
|
+
assert_contain "Email is invalid"
|
52
|
+
assert_contain "Password doesn't match confirmation"
|
53
|
+
assert_contain "2 errors prohibited"
|
54
|
+
assert_nil User.first
|
55
|
+
|
56
|
+
assert_not warden.authenticated?(:user)
|
57
|
+
end
|
58
|
+
|
59
|
+
test 'a guest should not sign up with email/password that already exists' do
|
60
|
+
user = create_user
|
61
|
+
get new_user_registration_path
|
62
|
+
|
63
|
+
fill_in 'email', :with => 'user@test.com'
|
64
|
+
fill_in 'password', :with => '123456'
|
65
|
+
fill_in 'password confirmation', :with => '123456'
|
66
|
+
click_button 'Sign up'
|
67
|
+
|
68
|
+
assert_current_url '/users'
|
69
|
+
assert_contain(/Email.*already.*taken/)
|
70
|
+
|
71
|
+
assert_not warden.authenticated?(:user)
|
72
|
+
end
|
73
|
+
|
74
|
+
test 'a guest should not be able to change account' do
|
75
|
+
get edit_user_registration_path
|
76
|
+
assert_redirected_to new_user_session_path
|
77
|
+
follow_redirect!
|
78
|
+
assert_contain 'You need to sign in or sign up before continuing.'
|
79
|
+
end
|
80
|
+
|
81
|
+
test 'a signed in user should not be able to access sign up' do
|
82
|
+
sign_in_as_user
|
83
|
+
get new_user_registration_path
|
84
|
+
assert_redirected_to root_path
|
85
|
+
end
|
86
|
+
|
87
|
+
test 'a signed in user should be able to edit his account' do
|
88
|
+
sign_in_as_user
|
89
|
+
get edit_user_registration_path
|
90
|
+
|
91
|
+
fill_in 'email', :with => 'user.new@email.com'
|
92
|
+
fill_in 'current password', :with => '123456'
|
93
|
+
click_button 'Update'
|
94
|
+
|
95
|
+
assert_current_url '/'
|
96
|
+
assert_contain 'You updated your account successfully.'
|
97
|
+
|
98
|
+
assert_equal "user.new@email.com", User.first.email
|
99
|
+
end
|
100
|
+
|
101
|
+
test 'a signed in user should still be able to use the website after changing his password' do
|
102
|
+
sign_in_as_user
|
103
|
+
get edit_user_registration_path
|
104
|
+
|
105
|
+
fill_in 'password', :with => '12345678'
|
106
|
+
fill_in 'password confirmation', :with => '12345678'
|
107
|
+
fill_in 'current password', :with => '123456'
|
108
|
+
click_button 'Update'
|
109
|
+
|
110
|
+
assert_contain 'You updated your account successfully.'
|
111
|
+
get users_path
|
112
|
+
assert warden.authenticated?(:user)
|
113
|
+
end
|
114
|
+
|
115
|
+
test 'a signed in user should not change his current user with invalid password' do
|
116
|
+
sign_in_as_user
|
117
|
+
get edit_user_registration_path
|
118
|
+
|
119
|
+
fill_in 'email', :with => 'user.new@email.com'
|
120
|
+
fill_in 'current password', :with => 'invalid'
|
121
|
+
click_button 'Update'
|
122
|
+
|
123
|
+
assert_template 'registrations/edit'
|
124
|
+
assert_contain 'user@test.com'
|
125
|
+
assert_have_selector 'form input[value="user.new@email.com"]'
|
126
|
+
|
127
|
+
assert_equal "user@test.com", User.first.email
|
128
|
+
end
|
129
|
+
|
130
|
+
test 'a signed in user should be able to edit his password' do
|
131
|
+
sign_in_as_user
|
132
|
+
get edit_user_registration_path
|
133
|
+
|
134
|
+
fill_in 'password', :with => 'pas123'
|
135
|
+
fill_in 'password confirmation', :with => 'pas123'
|
136
|
+
fill_in 'current password', :with => '123456'
|
137
|
+
click_button 'Update'
|
138
|
+
|
139
|
+
assert_current_url '/'
|
140
|
+
assert_contain 'You updated your account successfully.'
|
141
|
+
|
142
|
+
assert User.first.valid_password?('pas123')
|
143
|
+
end
|
144
|
+
|
145
|
+
test 'a signed in user should not be able to edit his password with invalid confirmation' do
|
146
|
+
sign_in_as_user
|
147
|
+
get edit_user_registration_path
|
148
|
+
|
149
|
+
fill_in 'password', :with => 'pas123'
|
150
|
+
fill_in 'password confirmation', :with => ''
|
151
|
+
fill_in 'current password', :with => '123456'
|
152
|
+
click_button 'Update'
|
153
|
+
|
154
|
+
assert_contain "Password doesn't match confirmation"
|
155
|
+
assert_not User.first.valid_password?('pas123')
|
156
|
+
end
|
157
|
+
|
158
|
+
test 'a signed in user should be able to cancel his account' do
|
159
|
+
sign_in_as_user
|
160
|
+
get edit_user_registration_path
|
161
|
+
|
162
|
+
click_link "Cancel my account", :method => :delete
|
163
|
+
assert_contain "Bye! Your account was successfully cancelled. We hope to see you again soon."
|
164
|
+
|
165
|
+
assert User.all.empty?
|
166
|
+
end
|
167
|
+
|
168
|
+
test 'a user should be able to cancel sign up by deleting data in the session' do
|
169
|
+
get "/set"
|
170
|
+
assert_equal "something", @request.session["devise.foo_bar"]
|
171
|
+
|
172
|
+
get "/users/sign_up"
|
173
|
+
assert_equal "something", @request.session["devise.foo_bar"]
|
174
|
+
|
175
|
+
get "/users/cancel"
|
176
|
+
assert_nil @request.session["devise.foo_bar"]
|
177
|
+
assert_redirected_to new_user_registration_path
|
178
|
+
end
|
179
|
+
end
|