cloudfoundry-devise 1.5.2
Sign up to get free protection for your applications and to get access to all the features.
- 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,27 @@
|
|
1
|
+
require 'active_support/test_case'
|
2
|
+
|
3
|
+
class ActiveSupport::TestCase
|
4
|
+
def assert_not(assertion)
|
5
|
+
assert !assertion
|
6
|
+
end
|
7
|
+
|
8
|
+
def assert_blank(assertion)
|
9
|
+
assert assertion.blank?
|
10
|
+
end
|
11
|
+
|
12
|
+
def assert_not_blank(assertion)
|
13
|
+
assert !assertion.blank?
|
14
|
+
end
|
15
|
+
alias :assert_present :assert_not_blank
|
16
|
+
|
17
|
+
def assert_email_sent(address = nil, &block)
|
18
|
+
assert_difference('ActionMailer::Base.deliveries.size') { yield }
|
19
|
+
if address.present?
|
20
|
+
assert_equal address, ActionMailer::Base.deliveries.last['to'].to_s
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def assert_email_not_sent(&block)
|
25
|
+
assert_no_difference('ActionMailer::Base.deliveries.size') { yield }
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
require 'active_support/test_case'
|
2
|
+
|
3
|
+
class ActiveSupport::TestCase
|
4
|
+
VALID_AUTHENTICATION_TOKEN = 'AbCdEfGhIjKlMnOpQrSt'.freeze
|
5
|
+
|
6
|
+
def setup_mailer
|
7
|
+
ActionMailer::Base.deliveries = []
|
8
|
+
end
|
9
|
+
|
10
|
+
def store_translations(locale, translations, &block)
|
11
|
+
begin
|
12
|
+
I18n.backend.store_translations(locale, translations)
|
13
|
+
yield
|
14
|
+
ensure
|
15
|
+
I18n.reload!
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def generate_unique_email
|
20
|
+
@@email_count ||= 0
|
21
|
+
@@email_count += 1
|
22
|
+
"test#{@@email_count}@example.com"
|
23
|
+
end
|
24
|
+
|
25
|
+
def valid_attributes(attributes={})
|
26
|
+
{ :username => "usertest",
|
27
|
+
:email => generate_unique_email,
|
28
|
+
:password => '123456',
|
29
|
+
:password_confirmation => '123456' }.update(attributes)
|
30
|
+
end
|
31
|
+
|
32
|
+
def new_user(attributes={})
|
33
|
+
User.new(valid_attributes(attributes))
|
34
|
+
end
|
35
|
+
|
36
|
+
def create_user(attributes={})
|
37
|
+
User.create!(valid_attributes(attributes))
|
38
|
+
end
|
39
|
+
|
40
|
+
def create_admin(attributes={})
|
41
|
+
valid_attributes = valid_attributes(attributes)
|
42
|
+
valid_attributes.delete(:username)
|
43
|
+
Admin.create!(valid_attributes)
|
44
|
+
end
|
45
|
+
|
46
|
+
# Execute the block setting the given values and restoring old values after
|
47
|
+
# the block is executed.
|
48
|
+
def swap(object, new_values)
|
49
|
+
old_values = {}
|
50
|
+
new_values.each do |key, value|
|
51
|
+
old_values[key] = object.send key
|
52
|
+
object.send :"#{key}=", value
|
53
|
+
end
|
54
|
+
clear_cached_variables(new_values)
|
55
|
+
yield
|
56
|
+
ensure
|
57
|
+
clear_cached_variables(new_values)
|
58
|
+
old_values.each do |key, value|
|
59
|
+
object.send :"#{key}=", value
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def clear_cached_variables(options)
|
64
|
+
if options.key?(:case_insensitive_keys) || options.key?(:strip_whitespace_keys)
|
65
|
+
Devise.mappings.each do |_, mapping|
|
66
|
+
mapping.to.instance_variable_set(:@devise_param_filter, nil)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def with_rails_version(constants)
|
72
|
+
saved_constants = {}
|
73
|
+
|
74
|
+
constants.each do |constant, val|
|
75
|
+
saved_constants[constant] = ::Rails::VERSION.const_get constant
|
76
|
+
Kernel::silence_warnings { ::Rails::VERSION.const_set(constant, val) }
|
77
|
+
end
|
78
|
+
|
79
|
+
begin
|
80
|
+
yield
|
81
|
+
ensure
|
82
|
+
constants.each do |constant, val|
|
83
|
+
Kernel::silence_warnings { ::Rails::VERSION.const_set(constant, saved_constants[constant]) }
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
# TODO: Get rid of this in favor of a real model with unconfirmed
|
89
|
+
def add_unconfirmed_email_column
|
90
|
+
if DEVISE_ORM == :active_record
|
91
|
+
ActiveRecord::Base.connection.add_column(:users, :unconfirmed_email, :string)
|
92
|
+
User.reset_column_information
|
93
|
+
elsif DEVISE_ORM == :mongoid
|
94
|
+
User.field(:unconfirmed_email, :type => String)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
# TODO: Get rid of this in favor of a real model with unconfirmed
|
99
|
+
def remove_unconfirmed_email_column
|
100
|
+
if DEVISE_ORM == :active_record
|
101
|
+
ActiveRecord::Base.connection.remove_column(:users, :unconfirmed_email)
|
102
|
+
User.reset_column_information
|
103
|
+
elsif DEVISE_ORM == :mongoid
|
104
|
+
User.fields.delete(:unconfirmed_email)
|
105
|
+
User.send(:undefine_attribute_methods)
|
106
|
+
User.send(:define_attribute_methods, User.fields.keys)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'action_dispatch/testing/integration'
|
2
|
+
|
3
|
+
class ActionDispatch::IntegrationTest
|
4
|
+
def warden
|
5
|
+
request.env['warden']
|
6
|
+
end
|
7
|
+
|
8
|
+
def create_user(options={})
|
9
|
+
@user ||= begin
|
10
|
+
user = User.create!(
|
11
|
+
:username => 'usertest',
|
12
|
+
:email => options[:email] || 'user@test.com',
|
13
|
+
:password => options[:password] || '123456',
|
14
|
+
:password_confirmation => options[:password] || '123456',
|
15
|
+
:created_at => Time.now.utc
|
16
|
+
)
|
17
|
+
user.confirm! unless options[:confirm] == false
|
18
|
+
user.lock_access! if options[:locked] == true
|
19
|
+
user
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def create_admin(options={})
|
24
|
+
@admin ||= begin
|
25
|
+
admin = Admin.create!(
|
26
|
+
:email => 'admin@test.com', :password => '123456', :password_confirmation => '123456'
|
27
|
+
)
|
28
|
+
admin
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def sign_in_as_user(options={}, &block)
|
33
|
+
user = create_user(options)
|
34
|
+
visit_with_option options[:visit], new_user_session_path
|
35
|
+
fill_in 'email', :with => options[:email] || 'user@test.com'
|
36
|
+
fill_in 'password', :with => options[:password] || '123456'
|
37
|
+
check 'remember me' if options[:remember_me] == true
|
38
|
+
yield if block_given?
|
39
|
+
click_button 'Sign In'
|
40
|
+
user
|
41
|
+
end
|
42
|
+
|
43
|
+
def sign_in_as_admin(options={}, &block)
|
44
|
+
admin = create_admin(options)
|
45
|
+
visit_with_option options[:visit], new_admin_session_path
|
46
|
+
fill_in 'email', :with => 'admin@test.com'
|
47
|
+
fill_in 'password', :with => '123456'
|
48
|
+
yield if block_given?
|
49
|
+
click_button 'Sign In'
|
50
|
+
admin
|
51
|
+
end
|
52
|
+
|
53
|
+
# Fix assert_redirect_to in integration sessions because they don't take into
|
54
|
+
# account Middleware redirects.
|
55
|
+
#
|
56
|
+
def assert_redirected_to(url)
|
57
|
+
assert [301, 302].include?(@integration_session.status),
|
58
|
+
"Expected status to be 301 or 302, got #{@integration_session.status}"
|
59
|
+
|
60
|
+
assert_url url, @integration_session.headers["Location"]
|
61
|
+
end
|
62
|
+
|
63
|
+
def assert_current_url(expected)
|
64
|
+
assert_url expected, current_url
|
65
|
+
end
|
66
|
+
|
67
|
+
def assert_url(expected, actual)
|
68
|
+
assert_equal prepend_host(expected), prepend_host(actual)
|
69
|
+
end
|
70
|
+
|
71
|
+
protected
|
72
|
+
|
73
|
+
def visit_with_option(given, default)
|
74
|
+
case given
|
75
|
+
when String
|
76
|
+
visit given
|
77
|
+
when FalseClass
|
78
|
+
# Do nothing
|
79
|
+
else
|
80
|
+
visit default
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def prepend_host(url)
|
85
|
+
url = "http://#{request.host}#{url}" if url[0] == ?/
|
86
|
+
url
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'webrat/core/elements/form'
|
2
|
+
require 'action_dispatch/testing/integration'
|
3
|
+
|
4
|
+
module Webrat
|
5
|
+
Form.class_eval do
|
6
|
+
def self.parse_rails_request_params(params)
|
7
|
+
Rack::Utils.parse_nested_query(params)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
module Logging
|
12
|
+
# Avoid RAILS_DEFAULT_LOGGER deprecation warning
|
13
|
+
def logger # :nodoc:
|
14
|
+
::Rails.logger
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
module ActionDispatch #:nodoc:
|
20
|
+
IntegrationTest.class_eval do
|
21
|
+
include Webrat::Methods
|
22
|
+
include Webrat::Matchers
|
23
|
+
end
|
24
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
ENV["RAILS_ENV"] = "test"
|
2
|
+
DEVISE_ORM = (ENV["DEVISE_ORM"] || :active_record).to_sym
|
3
|
+
|
4
|
+
$:.unshift File.dirname(__FILE__)
|
5
|
+
puts "\n==> Devise.orm = #{DEVISE_ORM.inspect}"
|
6
|
+
|
7
|
+
require "rails_app/config/environment"
|
8
|
+
require "rails/test_help"
|
9
|
+
require "orm/#{DEVISE_ORM}"
|
10
|
+
|
11
|
+
I18n.load_path << File.expand_path("../support/locale/en.yml", __FILE__)
|
12
|
+
|
13
|
+
require 'mocha'
|
14
|
+
require 'webrat'
|
15
|
+
Webrat.configure do |config|
|
16
|
+
config.mode = :rails
|
17
|
+
config.open_error_files = false
|
18
|
+
end
|
19
|
+
|
20
|
+
# Add support to load paths so we can overwrite broken webrat setup
|
21
|
+
$:.unshift File.expand_path('../support', __FILE__)
|
22
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
23
|
+
|
24
|
+
# For generators
|
25
|
+
require "rails/generators/test_case"
|
26
|
+
require "generators/devise/install_generator"
|
27
|
+
require "generators/devise/views_generator"
|
@@ -0,0 +1,134 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TestHelpersTest < ActionController::TestCase
|
4
|
+
tests UsersController
|
5
|
+
include Devise::TestHelpers
|
6
|
+
|
7
|
+
class CustomFailureApp < Devise::FailureApp
|
8
|
+
def redirect
|
9
|
+
self.status = 306
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
test "redirects if attempting to access a page unauthenticated" do
|
14
|
+
get :index
|
15
|
+
assert_redirected_to new_user_session_path
|
16
|
+
assert_equal "You need to sign in or sign up before continuing.", flash[:alert]
|
17
|
+
end
|
18
|
+
|
19
|
+
test "redirects if attempting to access a page with an unconfirmed account" do
|
20
|
+
swap Devise, :confirm_within => 0 do
|
21
|
+
user = create_user
|
22
|
+
assert !user.active_for_authentication?
|
23
|
+
|
24
|
+
sign_in user
|
25
|
+
get :index
|
26
|
+
assert_redirected_to new_user_session_path
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
test "returns nil if accessing current_user with an unconfirmed account" do
|
31
|
+
swap Devise, :confirm_within => 0 do
|
32
|
+
user = create_user
|
33
|
+
assert !user.active_for_authentication?
|
34
|
+
|
35
|
+
sign_in user
|
36
|
+
get :accept, :id => user
|
37
|
+
assert_nil assigns(:current_user)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
test "does not redirect with valid user" do
|
42
|
+
user = create_user
|
43
|
+
user.confirm!
|
44
|
+
|
45
|
+
sign_in user
|
46
|
+
get :index
|
47
|
+
assert_response :success
|
48
|
+
end
|
49
|
+
|
50
|
+
test "redirects if valid user signed out" do
|
51
|
+
user = create_user
|
52
|
+
user.confirm!
|
53
|
+
|
54
|
+
sign_in user
|
55
|
+
get :index
|
56
|
+
|
57
|
+
sign_out user
|
58
|
+
get :index
|
59
|
+
assert_redirected_to new_user_session_path
|
60
|
+
end
|
61
|
+
|
62
|
+
test "respects custom failure app" do
|
63
|
+
begin
|
64
|
+
Devise.warden_config.failure_app = CustomFailureApp
|
65
|
+
get :index
|
66
|
+
assert_response 306
|
67
|
+
ensure
|
68
|
+
Devise.warden_config.failure_app = Devise::FailureApp
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
test "defined Warden after_authentication callback should not be called when sign_in is called" do
|
73
|
+
begin
|
74
|
+
Warden::Manager.after_authentication do |user, auth, opts|
|
75
|
+
flunk "callback was called while it should not"
|
76
|
+
end
|
77
|
+
|
78
|
+
user = create_user
|
79
|
+
user.confirm!
|
80
|
+
sign_in user
|
81
|
+
ensure
|
82
|
+
Warden::Manager._after_set_user.pop
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
test "defined Warden before_logout callback should not be called when sign_out is called" do
|
87
|
+
begin
|
88
|
+
Warden::Manager.before_logout do |user, auth, opts|
|
89
|
+
flunk "callback was called while it should not"
|
90
|
+
end
|
91
|
+
user = create_user
|
92
|
+
user.confirm!
|
93
|
+
|
94
|
+
sign_in user
|
95
|
+
sign_out user
|
96
|
+
ensure
|
97
|
+
Warden::Manager._before_logout.pop
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
test "before_failure call should work" do
|
102
|
+
begin
|
103
|
+
executed = false
|
104
|
+
Warden::Manager.before_failure do |env,opts|
|
105
|
+
executed = true
|
106
|
+
end
|
107
|
+
|
108
|
+
user = create_user
|
109
|
+
sign_in user
|
110
|
+
|
111
|
+
get :index
|
112
|
+
assert executed
|
113
|
+
ensure
|
114
|
+
Warden::Manager._before_failure.pop
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
test "allows to sign in with different users" do
|
119
|
+
first_user = create_user
|
120
|
+
first_user.confirm!
|
121
|
+
|
122
|
+
sign_in first_user
|
123
|
+
get :index
|
124
|
+
assert_match /User ##{first_user.id}/, @response.body
|
125
|
+
sign_out first_user
|
126
|
+
|
127
|
+
second_user = create_user
|
128
|
+
second_user.confirm!
|
129
|
+
|
130
|
+
sign_in second_user
|
131
|
+
get :index
|
132
|
+
assert_match /User ##{second_user.id}/, @response.body
|
133
|
+
end
|
134
|
+
end
|
metadata
ADDED
@@ -0,0 +1,295 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cloudfoundry-devise
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 1.5.2
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jose Valim
|
9
|
+
- Carlos Antonio
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
|
14
|
+
date: 2011-12-07 00:00:00 Z
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: warden
|
18
|
+
prerelease: false
|
19
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
|
+
none: false
|
21
|
+
requirements:
|
22
|
+
- - ~>
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: "1.1"
|
25
|
+
type: :runtime
|
26
|
+
version_requirements: *id001
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: orm_adapter
|
29
|
+
prerelease: false
|
30
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
31
|
+
none: false
|
32
|
+
requirements:
|
33
|
+
- - ~>
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: 0.0.3
|
36
|
+
type: :runtime
|
37
|
+
version_requirements: *id002
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: bcrypt-ruby
|
40
|
+
prerelease: false
|
41
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ~>
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: "3.0"
|
47
|
+
type: :runtime
|
48
|
+
version_requirements: *id003
|
49
|
+
description: Flexible authentication solution for Rails with Warden
|
50
|
+
email: contact@plataformatec.com.br
|
51
|
+
executables: []
|
52
|
+
|
53
|
+
extensions: []
|
54
|
+
|
55
|
+
extra_rdoc_files: []
|
56
|
+
|
57
|
+
files:
|
58
|
+
- .gitignore
|
59
|
+
- .travis.yml
|
60
|
+
- CHANGELOG.rdoc
|
61
|
+
- Gemfile
|
62
|
+
- MIT-LICENSE
|
63
|
+
- README.rdoc
|
64
|
+
- Rakefile
|
65
|
+
- app/controllers/devise/confirmations_controller.rb
|
66
|
+
- app/controllers/devise/omniauth_callbacks_controller.rb
|
67
|
+
- app/controllers/devise/passwords_controller.rb
|
68
|
+
- app/controllers/devise/registrations_controller.rb
|
69
|
+
- app/controllers/devise/sessions_controller.rb
|
70
|
+
- app/controllers/devise/unlocks_controller.rb
|
71
|
+
- app/helpers/devise_helper.rb
|
72
|
+
- app/mailers/devise/mailer.rb
|
73
|
+
- app/views/devise/confirmations/new.html.erb
|
74
|
+
- app/views/devise/mailer/confirmation_instructions.html.erb
|
75
|
+
- app/views/devise/mailer/reset_password_instructions.html.erb
|
76
|
+
- app/views/devise/mailer/unlock_instructions.html.erb
|
77
|
+
- app/views/devise/passwords/edit.html.erb
|
78
|
+
- app/views/devise/passwords/new.html.erb
|
79
|
+
- app/views/devise/registrations/edit.html.erb
|
80
|
+
- app/views/devise/registrations/new.html.erb
|
81
|
+
- app/views/devise/sessions/new.html.erb
|
82
|
+
- app/views/devise/shared/_links.erb
|
83
|
+
- app/views/devise/unlocks/new.html.erb
|
84
|
+
- cloudfoundry-devise.gemspec
|
85
|
+
- config/locales/en.yml
|
86
|
+
- lib/devise.rb
|
87
|
+
- lib/devise/controllers/helpers.rb
|
88
|
+
- lib/devise/controllers/internal_helpers.rb
|
89
|
+
- lib/devise/controllers/rememberable.rb
|
90
|
+
- lib/devise/controllers/scoped_views.rb
|
91
|
+
- lib/devise/controllers/shared_helpers.rb
|
92
|
+
- lib/devise/controllers/url_helpers.rb
|
93
|
+
- lib/devise/delegator.rb
|
94
|
+
- lib/devise/encryptors/authlogic_sha512.rb
|
95
|
+
- lib/devise/encryptors/base.rb
|
96
|
+
- lib/devise/encryptors/clearance_sha1.rb
|
97
|
+
- lib/devise/encryptors/restful_authentication_sha1.rb
|
98
|
+
- lib/devise/encryptors/sha1.rb
|
99
|
+
- lib/devise/encryptors/sha512.rb
|
100
|
+
- lib/devise/failure_app.rb
|
101
|
+
- lib/devise/hooks/activatable.rb
|
102
|
+
- lib/devise/hooks/forgetable.rb
|
103
|
+
- lib/devise/hooks/rememberable.rb
|
104
|
+
- lib/devise/hooks/timeoutable.rb
|
105
|
+
- lib/devise/hooks/trackable.rb
|
106
|
+
- lib/devise/mailers/helpers.rb
|
107
|
+
- lib/devise/mapping.rb
|
108
|
+
- lib/devise/models.rb
|
109
|
+
- lib/devise/models/authenticatable.rb
|
110
|
+
- lib/devise/models/confirmable.rb
|
111
|
+
- lib/devise/models/database_authenticatable.rb
|
112
|
+
- lib/devise/models/encryptable.rb
|
113
|
+
- lib/devise/models/lockable.rb
|
114
|
+
- lib/devise/models/omniauthable.rb
|
115
|
+
- lib/devise/models/recoverable.rb
|
116
|
+
- lib/devise/models/registerable.rb
|
117
|
+
- lib/devise/models/rememberable.rb
|
118
|
+
- lib/devise/models/serializable.rb
|
119
|
+
- lib/devise/models/timeoutable.rb
|
120
|
+
- lib/devise/models/token_authenticatable.rb
|
121
|
+
- lib/devise/models/trackable.rb
|
122
|
+
- lib/devise/models/validatable.rb
|
123
|
+
- lib/devise/modules.rb
|
124
|
+
- lib/devise/omniauth.rb
|
125
|
+
- lib/devise/omniauth/config.rb
|
126
|
+
- lib/devise/omniauth/url_helpers.rb
|
127
|
+
- lib/devise/orm/active_record.rb
|
128
|
+
- lib/devise/orm/mongoid.rb
|
129
|
+
- lib/devise/param_filter.rb
|
130
|
+
- lib/devise/path_checker.rb
|
131
|
+
- lib/devise/rails.rb
|
132
|
+
- lib/devise/rails/routes.rb
|
133
|
+
- lib/devise/rails/warden_compat.rb
|
134
|
+
- lib/devise/schema.rb
|
135
|
+
- lib/devise/strategies/authenticatable.rb
|
136
|
+
- lib/devise/strategies/base.rb
|
137
|
+
- lib/devise/strategies/database_authenticatable.rb
|
138
|
+
- lib/devise/strategies/rememberable.rb
|
139
|
+
- lib/devise/strategies/token_authenticatable.rb
|
140
|
+
- lib/devise/test_helpers.rb
|
141
|
+
- lib/devise/version.rb
|
142
|
+
- lib/generators/active_record/devise_generator.rb
|
143
|
+
- lib/generators/active_record/templates/migration.rb
|
144
|
+
- lib/generators/active_record/templates/migration_existing.rb
|
145
|
+
- lib/generators/devise/devise_generator.rb
|
146
|
+
- lib/generators/devise/install_generator.rb
|
147
|
+
- lib/generators/devise/orm_helpers.rb
|
148
|
+
- lib/generators/devise/views_generator.rb
|
149
|
+
- lib/generators/mongoid/devise_generator.rb
|
150
|
+
- lib/generators/templates/README
|
151
|
+
- lib/generators/templates/devise.rb
|
152
|
+
- lib/generators/templates/markerb/confirmation_instructions.markerb
|
153
|
+
- lib/generators/templates/markerb/reset_password_instructions.markerb
|
154
|
+
- lib/generators/templates/markerb/unlock_instructions.markerb
|
155
|
+
- lib/generators/templates/simple_form_for/confirmations/new.html.erb
|
156
|
+
- lib/generators/templates/simple_form_for/passwords/edit.html.erb
|
157
|
+
- lib/generators/templates/simple_form_for/passwords/new.html.erb
|
158
|
+
- lib/generators/templates/simple_form_for/registrations/edit.html.erb
|
159
|
+
- lib/generators/templates/simple_form_for/registrations/new.html.erb
|
160
|
+
- lib/generators/templates/simple_form_for/sessions/new.html.erb
|
161
|
+
- lib/generators/templates/simple_form_for/unlocks/new.html.erb
|
162
|
+
- test/controllers/helpers_test.rb
|
163
|
+
- test/controllers/internal_helpers_test.rb
|
164
|
+
- test/controllers/sessions_controller_test.rb
|
165
|
+
- test/controllers/url_helpers_test.rb
|
166
|
+
- test/delegator_test.rb
|
167
|
+
- test/devise_test.rb
|
168
|
+
- test/encryptors_test.rb
|
169
|
+
- test/failure_app_test.rb
|
170
|
+
- test/generators/active_record_generator_test.rb
|
171
|
+
- test/generators/devise_generator_test.rb
|
172
|
+
- test/generators/install_generator_test.rb
|
173
|
+
- test/generators/mongoid_generator_test.rb
|
174
|
+
- test/generators/views_generator_test.rb
|
175
|
+
- test/helpers/devise_helper_test.rb
|
176
|
+
- test/indifferent_hash.rb
|
177
|
+
- test/integration/authenticatable_test.rb
|
178
|
+
- test/integration/confirmable_test.rb
|
179
|
+
- test/integration/database_authenticatable_test.rb
|
180
|
+
- test/integration/http_authenticatable_test.rb
|
181
|
+
- test/integration/lockable_test.rb
|
182
|
+
- test/integration/omniauthable_test.rb
|
183
|
+
- test/integration/recoverable_test.rb
|
184
|
+
- test/integration/registerable_test.rb
|
185
|
+
- test/integration/rememberable_test.rb
|
186
|
+
- test/integration/timeoutable_test.rb
|
187
|
+
- test/integration/token_authenticatable_test.rb
|
188
|
+
- test/integration/trackable_test.rb
|
189
|
+
- test/mailers/confirmation_instructions_test.rb
|
190
|
+
- test/mailers/reset_password_instructions_test.rb
|
191
|
+
- test/mailers/unlock_instructions_test.rb
|
192
|
+
- test/mapping_test.rb
|
193
|
+
- test/models/confirmable_test.rb
|
194
|
+
- test/models/database_authenticatable_test.rb
|
195
|
+
- test/models/encryptable_test.rb
|
196
|
+
- test/models/lockable_test.rb
|
197
|
+
- test/models/recoverable_test.rb
|
198
|
+
- test/models/rememberable_test.rb
|
199
|
+
- test/models/serializable_test.rb
|
200
|
+
- test/models/timeoutable_test.rb
|
201
|
+
- test/models/token_authenticatable_test.rb
|
202
|
+
- test/models/trackable_test.rb
|
203
|
+
- test/models/validatable_test.rb
|
204
|
+
- test/models_test.rb
|
205
|
+
- test/omniauth/config_test.rb
|
206
|
+
- test/omniauth/url_helpers_test.rb
|
207
|
+
- test/orm/active_record.rb
|
208
|
+
- test/orm/mongoid.rb
|
209
|
+
- test/rails_app/Rakefile
|
210
|
+
- test/rails_app/app/active_record/admin.rb
|
211
|
+
- test/rails_app/app/active_record/shim.rb
|
212
|
+
- test/rails_app/app/active_record/user.rb
|
213
|
+
- test/rails_app/app/controllers/admins/sessions_controller.rb
|
214
|
+
- test/rails_app/app/controllers/admins_controller.rb
|
215
|
+
- test/rails_app/app/controllers/application_controller.rb
|
216
|
+
- test/rails_app/app/controllers/home_controller.rb
|
217
|
+
- test/rails_app/app/controllers/publisher/registrations_controller.rb
|
218
|
+
- test/rails_app/app/controllers/publisher/sessions_controller.rb
|
219
|
+
- test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb
|
220
|
+
- test/rails_app/app/controllers/users_controller.rb
|
221
|
+
- test/rails_app/app/helpers/application_helper.rb
|
222
|
+
- test/rails_app/app/mailers/users/mailer.rb
|
223
|
+
- test/rails_app/app/mongoid/admin.rb
|
224
|
+
- test/rails_app/app/mongoid/shim.rb
|
225
|
+
- test/rails_app/app/mongoid/user.rb
|
226
|
+
- test/rails_app/app/views/admins/index.html.erb
|
227
|
+
- test/rails_app/app/views/admins/sessions/new.html.erb
|
228
|
+
- test/rails_app/app/views/home/admin_dashboard.html.erb
|
229
|
+
- test/rails_app/app/views/home/index.html.erb
|
230
|
+
- test/rails_app/app/views/home/join.html.erb
|
231
|
+
- test/rails_app/app/views/home/private.html.erb
|
232
|
+
- test/rails_app/app/views/home/user_dashboard.html.erb
|
233
|
+
- test/rails_app/app/views/layouts/application.html.erb
|
234
|
+
- test/rails_app/app/views/users/index.html.erb
|
235
|
+
- test/rails_app/app/views/users/mailer/confirmation_instructions.erb
|
236
|
+
- test/rails_app/app/views/users/sessions/new.html.erb
|
237
|
+
- test/rails_app/config.ru
|
238
|
+
- test/rails_app/config/application.rb
|
239
|
+
- test/rails_app/config/boot.rb
|
240
|
+
- test/rails_app/config/database.yml
|
241
|
+
- test/rails_app/config/environment.rb
|
242
|
+
- test/rails_app/config/environments/development.rb
|
243
|
+
- test/rails_app/config/environments/production.rb
|
244
|
+
- test/rails_app/config/environments/test.rb
|
245
|
+
- test/rails_app/config/initializers/backtrace_silencers.rb
|
246
|
+
- test/rails_app/config/initializers/devise.rb
|
247
|
+
- test/rails_app/config/initializers/inflections.rb
|
248
|
+
- test/rails_app/config/initializers/secret_token.rb
|
249
|
+
- test/rails_app/config/routes.rb
|
250
|
+
- test/rails_app/db/migrate/20100401102949_create_tables.rb
|
251
|
+
- test/rails_app/db/schema.rb
|
252
|
+
- test/rails_app/lib/shared_admin.rb
|
253
|
+
- test/rails_app/lib/shared_user.rb
|
254
|
+
- test/rails_app/public/404.html
|
255
|
+
- test/rails_app/public/422.html
|
256
|
+
- test/rails_app/public/500.html
|
257
|
+
- test/rails_app/public/favicon.ico
|
258
|
+
- test/rails_app/script/rails
|
259
|
+
- test/routes_test.rb
|
260
|
+
- test/support/assertions.rb
|
261
|
+
- test/support/helpers.rb
|
262
|
+
- test/support/integration.rb
|
263
|
+
- test/support/locale/en.yml
|
264
|
+
- test/support/webrat/integrations/rails.rb
|
265
|
+
- test/test_helper.rb
|
266
|
+
- test/test_helpers_test.rb
|
267
|
+
homepage: http://github.com/plataformatec/devise
|
268
|
+
licenses: []
|
269
|
+
|
270
|
+
post_install_message:
|
271
|
+
rdoc_options: []
|
272
|
+
|
273
|
+
require_paths:
|
274
|
+
- lib
|
275
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
276
|
+
none: false
|
277
|
+
requirements:
|
278
|
+
- - ">="
|
279
|
+
- !ruby/object:Gem::Version
|
280
|
+
version: "0"
|
281
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
282
|
+
none: false
|
283
|
+
requirements:
|
284
|
+
- - ">="
|
285
|
+
- !ruby/object:Gem::Version
|
286
|
+
version: "0"
|
287
|
+
requirements: []
|
288
|
+
|
289
|
+
rubyforge_project: devise
|
290
|
+
rubygems_version: 1.8.12
|
291
|
+
signing_key:
|
292
|
+
specification_version: 3
|
293
|
+
summary: Flexible authentication solution for Rails with Warden
|
294
|
+
test_files: []
|
295
|
+
|