authlogic 3.8.0 → 6.0.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 (150) hide show
  1. checksums.yaml +7 -0
  2. data/lib/authlogic/acts_as_authentic/base.rb +33 -36
  3. data/lib/authlogic/acts_as_authentic/email.rb +8 -141
  4. data/lib/authlogic/acts_as_authentic/logged_in_status.rb +17 -10
  5. data/lib/authlogic/acts_as_authentic/login.rb +14 -165
  6. data/lib/authlogic/acts_as_authentic/magic_columns.rb +13 -10
  7. data/lib/authlogic/acts_as_authentic/password.rb +186 -254
  8. data/lib/authlogic/acts_as_authentic/perishable_token.rb +30 -22
  9. data/lib/authlogic/acts_as_authentic/persistence_token.rb +19 -18
  10. data/lib/authlogic/acts_as_authentic/queries/case_sensitivity.rb +53 -0
  11. data/lib/authlogic/acts_as_authentic/queries/find_with_case.rb +83 -0
  12. data/lib/authlogic/acts_as_authentic/session_maintenance.rb +94 -62
  13. data/lib/authlogic/acts_as_authentic/single_access_token.rb +28 -14
  14. data/lib/authlogic/config.rb +29 -10
  15. data/lib/authlogic/controller_adapters/abstract_adapter.rb +43 -13
  16. data/lib/authlogic/controller_adapters/rack_adapter.rb +11 -5
  17. data/lib/authlogic/controller_adapters/rails_adapter.rb +11 -29
  18. data/lib/authlogic/controller_adapters/sinatra_adapter.rb +8 -2
  19. data/lib/authlogic/cookie_credentials.rb +63 -0
  20. data/lib/authlogic/crypto_providers/bcrypt.rb +24 -18
  21. data/lib/authlogic/crypto_providers/md5/v2.rb +35 -0
  22. data/lib/authlogic/crypto_providers/md5.rb +8 -6
  23. data/lib/authlogic/crypto_providers/scrypt.rb +24 -17
  24. data/lib/authlogic/crypto_providers/sha1/v2.rb +41 -0
  25. data/lib/authlogic/crypto_providers/sha1.rb +12 -5
  26. data/lib/authlogic/crypto_providers/sha256/v2.rb +58 -0
  27. data/lib/authlogic/crypto_providers/sha256.rb +18 -9
  28. data/lib/authlogic/crypto_providers/sha512/v2.rb +39 -0
  29. data/lib/authlogic/crypto_providers/sha512.rb +9 -26
  30. data/lib/authlogic/crypto_providers.rb +77 -1
  31. data/lib/authlogic/errors.rb +35 -0
  32. data/lib/authlogic/i18n/translator.rb +4 -1
  33. data/lib/authlogic/i18n.rb +29 -20
  34. data/lib/authlogic/random.rb +12 -28
  35. data/lib/authlogic/session/base.rb +2087 -33
  36. data/lib/authlogic/session/magic_column/assigns_last_request_at.rb +46 -0
  37. data/lib/authlogic/test_case/mock_controller.rb +7 -4
  38. data/lib/authlogic/test_case/mock_cookie_jar.rb +19 -3
  39. data/lib/authlogic/test_case/mock_logger.rb +2 -0
  40. data/lib/authlogic/test_case/mock_request.rb +8 -3
  41. data/lib/authlogic/test_case/rails_request_adapter.rb +5 -2
  42. data/lib/authlogic/test_case.rb +74 -2
  43. data/lib/authlogic/version.rb +22 -0
  44. data/lib/authlogic.rb +33 -54
  45. metadata +208 -234
  46. data/.github/ISSUE_TEMPLATE.md +0 -13
  47. data/.gitignore +0 -14
  48. data/.rubocop.yml +0 -33
  49. data/.rubocop_todo.yml +0 -391
  50. data/.travis.yml +0 -48
  51. data/CHANGELOG.md +0 -5
  52. data/CONTRIBUTING.md +0 -60
  53. data/Gemfile +0 -5
  54. data/LICENSE +0 -20
  55. data/README.md +0 -294
  56. data/Rakefile +0 -21
  57. data/authlogic.gemspec +0 -27
  58. data/lib/authlogic/acts_as_authentic/restful_authentication.rb +0 -70
  59. data/lib/authlogic/acts_as_authentic/validations_scope.rb +0 -32
  60. data/lib/authlogic/authenticates_many/association.rb +0 -50
  61. data/lib/authlogic/authenticates_many/base.rb +0 -65
  62. data/lib/authlogic/crypto_providers/aes256.rb +0 -66
  63. data/lib/authlogic/crypto_providers/wordpress.rb +0 -43
  64. data/lib/authlogic/regex.rb +0 -48
  65. data/lib/authlogic/session/activation.rb +0 -70
  66. data/lib/authlogic/session/active_record_trickery.rb +0 -61
  67. data/lib/authlogic/session/brute_force_protection.rb +0 -120
  68. data/lib/authlogic/session/callbacks.rb +0 -105
  69. data/lib/authlogic/session/cookies.rb +0 -244
  70. data/lib/authlogic/session/existence.rb +0 -93
  71. data/lib/authlogic/session/foundation.rb +0 -55
  72. data/lib/authlogic/session/http_auth.rb +0 -100
  73. data/lib/authlogic/session/id.rb +0 -48
  74. data/lib/authlogic/session/klass.rb +0 -70
  75. data/lib/authlogic/session/magic_columns.rb +0 -116
  76. data/lib/authlogic/session/magic_states.rb +0 -76
  77. data/lib/authlogic/session/params.rb +0 -116
  78. data/lib/authlogic/session/password.rb +0 -308
  79. data/lib/authlogic/session/perishable_token.rb +0 -23
  80. data/lib/authlogic/session/persistence.rb +0 -71
  81. data/lib/authlogic/session/priority_record.rb +0 -35
  82. data/lib/authlogic/session/scopes.rb +0 -119
  83. data/lib/authlogic/session/session.rb +0 -67
  84. data/lib/authlogic/session/timeout.rb +0 -103
  85. data/lib/authlogic/session/unauthorized_record.rb +0 -51
  86. data/lib/authlogic/session/validation.rb +0 -93
  87. data/test/acts_as_authentic_test/base_test.rb +0 -25
  88. data/test/acts_as_authentic_test/email_test.rb +0 -240
  89. data/test/acts_as_authentic_test/logged_in_status_test.rb +0 -62
  90. data/test/acts_as_authentic_test/login_test.rb +0 -156
  91. data/test/acts_as_authentic_test/magic_columns_test.rb +0 -27
  92. data/test/acts_as_authentic_test/password_test.rb +0 -249
  93. data/test/acts_as_authentic_test/perishable_token_test.rb +0 -90
  94. data/test/acts_as_authentic_test/persistence_token_test.rb +0 -56
  95. data/test/acts_as_authentic_test/restful_authentication_test.rb +0 -37
  96. data/test/acts_as_authentic_test/session_maintenance_test.rb +0 -96
  97. data/test/acts_as_authentic_test/single_access_test.rb +0 -44
  98. data/test/authenticates_many_test.rb +0 -31
  99. data/test/config_test.rb +0 -36
  100. data/test/crypto_provider_test/aes256_test.rb +0 -14
  101. data/test/crypto_provider_test/bcrypt_test.rb +0 -14
  102. data/test/crypto_provider_test/scrypt_test.rb +0 -14
  103. data/test/crypto_provider_test/sha1_test.rb +0 -23
  104. data/test/crypto_provider_test/sha256_test.rb +0 -14
  105. data/test/crypto_provider_test/sha512_test.rb +0 -14
  106. data/test/fixtures/companies.yml +0 -5
  107. data/test/fixtures/employees.yml +0 -17
  108. data/test/fixtures/projects.yml +0 -3
  109. data/test/fixtures/users.yml +0 -41
  110. data/test/gemfiles/Gemfile.rails-3.2.x +0 -7
  111. data/test/gemfiles/Gemfile.rails-4.0.x +0 -7
  112. data/test/gemfiles/Gemfile.rails-4.1.x +0 -7
  113. data/test/gemfiles/Gemfile.rails-4.2.x +0 -7
  114. data/test/gemfiles/Gemfile.rails-5.0.x +0 -6
  115. data/test/gemfiles/Gemfile.rails-5.1.x +0 -6
  116. data/test/gemfiles/Gemfile.rails-5.2.x +0 -6
  117. data/test/i18n/lol.yml +0 -4
  118. data/test/i18n_test.rb +0 -33
  119. data/test/libs/affiliate.rb +0 -7
  120. data/test/libs/company.rb +0 -6
  121. data/test/libs/employee.rb +0 -7
  122. data/test/libs/employee_session.rb +0 -2
  123. data/test/libs/ldaper.rb +0 -3
  124. data/test/libs/project.rb +0 -3
  125. data/test/libs/user.rb +0 -7
  126. data/test/libs/user_session.rb +0 -25
  127. data/test/random_test.rb +0 -43
  128. data/test/session_test/activation_test.rb +0 -43
  129. data/test/session_test/active_record_trickery_test.rb +0 -75
  130. data/test/session_test/brute_force_protection_test.rb +0 -108
  131. data/test/session_test/callbacks_test.rb +0 -34
  132. data/test/session_test/cookies_test.rb +0 -201
  133. data/test/session_test/credentials_test.rb +0 -0
  134. data/test/session_test/existence_test.rb +0 -75
  135. data/test/session_test/foundation_test.rb +0 -6
  136. data/test/session_test/http_auth_test.rb +0 -56
  137. data/test/session_test/id_test.rb +0 -17
  138. data/test/session_test/klass_test.rb +0 -40
  139. data/test/session_test/magic_columns_test.rb +0 -62
  140. data/test/session_test/magic_states_test.rb +0 -58
  141. data/test/session_test/params_test.rb +0 -53
  142. data/test/session_test/password_test.rb +0 -105
  143. data/test/session_test/perishability_test.rb +0 -15
  144. data/test/session_test/persistence_test.rb +0 -32
  145. data/test/session_test/scopes_test.rb +0 -60
  146. data/test/session_test/session_test.rb +0 -78
  147. data/test/session_test/timeout_test.rb +0 -82
  148. data/test/session_test/unauthorized_record_test.rb +0 -13
  149. data/test/session_test/validation_test.rb +0 -23
  150. data/test/test_helper.rb +0 -233
@@ -1,103 +0,0 @@
1
- module Authlogic
2
- module Session
3
- # Think about financial websites, if you are inactive for a certain period
4
- # of time you will be asked to log back in on your next request. You can do
5
- # this with Authlogic easily, there are 2 parts to this:
6
- #
7
- # 1. Define the timeout threshold:
8
- #
9
- # acts_as_authentic do |c|
10
- # c.logged_in_timeout = 10.minutes # default is 10.minutes
11
- # end
12
- #
13
- # 2. Enable logging out on timeouts
14
- #
15
- # class UserSession < Authlogic::Session::Base
16
- # logout_on_timeout true # default if false
17
- # end
18
- #
19
- # This will require a user to log back in if they are inactive for more than
20
- # 10 minutes. In order for this feature to be used you must have a
21
- # last_request_at datetime column in your table for whatever model you are
22
- # authenticating with.
23
- module Timeout
24
- def self.included(klass)
25
- klass.class_eval do
26
- extend Config
27
- include InstanceMethods
28
- before_persisting :reset_stale_state
29
- after_persisting :enforce_timeout
30
- attr_accessor :stale_record
31
- end
32
- end
33
-
34
- # Configuration for the timeout feature.
35
- module Config
36
- # With acts_as_authentic you get a :logged_in_timeout configuration
37
- # option. If this is set, after this amount of time has passed the user
38
- # will be marked as logged out. Obviously, since web based apps are on a
39
- # per request basis, we have to define a time limit threshold that
40
- # determines when we consider a user to be "logged out". Meaning, if
41
- # they login and then leave the website, when do mark them as logged
42
- # out? I recommend just using this as a fun feature on your website or
43
- # reports, giving you a ballpark number of users logged in and active.
44
- # This is not meant to be a dead accurate representation of a users
45
- # logged in state, since there is really no real way to do this with web
46
- # based apps. Think about a user that logs in and doesn't log out. There
47
- # is no action that tells you that the user isn't technically still
48
- # logged in and active.
49
- #
50
- # That being said, you can use that feature to require a new login if
51
- # their session times out. Similar to how financial sites work. Just set
52
- # this option to true and if your record returns true for stale? then
53
- # they will be required to log back in.
54
- #
55
- # Lastly, UserSession.find will still return a object is the session is
56
- # stale, but you will not get a record. This allows you to determine if
57
- # the user needs to log back in because their session went stale, or
58
- # because they just aren't logged in. Just call
59
- # current_user_session.stale? as your flag.
60
- #
61
- # * <tt>Default:</tt> false
62
- # * <tt>Accepts:</tt> Boolean
63
- def logout_on_timeout(value = nil)
64
- rw_config(:logout_on_timeout, value, false)
65
- end
66
- alias_method :logout_on_timeout=, :logout_on_timeout
67
- end
68
-
69
- # Instance methods for the timeout feature.
70
- module InstanceMethods
71
- # Tells you if the record is stale or not. Meaning the record has timed
72
- # out. This will only return true if you set logout_on_timeout to true
73
- # in your configuration. Basically how a bank website works. If you
74
- # aren't active over a certain period of time your session becomes stale
75
- # and requires you to log back in.
76
- def stale?
77
- if remember_me?
78
- remember_me_expired?
79
- else
80
- !stale_record.nil? || (logout_on_timeout? && record && record.logged_out?)
81
- end
82
- end
83
-
84
- private
85
-
86
- def reset_stale_state
87
- self.stale_record = nil
88
- end
89
-
90
- def enforce_timeout
91
- if stale?
92
- self.stale_record = record
93
- self.record = nil
94
- end
95
- end
96
-
97
- def logout_on_timeout?
98
- self.class.logout_on_timeout == true
99
- end
100
- end
101
- end
102
- end
103
- end
@@ -1,51 +0,0 @@
1
- module Authlogic
2
- module Session
3
- # Allows you to create session with an object. Ex:
4
- #
5
- # UserSession.create(my_user_object)
6
- #
7
- # Be careful with this, because Authlogic is assuming that you have already confirmed that the
8
- # user is who he says he is.
9
- #
10
- # For example, this is the method used to persist the session internally. Authlogic finds the user with
11
- # the persistence token. At this point we know the user is who he says he is, so Authlogic just creates a
12
- # session with the record. This is particularly useful for 3rd party authentication methods, such as
13
- # OpenID. Let that method verify the identity, once it's verified, pass the object and create a session.
14
- module UnauthorizedRecord
15
- def self.included(klass)
16
- klass.class_eval do
17
- attr_accessor :unauthorized_record
18
- validate :validate_by_unauthorized_record, :if => :authenticating_with_unauthorized_record?
19
- end
20
- end
21
-
22
- # Returning meaningful credentials
23
- def credentials
24
- if authenticating_with_unauthorized_record?
25
- details = {}
26
- details[:unauthorized_record] = "<protected>"
27
- details
28
- else
29
- super
30
- end
31
- end
32
-
33
- # Setting the unauthorized record if it exists in the credentials passed.
34
- def credentials=(value)
35
- super
36
- values = value.is_a?(Array) ? value : [value]
37
- self.unauthorized_record = values.first if values.first.class < ::ActiveRecord::Base
38
- end
39
-
40
- private
41
-
42
- def authenticating_with_unauthorized_record?
43
- !unauthorized_record.nil?
44
- end
45
-
46
- def validate_by_unauthorized_record
47
- self.attempted_record = unauthorized_record
48
- end
49
- end
50
- end
51
- end
@@ -1,93 +0,0 @@
1
- module Authlogic
2
- module Session
3
- # Responsible for session validation
4
- module Validation
5
- # The errors in Authlogic work JUST LIKE ActiveRecord. In fact, it uses
6
- # the exact same ActiveRecord errors class. Use it the same way:
7
- #
8
- # class UserSession
9
- # validate :check_if_awesome
10
- #
11
- # private
12
- # def check_if_awesome
13
- # errors.add(:login, "must contain awesome") if login && !login.include?("awesome")
14
- # errors.add(:base, "You must be awesome to log in") unless attempted_record.awesome?
15
- # end
16
- # end
17
- class Errors < (defined?(::ActiveModel) ? ::ActiveModel::Errors : ::ActiveRecord::Errors)
18
- unless defined?(::ActiveModel)
19
- def [](key)
20
- value = super
21
- value.is_a?(Array) ? value : [value].compact
22
- end
23
- end
24
- end
25
-
26
- # You should use this as a place holder for any records that you find
27
- # during validation. The main reason for this is to allow other modules to
28
- # use it if needed. Take the failed_login_count feature, it needs this in
29
- # order to increase the failed login count.
30
- def attempted_record
31
- @attempted_record
32
- end
33
-
34
- # See attempted_record
35
- def attempted_record=(value)
36
- @attempted_record = value
37
- end
38
-
39
- # The errors in Authlogic work JUST LIKE ActiveRecord. In fact, it uses
40
- # the exact same ActiveRecord errors class. Use it the same way:
41
- #
42
- # === Example
43
- #
44
- # class UserSession
45
- # before_validation :check_if_awesome
46
- #
47
- # private
48
- # def check_if_awesome
49
- # errors.add(:login, "must contain awesome") if login && !login.include?("awesome")
50
- # errors.add(:base, "You must be awesome to log in") unless attempted_record.awesome?
51
- # end
52
- # end
53
- def errors
54
- @errors ||= Errors.new(self)
55
- end
56
-
57
- # Determines if the information you provided for authentication is valid
58
- # or not. If there is a problem with the information provided errors will
59
- # be added to the errors object and this method will return false.
60
- def valid?
61
- errors.clear
62
- self.attempted_record = nil
63
-
64
- before_validation
65
- new_session? ? before_validation_on_create : before_validation_on_update
66
- validate
67
- ensure_authentication_attempted
68
-
69
- if errors.empty?
70
- new_session? ? after_validation_on_create : after_validation_on_update
71
- after_validation
72
- end
73
-
74
- save_record(attempted_record)
75
- errors.empty?
76
- end
77
-
78
- private
79
-
80
- def ensure_authentication_attempted
81
- if errors.empty? && attempted_record.nil?
82
- errors.add(
83
- :base,
84
- I18n.t(
85
- 'error_messages.no_authentication_details',
86
- :default => "You did not provide any details for authentication."
87
- )
88
- )
89
- end
90
- end
91
- end
92
- end
93
- end
@@ -1,25 +0,0 @@
1
- require 'test_helper'
2
-
3
- module ActsAsAuthenticTest
4
- class BaseTest < ActiveSupport::TestCase
5
- def test_acts_as_authentic
6
- assert_nothing_raised do
7
- User.acts_as_authentic do
8
- end
9
- end
10
- end
11
-
12
- def test_acts_as_authentic_with_old_config
13
- assert_raise(ArgumentError) do
14
- User.acts_as_authentic({})
15
- end
16
- end
17
-
18
- def test_acts_as_authentic_with_no_table
19
- klass = Class.new(ActiveRecord::Base)
20
- assert_nothing_raised do
21
- klass.acts_as_authentic
22
- end
23
- end
24
- end
25
- end
@@ -1,240 +0,0 @@
1
- # encoding: utf-8
2
- require 'test_helper'
3
-
4
- module ActsAsAuthenticTest
5
- class EmailTest < ActiveSupport::TestCase
6
- GOOD_ASCII_EMAILS = [
7
- "a@a.com",
8
- "damien+test1...etc..@mydomain.com",
9
- "dakota.dux+1@gmail.com",
10
- "dakota.d'ux@gmail.com",
11
- "a&b@c.com",
12
- "someuser@somedomain.travelersinsurance"
13
- ]
14
-
15
- BAD_ASCII_EMAILS = [
16
- "",
17
- "aaaaaaaaaaaaa",
18
- "question?mark@gmail.com",
19
- "backslash@g\\mail.com",
20
- "<script>alert(123);</script>\nnobody@example.com",
21
- "someuser@somedomain.isreallytoolongandimeanreallytoolong"
22
- ]
23
-
24
- # http://en.wikipedia.org/wiki/ISO/IEC_8859-1#Codepage_layout
25
- GOOD_ISO88591_EMAILS = [
26
- "töm.öm@dömain.fi", # https://github.com/binarylogic/authlogic/issues/176
27
- "Pelé@examplé.com", # http://en.wikipedia.org/wiki/Email_address#Internationalization_examples
28
- ]
29
-
30
- BAD_ISO88591_EMAILS = [
31
- "",
32
- "öm(@ava.fi", # L paren
33
- "é)@domain.com", # R paren
34
- "é[@example.com", # L bracket
35
- "question?mark@gmail.com", # question mark
36
- "back\\slash@gmail.com", # backslash
37
- ]
38
-
39
- GOOD_UTF8_EMAILS = [
40
- "δκιμή@παράδεγμα.δοκμή", # http://en.wikipedia.org/wiki/Email_address#Internationalization_examples
41
- "我本@屋企.香港", # http://en.wikipedia.org/wiki/Email_address#Internationalization_examples
42
- "甲斐@黒川.日買", # http://en.wikipedia.org/wiki/Email_address#Internationalization_examples
43
- "чебурша@ящик-с-пельнами.рф", # Contains dashes in domain head
44
- "企斐@黒川.みんな", # https://github.com/binarylogic/authlogic/issues/176#issuecomment-55829320
45
- ]
46
-
47
- BAD_UTF8_EMAILS = [
48
- "",
49
- ".みんな", # https://github.com/binarylogic/authlogic/issues/176#issuecomment-55829320
50
- 'δκιμή@παράδεγμα.δ', # short TLD
51
- "öm(@ava.fi", # L paren
52
- "é)@domain.com", # R paren
53
- "é[@example.com", # L bracket
54
- "δ]@πράιγμα.δοκμή", # R bracket
55
- "我\.香港", # slash
56
- "甲;.日本", # semicolon
57
- "ч:@ящик-с-пельнами.рф", # colon
58
- "斐,.みんな", # comma
59
- "香<.香港", # less than
60
- "我>.香港", # greater than
61
- "我?本@屋企.香港", # question mark
62
- "чебурша@ьн\\ами.рф", # backslash
63
- "user@domain.com%0A<script>alert('hello')</script>"
64
- ]
65
-
66
- def test_email_field_config
67
- assert_equal :email, User.email_field
68
- assert_equal :email, Employee.email_field
69
-
70
- User.email_field = :nope
71
- assert_equal :nope, User.email_field
72
- User.email_field :email
73
- assert_equal :email, User.email_field
74
- end
75
-
76
- def test_validate_email_field_config
77
- assert User.validate_email_field
78
- assert Employee.validate_email_field
79
-
80
- User.validate_email_field = false
81
- refute User.validate_email_field
82
- User.validate_email_field true
83
- assert User.validate_email_field
84
- end
85
-
86
- def test_validates_length_of_email_field_options_config
87
- assert_equal({ :maximum => 100 }, User.validates_length_of_email_field_options)
88
- assert_equal({ :maximum => 100 }, Employee.validates_length_of_email_field_options)
89
-
90
- User.validates_length_of_email_field_options = { :yes => "no" }
91
- assert_equal({ :yes => "no" }, User.validates_length_of_email_field_options)
92
- User.validates_length_of_email_field_options({ :within => 6..100 })
93
- assert_equal({ :within => 6..100 }, User.validates_length_of_email_field_options)
94
- end
95
-
96
- def test_validates_format_of_email_field_options_config
97
- default = {
98
- :with => Authlogic::Regex.email,
99
- :message => proc do
100
- I18n.t(
101
- 'error_messages.email_invalid',
102
- :default => "should look like an email address."
103
- )
104
- end
105
- }
106
- default_message = default.delete(:message).call
107
-
108
- options = User.validates_format_of_email_field_options
109
- message = options.delete(:message)
110
- assert message.is_a?(Proc)
111
- assert_equal default_message, message.call
112
- assert_equal default, options
113
-
114
- options = Employee.validates_format_of_email_field_options
115
- message = options.delete(:message)
116
- assert message.is_a?(Proc)
117
- assert_equal default_message, message.call
118
- assert_equal default, options
119
-
120
- User.validates_format_of_email_field_options = { :yes => "no" }
121
- assert_equal({ :yes => "no" }, User.validates_format_of_email_field_options)
122
- User.validates_format_of_email_field_options default
123
- assert_equal default, User.validates_format_of_email_field_options
124
-
125
- with_email_nonascii = {
126
- :with => Authlogic::Regex.email_nonascii,
127
- :message => Proc.new do
128
- I18n.t(
129
- 'error_messages.email_invalid_international',
130
- :default => "should look like an international email address."
131
- )
132
- end
133
- }
134
- User.validates_format_of_email_field_options = with_email_nonascii
135
- assert_equal(with_email_nonascii, User.validates_format_of_email_field_options)
136
- User.validates_format_of_email_field_options with_email_nonascii
137
- assert_equal with_email_nonascii, User.validates_format_of_email_field_options
138
- end
139
-
140
- def test_deferred_error_message_translation
141
- # ensure we successfully loaded the test locale
142
- assert I18n.available_locales.include?(:lol), "Test locale failed to load"
143
-
144
- I18n.with_locale('lol') do
145
- message = I18n.t("authlogic.error_messages.email_invalid")
146
-
147
- cat = User.new
148
- cat.email = 'meow'
149
- cat.valid?
150
-
151
- # filter duplicate error messages
152
- error = cat.errors[:email]
153
- error = error.first if error.is_a?(Array)
154
-
155
- assert_equal message, error
156
- end
157
- end
158
-
159
- def test_validates_uniqueness_of_email_field_options_config
160
- default = {
161
- :case_sensitive => false,
162
- :scope => Employee.validations_scope,
163
- :if => "#{Employee.email_field}_changed?".to_sym
164
- }
165
- assert_equal default, Employee.validates_uniqueness_of_email_field_options
166
-
167
- Employee.validates_uniqueness_of_email_field_options = { :yes => "no" }
168
- assert_equal({ :yes => "no" }, Employee.validates_uniqueness_of_email_field_options)
169
- Employee.validates_uniqueness_of_email_field_options default
170
- assert_equal default, Employee.validates_uniqueness_of_email_field_options
171
- end
172
-
173
- def test_validates_length_of_email_field
174
- u = User.new
175
- u.email = "a@a.a"
176
- refute u.valid?
177
- refute u.errors[:email].empty?
178
-
179
- u.email = "a@a.com"
180
- refute u.valid?
181
- assert u.errors[:email].empty?
182
- end
183
-
184
- def test_validates_format_of_email_field
185
- u = User.new
186
- u.email = "aaaaaaaaaaaaa"
187
- u.valid?
188
- refute u.errors[:email].empty?
189
-
190
- u.email = "a@a.com"
191
- u.valid?
192
- assert u.errors[:email].empty?
193
-
194
- u.email = "damien+test1...etc..@mydomain.com"
195
- u.valid?
196
- assert u.errors[:email].empty?
197
-
198
- u.email = "dakota.dux+1@gmail.com"
199
- u.valid?
200
- assert u.errors[:email].empty?
201
-
202
- u.email = "dakota.d'ux@gmail.com"
203
- u.valid?
204
- assert u.errors[:email].empty?
205
-
206
- u.email = "<script>alert(123);</script>\nnobody@example.com"
207
- refute u.valid?
208
- refute u.errors[:email].empty?
209
-
210
- u.email = "a&b@c.com"
211
- u.valid?
212
- assert u.errors[:email].empty?
213
- end
214
-
215
- def test_validates_format_of_nonascii_email_field
216
- (GOOD_ASCII_EMAILS + GOOD_ISO88591_EMAILS + GOOD_UTF8_EMAILS).each do |e|
217
- assert e =~ Authlogic::Regex.email_nonascii, "Good email should validate: #{e}"
218
- end
219
-
220
- (BAD_ASCII_EMAILS + BAD_ISO88591_EMAILS + BAD_UTF8_EMAILS).each do |e|
221
- assert e !~ Authlogic::Regex.email_nonascii, "Bad email should not validate: #{e}"
222
- end
223
- end
224
-
225
- def test_validates_uniqueness_of_email_field
226
- u = User.new
227
- u.email = "bjohnson@binarylogic.com"
228
- refute u.valid?
229
- refute u.errors[:email].empty?
230
-
231
- u.email = "BJOHNSON@binarylogic.com"
232
- refute u.valid?
233
- refute u.errors[:email].empty?
234
-
235
- u.email = "a@a.com"
236
- refute u.valid?
237
- assert u.errors[:email].empty?
238
- end
239
- end
240
- end
@@ -1,62 +0,0 @@
1
- require 'test_helper'
2
-
3
- module ActsAsAuthenticTest
4
- class LoggedInStatusTest < ActiveSupport::TestCase
5
- ERROR_MSG = 'Multiple calls to %s should result in different relations'
6
-
7
- def test_logged_in_timeout_config
8
- assert_equal 10.minutes.to_i, User.logged_in_timeout
9
- assert_equal 10.minutes.to_i, Employee.logged_in_timeout
10
-
11
- User.logged_in_timeout = 1.hour
12
- assert_equal 1.hour.to_i, User.logged_in_timeout
13
- User.logged_in_timeout 10.minutes
14
- assert_equal 10.minutes.to_i, User.logged_in_timeout
15
- end
16
-
17
- def test_named_scope_logged_in
18
- # Testing that the scope returned differs, because the time it was called should be
19
- # slightly different. This is an attempt to make sure the scope is lambda wrapped
20
- # so that it is re-evaluated every time its called. My biggest concern is that the
21
- # test happens so fast that the test fails... I just don't know a better way to test it!
22
-
23
- # for rails 5 I've changed the where_values to to_sql to compare
24
-
25
- query1 = User.logged_in.to_sql
26
- sleep 0.1
27
- query2 = User.logged_in.to_sql
28
- assert query1 != query2, ERROR_MSG % '#logged_in'
29
-
30
- assert_equal 0, User.logged_in.count
31
- user = User.first
32
- user.last_request_at = Time.now
33
- user.current_login_at = Time.now
34
- user.save!
35
- assert_equal 1, User.logged_in.count
36
- end
37
-
38
- def test_named_scope_logged_out
39
- # Testing that the scope returned differs, because the time it was called should be
40
- # slightly different. This is an attempt to make sure the scope is lambda wrapped
41
- # so that it is re-evaluated every time its called. My biggest concern is that the
42
- # test happens so fast that the test fails... I just don't know a better way to test it!
43
-
44
- # for rails 5 I've changed the where_values to to_sql to compare
45
-
46
- assert User.logged_in.to_sql != User.logged_out.to_sql, ERROR_MSG % '#logged_out'
47
-
48
- assert_equal 3, User.logged_out.count
49
- User.first.update_attribute(:last_request_at, Time.now)
50
- assert_equal 2, User.logged_out.count
51
- end
52
-
53
- def test_logged_in_logged_out
54
- u = User.first
55
- refute u.logged_in?
56
- assert u.logged_out?
57
- u.last_request_at = Time.now
58
- assert u.logged_in?
59
- refute u.logged_out?
60
- end
61
- end
62
- end