devise_security_extension 0.7.2 → 0.10.0

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.
Files changed (68) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +39 -0
  3. data/.rubocop.yml +38 -0
  4. data/Gemfile +2 -15
  5. data/Gemfile.lock +157 -112
  6. data/README.md +264 -0
  7. data/Rakefile +13 -29
  8. data/app/controllers/devise/paranoid_verification_code_controller.rb +42 -0
  9. data/app/controllers/devise/password_expired_controller.rb +20 -7
  10. data/app/views/devise/paranoid_verification_code/show.html.erb +10 -0
  11. data/config/locales/de.yml +3 -0
  12. data/config/locales/en.yml +7 -4
  13. data/config/locales/it.yml +10 -0
  14. data/devise_security_extension.gemspec +24 -88
  15. data/lib/devise_security_extension/controllers/helpers.rb +40 -7
  16. data/lib/devise_security_extension/hooks/paranoid_verification.rb +5 -0
  17. data/lib/devise_security_extension/hooks/password_expirable.rb +1 -1
  18. data/lib/devise_security_extension/hooks/session_limitable.rb +3 -2
  19. data/lib/devise_security_extension/models/database_authenticatable_patch.rb +26 -0
  20. data/lib/devise_security_extension/models/expirable.rb +1 -2
  21. data/lib/devise_security_extension/models/old_password.rb +1 -2
  22. data/lib/devise_security_extension/models/paranoid_verification.rb +35 -0
  23. data/lib/devise_security_extension/models/password_archivable.rb +11 -11
  24. data/lib/devise_security_extension/models/password_expirable.rb +9 -5
  25. data/lib/devise_security_extension/models/secure_validatable.rb +35 -9
  26. data/lib/devise_security_extension/models/security_questionable.rb +4 -1
  27. data/lib/devise_security_extension/patches/confirmations_controller_captcha.rb +3 -1
  28. data/lib/devise_security_extension/patches/confirmations_controller_security_question.rb +3 -1
  29. data/lib/devise_security_extension/patches/passwords_controller_captcha.rb +3 -1
  30. data/lib/devise_security_extension/patches/passwords_controller_security_question.rb +3 -1
  31. data/lib/devise_security_extension/patches/registrations_controller_captcha.rb +11 -8
  32. data/lib/devise_security_extension/patches/sessions_controller_captcha.rb +8 -5
  33. data/lib/devise_security_extension/patches/unlocks_controller_captcha.rb +3 -1
  34. data/lib/devise_security_extension/patches/unlocks_controller_security_question.rb +3 -1
  35. data/lib/devise_security_extension/routes.rb +4 -0
  36. data/lib/devise_security_extension/version.rb +3 -0
  37. data/lib/devise_security_extension.rb +20 -10
  38. data/lib/generators/devise_security_extension/install_generator.rb +16 -33
  39. data/lib/generators/templates/devise_security_extension.rb +38 -0
  40. data/test/dummy/Rakefile +6 -0
  41. data/test/dummy/app/controllers/application_controller.rb +2 -0
  42. data/test/dummy/app/controllers/foos_controller.rb +0 -0
  43. data/test/dummy/app/models/.gitkeep +0 -0
  44. data/test/dummy/app/models/user.rb +4 -0
  45. data/test/dummy/app/views/foos/index.html.erb +0 -0
  46. data/test/dummy/config/application.rb +24 -0
  47. data/test/dummy/config/boot.rb +6 -0
  48. data/test/dummy/config/database.yml +7 -0
  49. data/test/dummy/config/environment.rb +5 -0
  50. data/test/dummy/config/environments/test.rb +21 -0
  51. data/test/dummy/config/initializers/devise.rb +9 -0
  52. data/test/dummy/config/routes.rb +6 -0
  53. data/test/dummy/config/secrets.yml +3 -0
  54. data/test/dummy/config.ru +4 -0
  55. data/test/dummy/db/migrate/20120508165529_create_tables.rb +26 -0
  56. data/test/dummy/db/migrate/20150402165590_add_verification_columns.rb +11 -0
  57. data/test/dummy/db/migrate/20150407162345_add_verification_attempt_column.rb +9 -0
  58. data/test/test_helper.rb +10 -0
  59. data/test/test_install_generator.rb +16 -0
  60. data/test/test_paranoid_verification.rb +124 -0
  61. data/test/test_password_archivable.rb +61 -0
  62. data/test/test_password_expired_controller.rb +24 -0
  63. metadata +142 -62
  64. data/README.rdoc +0 -193
  65. data/VERSION +0 -1
  66. data/lib/devise_security_extension/models/security_question.rb +0 -3
  67. data/test/helper.rb +0 -17
  68. data/test/test_devise_security_extension.rb +0 -7
@@ -17,17 +17,27 @@ module Devise
17
17
  assert_secure_validations_api!(base)
18
18
 
19
19
  base.class_eval do
20
+ # validate login in a strict way if not yet validated
21
+ unless has_uniqueness_validation_of_login?
22
+ validation_condition = "#{login_attribute}_changed?".to_sym
20
23
 
21
- # uniq login
22
- validates authentication_keys[0], :uniqueness => {:scope => authentication_keys[1..-1], :case_sensitive => (case_insensitive_keys != false)}, :if => :email_changed?
24
+ validates login_attribute, :uniqueness => {
25
+ :scope => authentication_keys[1..-1],
26
+ :case_sensitive => !!case_insensitive_keys
27
+ },
28
+ :if => validation_condition
29
+ end
23
30
 
24
- # validates email
25
- validates :email, :presence => true, :if => :email_required?
26
- validates :email, :uniqueness => true, :allow_blank => true, :if => :email_changed? # check uniq for email ever
27
- validates :email, :email => email_validation if email_validation # use rails_email_validator or similar
28
-
29
- # validates password
30
- validates :password, :presence => true, :length => password_length, :format => password_regex, :confirmation => true, :if => :password_required?
31
+ unless devise_validation_enabled?
32
+ validates :email, :presence => true, :if => :email_required?
33
+ validates :email, :uniqueness => true, :allow_blank => true, :if => :email_changed? # check uniq for email ever
34
+
35
+ validates :password, :presence => true, :length => password_length, :confirmation => true, :if => :password_required?
36
+ end
37
+
38
+ # extra validations
39
+ validates :email, :email => email_validation if email_validation # use rails_email_validator or similar
40
+ validates :password, :format => { :with => password_regex, :message => :password_format }, :if => :password_required?
31
41
 
32
42
  # don't allow use same password
33
43
  validate :current_equal_password_validation
@@ -62,6 +72,22 @@ module Devise
62
72
 
63
73
  module ClassMethods
64
74
  Devise::Models.config(self, :password_regex, :password_length, :email_validation)
75
+
76
+ private
77
+ def has_uniqueness_validation_of_login?
78
+ validators.any? do |validator|
79
+ validator.kind_of?(ActiveRecord::Validations::UniquenessValidator) &&
80
+ validator.attributes.include?(login_attribute)
81
+ end
82
+ end
83
+
84
+ def login_attribute
85
+ authentication_keys[0]
86
+ end
87
+
88
+ def devise_validation_enabled?
89
+ self.ancestors.map(&:to_s).include? 'Devise::Models::Validatable'
90
+ end
65
91
  end
66
92
  end
67
93
  end
@@ -3,10 +3,13 @@ module Devise
3
3
  # SecurityQuestionable is an accessible add-on for visually handicapped people,
4
4
  # to ship around the captcha with screenreader compatibility.
5
5
  #
6
- # You need to add two text_field_tags to the associated form:
6
+ # You need to add two text_field_tags to the associated forms (unlock,
7
+ # password, confirmation):
7
8
  # :security_question_answer and :captcha
8
9
  #
9
10
  # And add the security_question to the register/edit form.
11
+ # f.select :security_question_id, SecurityQuestion.where(locale: I18n.locale).map{|s| [s.name, s.id]}
12
+ # f.text_field :security_question_answer
10
13
  module SecurityQuestionable
11
14
  extend ActiveSupport::Concern
12
15
 
@@ -3,7 +3,9 @@ module DeviseSecurityExtension::Patches
3
3
  extend ActiveSupport::Concern
4
4
  included do
5
5
  define_method :create do
6
- if valid_captcha? params[:captcha]
6
+ if ((defined? verify_recaptcha) && (verify_recaptcha
7
+ params[:captcha])) or ((defined? valid_captcha?) && (valid_captcha?
8
+ params[:captcha]))
7
9
  self.resource = resource_class.send_confirmation_instructions(params[resource_name])
8
10
 
9
11
  if successfully_sent?(resource)
@@ -6,7 +6,9 @@ module DeviseSecurityExtension::Patches
6
6
  # only find via email, not login
7
7
  resource = resource_class.find_or_initialize_with_error_by(:email, params[resource_name][:email], :not_found)
8
8
 
9
- if valid_captcha? params[:captcha] or
9
+ if ((defined? verify_recaptcha) && (verify_recaptcha
10
+ params[:captcha])) or ((defined? valid_captcha?) && (valid_captcha?
11
+ params[:captcha])) or
10
12
  (resource.security_question_answer.present? and resource.security_question_answer == params[:security_question_answer])
11
13
  self.resource = resource_class.send_confirmation_instructions(params[resource_name])
12
14
 
@@ -3,7 +3,9 @@ module DeviseSecurityExtension::Patches
3
3
  extend ActiveSupport::Concern
4
4
  included do
5
5
  define_method :create do
6
- if valid_captcha? params[:captcha]
6
+ if ((defined? verify_recaptcha) && (verify_recaptcha
7
+ params[:captcha])) or ((defined? valid_captcha?) && (valid_captcha?
8
+ params[:captcha]))
7
9
  self.resource = resource_class.send_reset_password_instructions(params[resource_name])
8
10
  if successfully_sent?(resource)
9
11
  respond_with({}, :location => new_session_path(resource_name))
@@ -6,7 +6,9 @@ module DeviseSecurityExtension::Patches
6
6
  # only find via email, not login
7
7
  resource = resource_class.find_or_initialize_with_error_by(:email, params[resource_name][:email], :not_found)
8
8
 
9
- if valid_captcha? params[:captcha] or
9
+ if ((defined? verify_recaptcha) && (verify_recaptcha
10
+ params[:captcha])) or ((defined? valid_captcha?) && (valid_captcha?
11
+ params[:captcha]))
10
12
  (resource.security_question_answer.present? and resource.security_question_answer == params[:security_question_answer])
11
13
  self.resource = resource_class.send_reset_password_instructions(params[resource_name])
12
14
  if successfully_sent?(resource)
@@ -2,26 +2,29 @@ module DeviseSecurityExtension::Patches
2
2
  module RegistrationsControllerCaptcha
3
3
  extend ActiveSupport::Concern
4
4
  included do
5
- define_method :create do
6
- build_resource
5
+ define_method :create do |&block|
6
+ build_resource(sign_up_params)
7
7
 
8
- if valid_captcha? params[:captcha]
8
+ if ((defined? verify_recaptcha) && (verify_recaptcha
9
+ params[:captcha])) or ((defined? valid_captcha?) && (valid_captcha?
10
+ params[:captcha]))
9
11
 
10
12
  if resource.save
13
+ block.call(resource) if block
11
14
  if resource.active_for_authentication?
12
- set_flash_message :notice, :signed_up if is_navigational_format?
13
- sign_in(resource_name, resource)
15
+ set_flash_message :notice, :signed_up if is_flashing_format?
16
+ sign_up(resource_name, resource)
14
17
  respond_with resource, :location => after_sign_up_path_for(resource)
15
18
  else
16
- set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_navigational_format?
17
- expire_session_data_after_sign_in!
19
+ set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_flashing_format?
20
+ expire_data_after_sign_in!
18
21
  respond_with resource, :location => after_inactive_sign_up_path_for(resource)
19
22
  end
20
23
  else
21
24
  clean_up_passwords resource
22
25
  respond_with resource
23
26
  end
24
-
27
+
25
28
  else
26
29
  resource.errors.add :base, t('devise.invalid_captcha')
27
30
  clean_up_passwords resource
@@ -2,14 +2,17 @@ module DeviseSecurityExtension::Patches
2
2
  module SessionsControllerCaptcha
3
3
  extend ActiveSupport::Concern
4
4
  included do
5
- define_method :create do
6
- if valid_captcha? params[:captcha]
7
- resource = warden.authenticate!(auth_options)
8
- set_flash_message(:notice, :signed_in) if is_navigational_format?
5
+ define_method :create do |&block|
6
+ if ((defined? verify_recaptcha) && (verify_recaptcha
7
+ params[:captcha])) or ((defined? valid_captcha?) && (valid_captcha?
8
+ params[:captcha]))
9
+ self.resource = warden.authenticate!(auth_options)
10
+ set_flash_message(:notice, :signed_in) if is_flashing_format?
9
11
  sign_in(resource_name, resource)
12
+ block.call(resource) if block
10
13
  respond_with resource, :location => after_sign_in_path_for(resource)
11
14
  else
12
- flash[:alert] = t('devise.invalid_captcha') if is_navigational_format?
15
+ flash[:alert] = t('devise.invalid_captcha') if is_flashing_format?
13
16
  respond_with({}, :location => new_session_path(resource_name))
14
17
  end
15
18
  end
@@ -3,7 +3,9 @@ module DeviseSecurityExtension::Patches
3
3
  extend ActiveSupport::Concern
4
4
  included do
5
5
  define_method :create do
6
- if valid_captcha? params[:captcha]
6
+ if ((defined? verify_recaptcha) && (verify_recaptcha
7
+ params[:captcha])) or ((defined? valid_captcha?) && (valid_captcha?
8
+ params[:captcha]))
7
9
  self.resource = resource_class.send_unlock_instructions(params[resource_name])
8
10
  if successfully_sent?(resource)
9
11
  respond_with({}, :location => new_session_path(resource_name))
@@ -6,7 +6,9 @@ module DeviseSecurityExtension::Patches
6
6
  # only find via email, not login
7
7
  resource = resource_class.find_or_initialize_with_error_by(:email, params[resource_name][:email], :not_found)
8
8
 
9
- if valid_captcha? params[:captcha] or
9
+ if ((defined? verify_recaptcha) && (verify_recaptcha
10
+ params[:captcha])) or ((defined? valid_captcha?) && (valid_captcha?
11
+ params[:captcha]))
10
12
  (resource.security_question_answer.present? and resource.security_question_answer == params[:security_question_answer])
11
13
  self.resource = resource_class.send_unlock_instructions(params[resource_name])
12
14
  if successfully_sent?(resource)
@@ -8,6 +8,10 @@ module ActionDispatch::Routing
8
8
  resource :password_expired, :only => [:show, :update], :path => mapping.path_names[:password_expired], :controller => controllers[:password_expired]
9
9
  end
10
10
 
11
+ # route for handle paranoid verification
12
+ def devise_verification_code(mapping, controllers)
13
+ resource :paranoid_verification_code, :only => [:show, :update], :path => mapping.path_names[:verification_code], :controller => controllers[:paranoid_verification_code]
14
+ end
11
15
  end
12
16
  end
13
17
 
@@ -0,0 +1,3 @@
1
+ module DeviseSecurityExtension
2
+ VERSION = "0.10.0".freeze
3
+ end
@@ -1,5 +1,4 @@
1
- #require 'rails/all'
2
- require 'active_record/connection_adapters/abstract/schema_definitions'
1
+ require 'active_record'
3
2
  require 'active_support/core_ext/integer'
4
3
  require 'active_support/ordered_hash'
5
4
  require 'active_support/concern'
@@ -15,7 +14,7 @@ module Devise
15
14
  mattr_accessor :password_regex
16
15
  @@password_regex = /(?=.*\d)(?=.*[a-z])(?=.*[A-Z])/
17
16
 
18
- # How often save old passwords in archive
17
+ # Number of old passwords in archive
19
18
  mattr_accessor :password_archiving_count
20
19
  @@password_archiving_count = 5
21
20
 
@@ -63,11 +62,19 @@ module Devise
63
62
  mattr_accessor :captcha_for_confirmation
64
63
  @@captcha_for_confirmation = false
65
64
 
65
+ # captcha integration for confirmation form
66
+ mattr_accessor :verification_code_generator
67
+ @@verification_code_generator = -> { SecureRandom.hex[0..4] }
68
+
66
69
  # Time period for account expiry from last_activity_at
67
70
  mattr_accessor :expire_after
68
71
  @@expire_after = 90.days
69
72
  mattr_accessor :delete_expired_after
70
73
  @@delete_expired_after = 90.days
74
+
75
+ # paranoid_verification will regenerate verifacation code after faild attempt
76
+ mattr_accessor :paranoid_code_regenerate_after_attempt
77
+ @@paranoid_code_regenerate_after_attempt = 10
71
78
  end
72
79
 
73
80
  # an security extension for devise
@@ -81,16 +88,19 @@ module DeviseSecurityExtension
81
88
  end
82
89
 
83
90
  # modules
84
- Devise.add_module :password_expirable, :controller => :password_expirable, :model => 'devise_security_extension/models/password_expirable', :route => :password_expired
85
- Devise.add_module :secure_validatable, :model => 'devise_security_extension/models/secure_validatable'
86
- Devise.add_module :password_archivable, :model => 'devise_security_extension/models/password_archivable'
87
- Devise.add_module :session_limitable, :model => 'devise_security_extension/models/session_limitable'
88
- Devise.add_module :expirable, :model => 'devise_security_extension/models/expirable'
89
- Devise.add_module :security_questionable, :model => 'devise_security_extension/models/security_questionable'
91
+ Devise.add_module :password_expirable, controller: :password_expirable, model: 'devise_security_extension/models/password_expirable', route: :password_expired
92
+ Devise.add_module :secure_validatable, model: 'devise_security_extension/models/secure_validatable'
93
+ Devise.add_module :password_archivable, model: 'devise_security_extension/models/password_archivable'
94
+ Devise.add_module :session_limitable, model: 'devise_security_extension/models/session_limitable'
95
+ Devise.add_module :session_non_transferable, model: 'devise_security_extension/models/session_non_transferable'
96
+ Devise.add_module :expirable, model: 'devise_security_extension/models/expirable'
97
+ Devise.add_module :security_questionable, model: 'devise_security_extension/models/security_questionable'
98
+ Devise.add_module :paranoid_verification, controller: :paranoid_verification_code, model: 'devise_security_extension/models/paranoid_verification', route: :verification_code
90
99
 
91
100
  # requires
92
101
  require 'devise_security_extension/routes'
93
102
  require 'devise_security_extension/rails'
94
103
  require 'devise_security_extension/orm/active_record'
95
104
  require 'devise_security_extension/models/old_password'
96
- require 'devise_security_extension/models/security_question'
105
+ require 'devise_security_extension/models/database_authenticatable_patch'
106
+ require 'devise_security_extension/models/paranoid_verification'
@@ -1,43 +1,26 @@
1
1
  module DeviseSecurityExtension
2
2
  module Generators
3
- # Install Generator
3
+ # Generator for Rails to create or append to a Devise initializer.
4
4
  class InstallGenerator < Rails::Generators::Base
5
- source_root File.expand_path("../../templates", __FILE__)
5
+ LOCALES = %w[ en de it ]
6
6
 
7
- desc "Install the devise security extension"
7
+ source_root File.expand_path('../../templates', __FILE__)
8
+ desc 'Install the devise security extension'
8
9
 
9
- def add_configs
10
- inject_into_file "config/initializers/devise.rb", "\n # ==> Security Extension\n # Configure security extension for devise\n\n" +
11
- " # Should the password expire (e.g 3.months)\n" +
12
- " # config.expire_password_after = false\n\n" +
13
- " # Need 1 char of A-Z, a-z and 0-9\n" +
14
- " # config.password_regex = /(?=.*\\d)(?=.*[a-z])(?=.*[A-Z])/\n\n" +
15
- " # How many passwords to keep in archive\n" +
16
- " # config.password_archiving_count = 5\n\n" +
17
- " # Deny old password (true, false, count)\n" +
18
- " # config.deny_old_passwords = true\n\n" +
19
- " # enable email validation for :secure_validatable. (true, false, validation_options)\n" +
20
- " # dependency: need an email validator like rails_email_validator\n" +
21
- " # config.email_validation = true\n\n" +
22
- " # captcha integration for recover form\n" +
23
- " # config.captcha_for_recover = true\n\n" +
24
- " # captcha integration for sign up form\n" +
25
- " # config.captcha_for_sign_up = true\n\n" +
26
- " # captcha integration for sign in form\n" +
27
- " # config.captcha_for_sign_in = true\n\n" +
28
- " # captcha integration for unlock form\n" +
29
- " # config.captcha_for_unlock = true\n\n" +
30
- " # captcha integration for confirmation form\n" +
31
- " # config.captcha_for_confirmation = true\n\n" +
32
- " # Time period for account expiry from last_activity_at\n" +
33
- " # config.expire_after = 90.days\n\n" +
34
- "", :before => /end[ |\n|]+\Z/
10
+ def copy_initializer
11
+ template('devise_security_extension.rb',
12
+ 'config/initializers/devise_security_extension.rb',
13
+ )
35
14
  end
36
15
 
37
- def copy_locale
38
- copy_file "../../../config/locales/en.yml", "config/locales/devise.security_extension.en.yml"
39
- copy_file "../../../config/locales/de.yml", "config/locales/devise.security_extension.de.yml"
16
+ def copy_locales
17
+ LOCALES.each do |locale|
18
+ copy_file(
19
+ "../../../config/locales/#{locale}.yml",
20
+ "config/locales/devise.security_extension.#{locale}.yml",
21
+ )
22
+ end
40
23
  end
41
24
  end
42
25
  end
43
- end
26
+ end
@@ -0,0 +1,38 @@
1
+ Devise.setup do |config|
2
+ # ==> Security Extension
3
+ # Configure security extension for devise
4
+
5
+ # Should the password expire (e.g 3.months)
6
+ # config.expire_password_after = false
7
+
8
+ # Need 1 char of A-Z, a-z and 0-9
9
+ # config.password_regex = /(?=.*\\d)(?=.*[a-z])(?=.*[A-Z])/
10
+
11
+ # How many passwords to keep in archive
12
+ # config.password_archiving_count = 5
13
+
14
+ # Deny old password (true, false, count)
15
+ # config.deny_old_passwords = true
16
+
17
+ # enable email validation for :secure_validatable. (true, false, validation_options)
18
+ # dependency: need an email validator like rails_email_validator
19
+ # config.email_validation = true
20
+
21
+ # captcha integration for recover form
22
+ # config.captcha_for_recover = true
23
+
24
+ # captcha integration for sign up form
25
+ # config.captcha_for_sign_up = true
26
+
27
+ # captcha integration for sign in form
28
+ # config.captcha_for_sign_in = true
29
+
30
+ # captcha integration for unlock form
31
+ # config.captcha_for_unlock = true
32
+
33
+ # captcha integration for confirmation form
34
+ # config.captcha_for_confirmation = true
35
+
36
+ # Time period for account expiry from last_activity_at
37
+ # config.expire_after = 90.days
38
+ end
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require File.expand_path('../config/application', __FILE__)
5
+
6
+ Rails.application.load_tasks
@@ -0,0 +1,2 @@
1
+ class ApplicationController < ActionController::Base
2
+ end
File without changes
File without changes
@@ -0,0 +1,4 @@
1
+ class User < ActiveRecord::Base
2
+ devise :database_authenticatable, :password_archivable,
3
+ :paranoid_verification, :password_expirable
4
+ end
File without changes
@@ -0,0 +1,24 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ require 'rails/all'
4
+ require 'devise_security_extension'
5
+
6
+ if defined?(Bundler)
7
+ # If you precompile assets before deploying to production, use this line
8
+ Bundler.require(*Rails.groups(assets: %w[development test]))
9
+ # If you want your assets lazily compiled in production, use this line
10
+ # Bundler.require(:default, :assets, Rails.env)
11
+ end
12
+
13
+ module RailsApp
14
+ class Application < Rails::Application
15
+ config.encoding = 'utf-8'
16
+
17
+ config.filter_parameters += [:password]
18
+
19
+ config.assets.enabled = true
20
+
21
+ config.assets.version = '1.0'
22
+ config.secret_key_base = 'fuuuuuuuuuuu'
23
+ end
24
+ end
@@ -0,0 +1,6 @@
1
+ require 'rubygems'
2
+
3
+ # Set up gems listed in the Gemfile.
4
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
5
+
6
+ require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
@@ -0,0 +1,7 @@
1
+ development:
2
+ adapter: sqlite3
3
+ database: ":memory:"
4
+
5
+ test:
6
+ adapter: sqlite3
7
+ database: ":memory:"
@@ -0,0 +1,5 @@
1
+ # Load the rails application
2
+ require File.expand_path('../application', __FILE__)
3
+
4
+ # Initialize the rails application
5
+ RailsApp::Application.initialize!
@@ -0,0 +1,21 @@
1
+ RailsApp::Application.configure do
2
+ config.cache_classes = true
3
+ config.eager_load = false
4
+
5
+ config.serve_static_files = true
6
+ config.static_cache_control = 'public, max-age=3600'
7
+
8
+ config.consider_all_requests_local = true
9
+ config.action_controller.perform_caching = false
10
+
11
+ config.action_dispatch.show_exceptions = false
12
+
13
+ config.action_controller.allow_forgery_protection = false
14
+
15
+ config.action_mailer.delivery_method = :test
16
+
17
+ config.active_support.deprecation = :stderr
18
+ I18n.enforce_available_locales = false
19
+
20
+ config.active_support.test_order = :sorted
21
+ end
@@ -0,0 +1,9 @@
1
+ Devise.setup do |config|
2
+ config.mailer_sender = 'please-change-me-at-config-initializers-devise@example.com'
3
+
4
+ require 'devise/orm/active_record'
5
+ config.secret_key = 'f08cf11a38906f531d2dfc9a2c2d671aa0021be806c21255d4'
6
+ config.case_insensitive_keys = [:email]
7
+
8
+ config.strip_whitespace_keys = [:email]
9
+ end
@@ -0,0 +1,6 @@
1
+ RailsApp::Application.routes.draw do
2
+ devise_for :users
3
+ resources :foos
4
+
5
+ root to: 'foos#index'
6
+ end
@@ -0,0 +1,3 @@
1
+ test:
2
+ secret_token: 'fooooooooooo'
3
+ secret_key_base: 'fuuuuuuuuuuu'
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run RailsApp::Application
@@ -0,0 +1,26 @@
1
+ class CreateTables < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :users do |t|
4
+ t.string :username
5
+ t.string :facebook_token
6
+
7
+ ## Database authenticatable
8
+ t.string :email, null: false, default: ''
9
+ t.string :encrypted_password, null: false, default: ''
10
+
11
+ t.datetime :password_changed_at
12
+ t.timestamps null: false
13
+ end
14
+
15
+ create_table :old_passwords do |t|
16
+ t.string :encrypted_password
17
+
18
+ t.references :password_archivable, polymorphic: true
19
+ end
20
+ end
21
+
22
+ def self.down
23
+ drop_table :users
24
+ drop_table :old_passwords
25
+ end
26
+ end
@@ -0,0 +1,11 @@
1
+ class AddVerificationColumns < ActiveRecord::Migration
2
+ def self.up
3
+ add_column :users, :paranoid_verification_code, :string
4
+ add_column :users, :paranoid_verified_at, :datetime
5
+ end
6
+
7
+ def self.down
8
+ remove_column :users, :paranoid_verification_code
9
+ remove_column :users, :paranoid_verified_at
10
+ end
11
+ end
@@ -0,0 +1,9 @@
1
+ class AddVerificationAttemptColumn < ActiveRecord::Migration
2
+ def self.up
3
+ add_column :users, :paranoid_verification_attempt, :integer, default: 0
4
+ end
5
+
6
+ def self.down
7
+ remove_column :users, :paranoid_verification_attempt
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ ENV['RAILS_ENV'] ||= 'test'
2
+
3
+ require 'dummy/config/environment'
4
+ require 'minitest/autorun'
5
+ require 'rails/test_help'
6
+ require 'devise_security_extension'
7
+
8
+ ActiveRecord::Migration.verbose = false
9
+ ActiveRecord::Base.logger = Logger.new(nil)
10
+ ActiveRecord::Migrator.migrate(File.expand_path('../dummy/db/migrate', __FILE__))
@@ -0,0 +1,16 @@
1
+ require 'test_helper'
2
+ require 'rails/generators/test_case'
3
+ require 'generators/devise_security_extension/install_generator'
4
+
5
+ class TestInstallGenerator < Rails::Generators::TestCase
6
+ tests DeviseSecurityExtension::Generators::InstallGenerator
7
+ destination File.expand_path('../tmp', __FILE__)
8
+ setup :prepare_destination
9
+
10
+ test 'Assert all files are properly created' do
11
+ run_generator
12
+ assert_file 'config/initializers/devise_security_extension.rb'
13
+ assert_file 'config/locales/devise.security_extension.en.yml'
14
+ assert_file 'config/locales/devise.security_extension.de.yml'
15
+ end
16
+ end