cloudfoundry-devise 1.5.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 +12 -0
- data/.travis.yml +13 -0
- data/CHANGELOG.rdoc +755 -0
- data/Gemfile +35 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +366 -0
- data/Rakefile +34 -0
- data/app/controllers/devise/confirmations_controller.rb +46 -0
- data/app/controllers/devise/omniauth_callbacks_controller.rb +26 -0
- data/app/controllers/devise/passwords_controller.rb +50 -0
- data/app/controllers/devise/registrations_controller.rb +114 -0
- data/app/controllers/devise/sessions_controller.rb +49 -0
- data/app/controllers/devise/unlocks_controller.rb +34 -0
- data/app/helpers/devise_helper.rb +25 -0
- data/app/mailers/devise/mailer.rb +15 -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/cloudfoundry-devise.gemspec +25 -0
- data/config/locales/en.yml +59 -0
- data/lib/devise.rb +453 -0
- data/lib/devise/controllers/helpers.rb +260 -0
- data/lib/devise/controllers/internal_helpers.rb +161 -0
- data/lib/devise/controllers/rememberable.rb +52 -0
- data/lib/devise/controllers/scoped_views.rb +33 -0
- data/lib/devise/controllers/shared_helpers.rb +26 -0
- data/lib/devise/controllers/url_helpers.rb +53 -0
- data/lib/devise/delegator.rb +16 -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 +149 -0
- data/lib/devise/hooks/activatable.rb +11 -0
- data/lib/devise/hooks/forgetable.rb +9 -0
- data/lib/devise/hooks/rememberable.rb +6 -0
- data/lib/devise/hooks/timeoutable.rb +24 -0
- data/lib/devise/hooks/trackable.rb +9 -0
- data/lib/devise/mailers/helpers.rb +86 -0
- data/lib/devise/mapping.rb +175 -0
- data/lib/devise/models.rb +91 -0
- data/lib/devise/models/authenticatable.rb +181 -0
- data/lib/devise/models/confirmable.rb +220 -0
- data/lib/devise/models/database_authenticatable.rb +122 -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 +136 -0
- data/lib/devise/models/registerable.rb +21 -0
- data/lib/devise/models/rememberable.rb +114 -0
- data/lib/devise/models/serializable.rb +43 -0
- data/lib/devise/models/timeoutable.rb +45 -0
- data/lib/devise/models/token_authenticatable.rb +72 -0
- data/lib/devise/models/trackable.rb +30 -0
- data/lib/devise/models/validatable.rb +62 -0
- data/lib/devise/modules.rb +30 -0
- data/lib/devise/omniauth.rb +28 -0
- data/lib/devise/omniauth/config.rb +45 -0
- data/lib/devise/omniauth/url_helpers.rb +33 -0
- data/lib/devise/orm/active_record.rb +44 -0
- data/lib/devise/orm/mongoid.rb +31 -0
- data/lib/devise/param_filter.rb +41 -0
- data/lib/devise/path_checker.rb +18 -0
- data/lib/devise/rails.rb +73 -0
- data/lib/devise/rails/routes.rb +385 -0
- data/lib/devise/rails/warden_compat.rb +120 -0
- data/lib/devise/schema.rb +109 -0
- data/lib/devise/strategies/authenticatable.rb +155 -0
- data/lib/devise/strategies/base.rb +15 -0
- data/lib/devise/strategies/database_authenticatable.rb +21 -0
- data/lib/devise/strategies/rememberable.rb +53 -0
- data/lib/devise/strategies/token_authenticatable.rb +57 -0
- data/lib/devise/test_helpers.rb +90 -0
- data/lib/devise/version.rb +3 -0
- data/lib/generators/active_record/devise_generator.rb +71 -0
- data/lib/generators/active_record/templates/migration.rb +29 -0
- data/lib/generators/active_record/templates/migration_existing.rb +26 -0
- data/lib/generators/devise/devise_generator.rb +22 -0
- data/lib/generators/devise/install_generator.rb +24 -0
- data/lib/generators/devise/orm_helpers.rb +31 -0
- data/lib/generators/devise/views_generator.rb +98 -0
- data/lib/generators/mongoid/devise_generator.rb +60 -0
- data/lib/generators/templates/README +32 -0
- data/lib/generators/templates/devise.rb +215 -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/helpers_test.rb +254 -0
- data/test/controllers/internal_helpers_test.rb +96 -0
- data/test/controllers/sessions_controller_test.rb +16 -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/encryptors_test.rb +30 -0
- data/test/failure_app_test.rb +207 -0
- data/test/generators/active_record_generator_test.rb +47 -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/indifferent_hash.rb +33 -0
- data/test/integration/authenticatable_test.rb +590 -0
- data/test/integration/confirmable_test.rb +262 -0
- data/test/integration/database_authenticatable_test.rb +82 -0
- data/test/integration/http_authenticatable_test.rb +82 -0
- data/test/integration/lockable_test.rb +212 -0
- data/test/integration/omniauthable_test.rb +133 -0
- data/test/integration/recoverable_test.rb +287 -0
- data/test/integration/registerable_test.rb +335 -0
- data/test/integration/rememberable_test.rb +158 -0
- data/test/integration/timeoutable_test.rb +98 -0
- data/test/integration/token_authenticatable_test.rb +148 -0
- data/test/integration/trackable_test.rb +92 -0
- data/test/mailers/confirmation_instructions_test.rb +95 -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 +128 -0
- data/test/models/confirmable_test.rb +334 -0
- data/test/models/database_authenticatable_test.rb +167 -0
- data/test/models/encryptable_test.rb +67 -0
- data/test/models/lockable_test.rb +225 -0
- data/test/models/recoverable_test.rb +198 -0
- data/test/models/rememberable_test.rb +168 -0
- data/test/models/serializable_test.rb +38 -0
- data/test/models/timeoutable_test.rb +42 -0
- data/test/models/token_authenticatable_test.rb +49 -0
- data/test/models/trackable_test.rb +5 -0
- data/test/models/validatable_test.rb +113 -0
- data/test/models_test.rb +109 -0
- data/test/omniauth/config_test.rb +57 -0
- data/test/omniauth/url_helpers_test.rb +58 -0
- data/test/orm/active_record.rb +9 -0
- data/test/orm/mongoid.rb +14 -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 +6 -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 +3 -0
- data/test/rails_app/app/mongoid/admin.rb +24 -0
- data/test/rails_app/app/mongoid/shim.rb +24 -0
- data/test/rails_app/app/mongoid/user.rb +45 -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 +197 -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 +87 -0
- data/test/rails_app/db/migrate/20100401102949_create_tables.rb +71 -0
- data/test/rails_app/db/schema.rb +52 -0
- data/test/rails_app/lib/shared_admin.rb +10 -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 +240 -0
- data/test/support/assertions.rb +27 -0
- data/test/support/helpers.rb +109 -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 +27 -0
- data/test/test_helpers_test.rb +134 -0
- metadata +295 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
Hello <%= @resource.email %>!
|
|
2
|
+
|
|
3
|
+
Someone has requested a link to change your password, and you can do this through the link below.
|
|
4
|
+
|
|
5
|
+
<%= link_to 'Change my password', edit_password_url(@resource, :reset_password_token => @resource.reset_password_token) %>
|
|
6
|
+
|
|
7
|
+
If you didn't request this, please ignore this email.
|
|
8
|
+
Your password won't change until you access the link above and create a new one.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Hello <%= @resource.email %>!
|
|
2
|
+
|
|
3
|
+
Your account has been locked due to an excessive amount of unsuccessful sign in attempts.
|
|
4
|
+
|
|
5
|
+
Click the link below to unlock your account:
|
|
6
|
+
|
|
7
|
+
<%= link_to 'Unlock my account', unlock_url(@resource, :unlock_token => @resource.unlock_token) %>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<h2>Resend confirmation instructions</h2>
|
|
2
|
+
|
|
3
|
+
<%= simple_form_for(resource, :as => resource_name, :url => confirmation_path(resource_name), :html => { :method => :post }) do |f| %>
|
|
4
|
+
<%= f.error_notification %>
|
|
5
|
+
|
|
6
|
+
<div class="inputs">
|
|
7
|
+
<%= f.input :email, :required => true %>
|
|
8
|
+
</div>
|
|
9
|
+
|
|
10
|
+
<div class="actions">
|
|
11
|
+
<%= f.button :submit, "Resend confirmation instructions" %>
|
|
12
|
+
</div>
|
|
13
|
+
<% end %>
|
|
14
|
+
|
|
15
|
+
<%= render :partial => "devise/shared/links" %>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
<h2>Change your password</h2>
|
|
2
|
+
|
|
3
|
+
<%= simple_form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :put }) do |f| %>
|
|
4
|
+
<%= f.error_notification %>
|
|
5
|
+
|
|
6
|
+
<%= f.input :reset_password_token, :as => :hidden %>
|
|
7
|
+
<%= f.full_error :reset_password_token %>
|
|
8
|
+
|
|
9
|
+
<div class="inputs">
|
|
10
|
+
<%= f.input :password, :label => "New password", :required => true %>
|
|
11
|
+
<%= f.input :password_confirmation, :label => "Confirm your new password", :required => true %>
|
|
12
|
+
</div>
|
|
13
|
+
|
|
14
|
+
<div class="actions">
|
|
15
|
+
<%= f.button :submit, "Change my password" %>
|
|
16
|
+
</div>
|
|
17
|
+
<% end %>
|
|
18
|
+
|
|
19
|
+
<%= render :partial => "devise/shared/links" %>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<h2>Forgot your password?</h2>
|
|
2
|
+
|
|
3
|
+
<%= simple_form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :post }) do |f| %>
|
|
4
|
+
<%= f.error_notification %>
|
|
5
|
+
|
|
6
|
+
<div class="inputs">
|
|
7
|
+
<%= f.input :email, :required => true %>
|
|
8
|
+
</div>
|
|
9
|
+
|
|
10
|
+
<div class="actions">
|
|
11
|
+
<%= f.button :submit, "Send me reset password instructions" %>
|
|
12
|
+
</div>
|
|
13
|
+
<% end %>
|
|
14
|
+
|
|
15
|
+
<%= render :partial => "devise/shared/links" %>
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
<h2>Edit <%= resource_name.to_s.humanize %></h2>
|
|
2
|
+
|
|
3
|
+
<%= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put }) do |f| %>
|
|
4
|
+
<%= f.error_notification %>
|
|
5
|
+
|
|
6
|
+
<div class="inputs">
|
|
7
|
+
<%= f.input :email, :required => true, :autofocus => true %>
|
|
8
|
+
<%= f.input :password, :hint => "leave it blank if you don't want to change it", :required => false %>
|
|
9
|
+
<%= f.input :password_confirmation, :required => false %>
|
|
10
|
+
<%= f.input :current_password, :hint => "we need your current password to confirm your changes", :required => true %>
|
|
11
|
+
</div>
|
|
12
|
+
|
|
13
|
+
<div class="actions">
|
|
14
|
+
<%= f.button :submit, "Update" %>
|
|
15
|
+
</div>
|
|
16
|
+
<% end %>
|
|
17
|
+
|
|
18
|
+
<h3>Cancel my account</h3>
|
|
19
|
+
|
|
20
|
+
<p>Unhappy? <%= link_to "Cancel my account", registration_path(resource_name), :confirm => "Are you sure?", :method => :delete %>.</p>
|
|
21
|
+
|
|
22
|
+
<%= link_to "Back", :back %>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
<h2>Sign up</h2>
|
|
2
|
+
|
|
3
|
+
<%= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
|
|
4
|
+
<%= f.error_notification %>
|
|
5
|
+
|
|
6
|
+
<div class="inputs">
|
|
7
|
+
<%= f.input :email, :required => true, :autofocus => true %>
|
|
8
|
+
<%= f.input :password, :required => true %>
|
|
9
|
+
<%= f.input :password_confirmation, :required => true %>
|
|
10
|
+
</div>
|
|
11
|
+
|
|
12
|
+
<div class="actions">
|
|
13
|
+
<%= f.button :submit, "Sign up" %>
|
|
14
|
+
</div>
|
|
15
|
+
<% end %>
|
|
16
|
+
|
|
17
|
+
<%= render :partial => "devise/shared/links" %>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<h2>Sign in</h2>
|
|
2
|
+
|
|
3
|
+
<%= simple_form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %>
|
|
4
|
+
<div class="inputs">
|
|
5
|
+
<%= f.input :email, :required => false, :autofocus => true %>
|
|
6
|
+
<%= f.input :password, :required => false %>
|
|
7
|
+
<%= f.input :remember_me, :as => :boolean if devise_mapping.rememberable? %>
|
|
8
|
+
</div>
|
|
9
|
+
|
|
10
|
+
<div class="actions">
|
|
11
|
+
<%= f.button :submit, "Sign in" %>
|
|
12
|
+
</div>
|
|
13
|
+
<% end %>
|
|
14
|
+
|
|
15
|
+
<%= render :partial => "devise/shared/links" %>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<h2>Resend unlock instructions</h2>
|
|
2
|
+
|
|
3
|
+
<%= simple_form_for(resource, :as => resource_name, :url => unlock_path(resource_name), :html => { :method => :post }) do |f| %>
|
|
4
|
+
<%= f.error_notification %>
|
|
5
|
+
|
|
6
|
+
<div class="inputs">
|
|
7
|
+
<%= f.input :email, :required => true %>
|
|
8
|
+
</div>
|
|
9
|
+
|
|
10
|
+
<div class="actions">
|
|
11
|
+
<%= f.button :submit, "Resend unlock instructions" %>
|
|
12
|
+
</div>
|
|
13
|
+
<% end %>
|
|
14
|
+
|
|
15
|
+
<%= render :partial => "devise/shared/links" %>
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
require 'ostruct'
|
|
3
|
+
|
|
4
|
+
class ControllerAuthenticatableTest < ActionController::TestCase
|
|
5
|
+
tests ApplicationController
|
|
6
|
+
|
|
7
|
+
def setup
|
|
8
|
+
@mock_warden = OpenStruct.new
|
|
9
|
+
@controller.request.env['warden'] = @mock_warden
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
test 'provide access to warden instance' do
|
|
13
|
+
assert_equal @mock_warden, @controller.warden
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
test 'proxy signed_in?(scope) to authenticate?' do
|
|
17
|
+
@mock_warden.expects(:authenticate?).with(:scope => :my_scope)
|
|
18
|
+
@controller.signed_in?(:my_scope)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
test 'proxy signed_in?(nil) to authenticate?' do
|
|
22
|
+
Devise.mappings.keys.each do |scope| # :user, :admin, :manager
|
|
23
|
+
@mock_warden.expects(:authenticate?).with(:scope => scope)
|
|
24
|
+
end
|
|
25
|
+
@controller.signed_in?
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
test 'proxy current_user to authenticate with user scope' do
|
|
29
|
+
@mock_warden.expects(:authenticate).with(:scope => :user)
|
|
30
|
+
@controller.current_user
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
test 'proxy current_admin to authenticate with admin scope' do
|
|
34
|
+
@mock_warden.expects(:authenticate).with(:scope => :admin)
|
|
35
|
+
@controller.current_admin
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
test 'proxy current_publisher_account to authenticate with namespaced publisher account scope' do
|
|
39
|
+
@mock_warden.expects(:authenticate).with(:scope => :publisher_account)
|
|
40
|
+
@controller.current_publisher_account
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
test 'proxy authenticate_user! to authenticate with user scope' do
|
|
44
|
+
@mock_warden.expects(:authenticate!).with(:scope => :user)
|
|
45
|
+
@controller.authenticate_user!
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
test 'proxy authenticate_user! options to authenticate with user scope' do
|
|
49
|
+
@mock_warden.expects(:authenticate!).with(:scope => :user, :recall => "foo")
|
|
50
|
+
@controller.authenticate_user!(:recall => "foo")
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
test 'proxy authenticate_admin! to authenticate with admin scope' do
|
|
54
|
+
@mock_warden.expects(:authenticate!).with(:scope => :admin)
|
|
55
|
+
@controller.authenticate_admin!
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
test 'proxy authenticate_publisher_account! to authenticate with namespaced publisher account scope' do
|
|
59
|
+
@mock_warden.expects(:authenticate!).with(:scope => :publisher_account)
|
|
60
|
+
@controller.authenticate_publisher_account!
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
test 'proxy user_signed_in? to authenticate with user scope' do
|
|
64
|
+
@mock_warden.expects(:authenticate).with(:scope => :user).returns("user")
|
|
65
|
+
assert @controller.user_signed_in?
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
test 'proxy admin_signed_in? to authenticatewith admin scope' do
|
|
69
|
+
@mock_warden.expects(:authenticate).with(:scope => :admin)
|
|
70
|
+
assert_not @controller.admin_signed_in?
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
test 'proxy publisher_account_signed_in? to authenticate with namespaced publisher account scope' do
|
|
74
|
+
@mock_warden.expects(:authenticate).with(:scope => :publisher_account)
|
|
75
|
+
@controller.publisher_account_signed_in?
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
test 'proxy user_session to session scope in warden' do
|
|
79
|
+
@mock_warden.expects(:authenticate).with(:scope => :user).returns(true)
|
|
80
|
+
@mock_warden.expects(:session).with(:user).returns({})
|
|
81
|
+
@controller.user_session
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
test 'proxy admin_session to session scope in warden' do
|
|
85
|
+
@mock_warden.expects(:authenticate).with(:scope => :admin).returns(true)
|
|
86
|
+
@mock_warden.expects(:session).with(:admin).returns({})
|
|
87
|
+
@controller.admin_session
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
test 'proxy publisher_account_session from namespaced scope to session scope in warden' do
|
|
91
|
+
@mock_warden.expects(:authenticate).with(:scope => :publisher_account).returns(true)
|
|
92
|
+
@mock_warden.expects(:session).with(:publisher_account).returns({})
|
|
93
|
+
@controller.publisher_account_session
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
test 'sign in proxy to set_user on warden' do
|
|
97
|
+
user = User.new
|
|
98
|
+
@mock_warden.expects(:user).returns(nil)
|
|
99
|
+
@mock_warden.expects(:set_user).with(user, :scope => :user).returns(true)
|
|
100
|
+
@controller.sign_in(:user, user)
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
test 'sign in accepts a resource as argument' do
|
|
104
|
+
user = User.new
|
|
105
|
+
@mock_warden.expects(:user).returns(nil)
|
|
106
|
+
@mock_warden.expects(:set_user).with(user, :scope => :user).returns(true)
|
|
107
|
+
@controller.sign_in(user)
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
test 'does not sign in again if the user is already in' do
|
|
111
|
+
user = User.new
|
|
112
|
+
@mock_warden.expects(:user).returns(user)
|
|
113
|
+
@mock_warden.expects(:set_user).never
|
|
114
|
+
assert @controller.sign_in(user)
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
test 'sign in again when the user is already in only if force is given' do
|
|
118
|
+
user = User.new
|
|
119
|
+
@mock_warden.expects(:user).returns(user)
|
|
120
|
+
@mock_warden.expects(:set_user).with(user, :scope => :user).returns(true)
|
|
121
|
+
@controller.sign_in(user, :force => true)
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
test 'sign in accepts bypass as option' do
|
|
125
|
+
user = User.new
|
|
126
|
+
@mock_warden.expects(:session_serializer).returns(serializer = mock())
|
|
127
|
+
serializer.expects(:store).with(user, :user)
|
|
128
|
+
@controller.sign_in(user, :bypass => true)
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
test 'sign out clears up any signed in user from all scopes' do
|
|
132
|
+
user = User.new
|
|
133
|
+
@mock_warden.expects(:user).times(Devise.mappings.size)
|
|
134
|
+
@mock_warden.expects(:logout).with().returns(true)
|
|
135
|
+
@controller.instance_variable_set(:@current_user, user)
|
|
136
|
+
@controller.instance_variable_set(:@current_admin, user)
|
|
137
|
+
@controller.sign_out
|
|
138
|
+
assert_equal nil, @controller.instance_variable_get(:@current_user)
|
|
139
|
+
assert_equal nil, @controller.instance_variable_get(:@current_admin)
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
test 'sign out clears up any signed in user by scope' do
|
|
143
|
+
user = User.new
|
|
144
|
+
@mock_warden.expects(:user).with(:user).returns(user)
|
|
145
|
+
@mock_warden.expects(:logout).with(:user).returns(true)
|
|
146
|
+
@controller.instance_variable_set(:@current_user, user)
|
|
147
|
+
@controller.sign_out(:user)
|
|
148
|
+
assert_equal nil, @controller.instance_variable_get(:@current_user)
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
test 'sign out proxy to logout on warden' do
|
|
152
|
+
@mock_warden.expects(:user).with(:user).returns(true)
|
|
153
|
+
@mock_warden.expects(:logout).with(:user).returns(true)
|
|
154
|
+
@controller.sign_out(:user)
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
test 'sign out accepts a resource as argument' do
|
|
158
|
+
@mock_warden.expects(:user).with(:user).returns(true)
|
|
159
|
+
@mock_warden.expects(:logout).with(:user).returns(true)
|
|
160
|
+
@controller.sign_out(User.new)
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
test 'sign out without args proxy to sign out all scopes' do
|
|
164
|
+
@mock_warden.expects(:user).times(Devise.mappings.size)
|
|
165
|
+
@mock_warden.expects(:logout).with().returns(true)
|
|
166
|
+
@controller.sign_out
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
test 'sign out everybody proxy to logout on warden' do
|
|
170
|
+
@mock_warden.expects(:user).times(Devise.mappings.size)
|
|
171
|
+
@mock_warden.expects(:logout).with().returns(true)
|
|
172
|
+
@controller.sign_out_all_scopes
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
test 'stored location for returns the location for a given scope' do
|
|
176
|
+
assert_nil @controller.stored_location_for(:user)
|
|
177
|
+
@controller.session[:"user_return_to"] = "/foo.bar"
|
|
178
|
+
assert_equal "/foo.bar", @controller.stored_location_for(:user)
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
test 'stored location for accepts a resource as argument' do
|
|
182
|
+
assert_nil @controller.stored_location_for(:user)
|
|
183
|
+
@controller.session[:"user_return_to"] = "/foo.bar"
|
|
184
|
+
assert_equal "/foo.bar", @controller.stored_location_for(User.new)
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
test 'stored location cleans information after reading' do
|
|
188
|
+
@controller.session[:"user_return_to"] = "/foo.bar"
|
|
189
|
+
assert_equal "/foo.bar", @controller.stored_location_for(:user)
|
|
190
|
+
assert_nil @controller.session[:"user_return_to"]
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
test 'after sign in path defaults to root path if none by was specified for the given scope' do
|
|
194
|
+
assert_equal root_path, @controller.after_sign_in_path_for(:user)
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
test 'after sign in path defaults to the scoped root path' do
|
|
198
|
+
assert_equal admin_root_path, @controller.after_sign_in_path_for(:admin)
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
test 'after sign out path defaults to the root path' do
|
|
202
|
+
assert_equal root_path, @controller.after_sign_out_path_for(:admin)
|
|
203
|
+
assert_equal root_path, @controller.after_sign_out_path_for(:user)
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
test 'sign in and redirect uses the stored location' do
|
|
207
|
+
user = User.new
|
|
208
|
+
@controller.session[:"user_return_to"] = "/foo.bar"
|
|
209
|
+
@mock_warden.expects(:user).with(:user).returns(nil)
|
|
210
|
+
@mock_warden.expects(:set_user).with(user, :scope => :user).returns(true)
|
|
211
|
+
@controller.expects(:redirect_to).with("/foo.bar")
|
|
212
|
+
@controller.sign_in_and_redirect(user)
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
test 'sign in and redirect uses the configured after sign in path' do
|
|
216
|
+
admin = Admin.new
|
|
217
|
+
@mock_warden.expects(:user).with(:admin).returns(nil)
|
|
218
|
+
@mock_warden.expects(:set_user).with(admin, :scope => :admin).returns(true)
|
|
219
|
+
@controller.expects(:redirect_to).with(admin_root_path)
|
|
220
|
+
@controller.sign_in_and_redirect(admin)
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
test 'sign in and redirect does not sign in again if user is already signed' do
|
|
224
|
+
admin = Admin.new
|
|
225
|
+
@mock_warden.expects(:user).with(:admin).returns(admin)
|
|
226
|
+
@mock_warden.expects(:set_user).never
|
|
227
|
+
@controller.expects(:redirect_to).with(admin_root_path)
|
|
228
|
+
@controller.sign_in_and_redirect(admin)
|
|
229
|
+
end
|
|
230
|
+
|
|
231
|
+
test 'sign out and redirect uses the configured after sign out path when signing out only the current scope' do
|
|
232
|
+
swap Devise, :sign_out_all_scopes => false do
|
|
233
|
+
@mock_warden.expects(:user).with(:admin).returns(true)
|
|
234
|
+
@mock_warden.expects(:logout).with(:admin).returns(true)
|
|
235
|
+
@controller.expects(:redirect_to).with(admin_root_path)
|
|
236
|
+
@controller.instance_eval "def after_sign_out_path_for(resource); admin_root_path; end"
|
|
237
|
+
@controller.sign_out_and_redirect(:admin)
|
|
238
|
+
end
|
|
239
|
+
end
|
|
240
|
+
|
|
241
|
+
test 'sign out and redirect uses the configured after sign out path when signing out all scopes' do
|
|
242
|
+
swap Devise, :sign_out_all_scopes => true do
|
|
243
|
+
@mock_warden.expects(:user).times(Devise.mappings.size)
|
|
244
|
+
@mock_warden.expects(:logout).with().returns(true)
|
|
245
|
+
@controller.expects(:redirect_to).with(admin_root_path)
|
|
246
|
+
@controller.instance_eval "def after_sign_out_path_for(resource); admin_root_path; end"
|
|
247
|
+
@controller.sign_out_and_redirect(:admin)
|
|
248
|
+
end
|
|
249
|
+
end
|
|
250
|
+
|
|
251
|
+
test 'is not a devise controller' do
|
|
252
|
+
assert_not @controller.devise_controller?
|
|
253
|
+
end
|
|
254
|
+
end
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class MyController < ApplicationController
|
|
4
|
+
include Devise::Controllers::InternalHelpers
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
class HelpersTest < ActionController::TestCase
|
|
8
|
+
tests MyController
|
|
9
|
+
|
|
10
|
+
def setup
|
|
11
|
+
@mock_warden = OpenStruct.new
|
|
12
|
+
@controller.request.env['warden'] = @mock_warden
|
|
13
|
+
@controller.request.env['devise.mapping'] = Devise.mappings[:user]
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
test 'get resource name from env' do
|
|
17
|
+
assert_equal :user, @controller.resource_name
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
test 'get resource class from env' do
|
|
21
|
+
assert_equal User, @controller.resource_class
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
test 'get resource instance variable from env' do
|
|
25
|
+
@controller.instance_variable_set(:@user, user = User.new)
|
|
26
|
+
assert_equal user, @controller.resource
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
test 'set resource instance variable from env' do
|
|
30
|
+
user = @controller.send(:resource_class).new
|
|
31
|
+
@controller.send(:resource=, user)
|
|
32
|
+
|
|
33
|
+
assert_equal user, @controller.send(:resource)
|
|
34
|
+
assert_equal user, @controller.instance_variable_get(:@user)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
test 'resources methods are not controller actions' do
|
|
38
|
+
assert @controller.class.action_methods.empty?
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
test 'require no authentication tests current mapping' do
|
|
42
|
+
@mock_warden.expects(:authenticate?).with(:rememberable, :token_authenticatable, :scope => :user).returns(true)
|
|
43
|
+
@mock_warden.expects(:user).with(:user).returns(User.new)
|
|
44
|
+
@controller.expects(:redirect_to).with(root_path)
|
|
45
|
+
@controller.send :require_no_authentication
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
test 'require no authentication only checks if already authenticated if no inputs strategies are available' do
|
|
49
|
+
Devise.mappings[:user].expects(:no_input_strategies).returns([])
|
|
50
|
+
@mock_warden.expects(:authenticate?).never
|
|
51
|
+
@mock_warden.expects(:authenticated?).with(:user).once.returns(true)
|
|
52
|
+
@mock_warden.expects(:user).with(:user).returns(User.new)
|
|
53
|
+
@controller.expects(:redirect_to).with(root_path)
|
|
54
|
+
@controller.send :require_no_authentication
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
test 'require no authentication sets a flash message' do
|
|
58
|
+
@mock_warden.expects(:authenticate?).with(:rememberable, :token_authenticatable, :scope => :user).returns(true)
|
|
59
|
+
@mock_warden.expects(:user).with(:user).returns(User.new)
|
|
60
|
+
@controller.expects(:redirect_to).with(root_path)
|
|
61
|
+
@controller.send :require_no_authentication
|
|
62
|
+
assert flash[:alert] == I18n.t("devise.failure.already_authenticated")
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
test 'signed in resource returns signed in resource for current scope' do
|
|
66
|
+
@mock_warden.expects(:authenticate).with(:scope => :user).returns(User.new)
|
|
67
|
+
assert_kind_of User, @controller.signed_in_resource
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
test 'is a devise controller' do
|
|
71
|
+
assert @controller.devise_controller?
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
test 'does not issue blank flash messages' do
|
|
75
|
+
MyController.send(:public, :set_flash_message)
|
|
76
|
+
I18n.stubs(:t).returns(' ')
|
|
77
|
+
@controller.set_flash_message :notice, :send_instructions
|
|
78
|
+
assert flash[:notice].nil?
|
|
79
|
+
MyController.send(:protected, :set_flash_message)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
test 'issues non-blank flash messages normally' do
|
|
83
|
+
MyController.send(:public, :set_flash_message)
|
|
84
|
+
I18n.stubs(:t).returns('non-blank')
|
|
85
|
+
@controller.set_flash_message :notice, :send_instructions
|
|
86
|
+
assert flash[:notice] == 'non-blank'
|
|
87
|
+
MyController.send(:protected, :set_flash_message)
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
test 'navigational_formats not returning a wild card' do
|
|
91
|
+
MyController.send(:public, :navigational_formats)
|
|
92
|
+
Devise.navigational_formats = [:"*/*", :html]
|
|
93
|
+
assert_not @controller.navigational_formats.include?(:"*/*")
|
|
94
|
+
MyController.send(:protected, :navigational_formats)
|
|
95
|
+
end
|
|
96
|
+
end
|