authlogic 3.8.0 → 6.0.0

Sign up to get free protection for your applications and to get access to all the features.
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
data/test/test_helper.rb DELETED
@@ -1,233 +0,0 @@
1
- require "rubygems"
2
- require "minitest/autorun"
3
- require "active_record"
4
- require "active_record/fixtures"
5
- require "timecop"
6
- require "i18n"
7
-
8
- I18n.load_path << File.dirname(__FILE__) + '/i18n/lol.yml'
9
-
10
- # ActiveRecord::Schema.verbose = false
11
- ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
12
- logger = Logger.new(STDOUT)
13
- logger.level = Logger::FATAL
14
- ActiveRecord::Base.logger = logger
15
-
16
- if (ActiveRecord::VERSION::STRING < '4.1')
17
- ActiveRecord::Base.configurations = true
18
- end
19
-
20
- if ActiveSupport.respond_to?(:test_order)
21
- ActiveSupport.test_order = :sorted
22
- end
23
-
24
- ActiveRecord::Base.default_timezone = :local
25
- ActiveRecord::Schema.define(:version => 1) do
26
- create_table :companies do |t|
27
- t.datetime :created_at
28
- t.datetime :updated_at
29
- t.string :name
30
- t.boolean :active
31
- end
32
-
33
- create_table :projects do |t|
34
- t.datetime :created_at
35
- t.datetime :updated_at
36
- t.string :name
37
- end
38
-
39
- create_table :projects_users, :id => false do |t|
40
- t.integer :project_id
41
- t.integer :user_id
42
- end
43
-
44
- create_table :users do |t|
45
- t.datetime :created_at
46
- t.datetime :updated_at
47
- t.integer :lock_version, :default => 0
48
- t.integer :company_id
49
- t.string :login
50
- t.string :crypted_password
51
- t.string :password_salt
52
- t.string :persistence_token
53
- t.string :single_access_token
54
- t.string :perishable_token
55
- t.string :email
56
- t.string :first_name
57
- t.string :last_name
58
- t.integer :login_count, :default => 0, :null => false
59
- t.integer :failed_login_count, :default => 0, :null => false
60
- t.datetime :last_request_at
61
- t.datetime :current_login_at
62
- t.datetime :last_login_at
63
- t.string :current_login_ip
64
- t.string :last_login_ip
65
- t.boolean :active, :default => true
66
- t.boolean :approved, :default => true
67
- t.boolean :confirmed, :default => true
68
- end
69
-
70
- create_table :employees do |t|
71
- t.datetime :created_at
72
- t.datetime :updated_at
73
- t.integer :company_id
74
- t.string :email
75
- t.string :crypted_password
76
- t.string :password_salt
77
- t.string :persistence_token
78
- t.string :first_name
79
- t.string :last_name
80
- t.integer :login_count, :default => 0, :null => false
81
- t.datetime :last_request_at
82
- t.datetime :current_login_at
83
- t.datetime :last_login_at
84
- t.string :current_login_ip
85
- t.string :last_login_ip
86
- end
87
-
88
- create_table :affiliates do |t|
89
- t.datetime :created_at
90
- t.datetime :updated_at
91
- t.integer :company_id
92
- t.string :username
93
- t.string :pw_hash
94
- t.string :pw_salt
95
- t.string :persistence_token
96
- end
97
-
98
- create_table :ldapers do |t|
99
- t.datetime :created_at
100
- t.datetime :updated_at
101
- t.string :ldap_login
102
- t.string :persistence_token
103
- end
104
- end
105
-
106
- require_relative '../lib/authlogic' unless defined?(Authlogic)
107
- require_relative '../lib/authlogic/test_case'
108
- require_relative 'libs/project'
109
- require_relative 'libs/affiliate'
110
- require_relative 'libs/employee'
111
- require_relative 'libs/employee_session'
112
- require_relative 'libs/ldaper'
113
- require_relative 'libs/user'
114
- require_relative 'libs/user_session'
115
- require_relative 'libs/company'
116
-
117
- # Recent change, 2017-10-23: We had used a 54-letter string here. In the default
118
- # encoding, UTF-8, that's 54 bytes, which is clearly incorrect for an algorithm
119
- # with a 256-bit key, but I guess it worked. With the release of ruby 2.4 (and
120
- # thus openssl gem 2.0), it is more strict, and must be exactly 32 bytes.
121
- Authlogic::CryptoProviders::AES256.key = ::OpenSSL::Random.random_bytes(32)
122
-
123
- class ActiveSupport::TestCase
124
- include ActiveRecord::TestFixtures
125
- self.fixture_path = File.dirname(__FILE__) + "/fixtures"
126
-
127
- # use_transactional_fixtures= is deprecated and will be removed from Rails 5.1
128
- # (use use_transactional_tests= instead)
129
- if respond_to?(:use_transactional_tests=)
130
- self.use_transactional_tests = false
131
- else
132
- self.use_transactional_fixtures = false
133
- end
134
-
135
- self.use_instantiated_fixtures = false
136
- self.pre_loaded_fixtures = false
137
- fixtures :all
138
- setup :activate_authlogic
139
- setup :config_setup
140
- teardown :config_teardown
141
- teardown { Timecop.return } # for tests that need to freeze the time
142
-
143
- private
144
-
145
- # Many of the tests change Authlogic config for the test models. Some tests
146
- # were not resetting the config after tests, which didn't surface as broken
147
- # tests until Rails 4.1 was added for testing. This ensures that all the
148
- # models start tests with their original config.
149
- def config_setup
150
- [Project, Affiliate, Employee, EmployeeSession, Ldaper, User, UserSession, Company].each do |model|
151
- model.class_attribute :original_acts_as_authentic_config unless model.respond_to?(:original_acts_as_authentic_config)
152
- model.original_acts_as_authentic_config = model.acts_as_authentic_config
153
- end
154
- end
155
-
156
- def config_teardown
157
- [Project, Affiliate, Employee, EmployeeSession, Ldaper, User, UserSession, Company].each do |model|
158
- model.acts_as_authentic_config = model.original_acts_as_authentic_config
159
- end
160
- end
161
-
162
- def password_for(user)
163
- case user
164
- when users(:ben)
165
- "benrocks"
166
- when users(:zack)
167
- "zackrocks"
168
- when users(:aaron)
169
- "aaronrocks"
170
- end
171
- end
172
-
173
- def http_basic_auth_for(user = nil, &block)
174
- unless user.blank?
175
- controller.http_user = user.login
176
- controller.http_password = password_for(user)
177
- end
178
- yield
179
- controller.http_user = controller.http_password = controller.realm = nil
180
- end
181
-
182
- def set_cookie_for(user)
183
- controller.cookies["user_credentials"] = { :value => "#{user.persistence_token}::#{user.id}", :expires => nil }
184
- end
185
-
186
- def unset_cookie
187
- controller.cookies["user_credentials"] = nil
188
- end
189
-
190
- def set_params_for(user)
191
- controller.params["user_credentials"] = user.single_access_token
192
- end
193
-
194
- def unset_params
195
- controller.params["user_credentials"] = nil
196
- end
197
-
198
- def set_request_content_type(type)
199
- controller.request_content_type = type
200
- end
201
-
202
- def unset_request_content_type
203
- controller.request_content_type = nil
204
- end
205
-
206
- def session_credentials_prefix(scope_record)
207
- if scope_record.nil?
208
- ""
209
- else
210
- format(
211
- "%s_%d_",
212
- scope_record.class.model_name.name.underscore,
213
- scope_record.id
214
- )
215
- end
216
- end
217
-
218
- # Sets the session variables that `record` (eg. a `User`) would have after
219
- # logging in.
220
- #
221
- # If `record` belongs to an `authenticates_many` association that uses the
222
- # `scope_cookies` option, then a `scope_record` can be provided.
223
- def set_session_for(record, scope_record = nil)
224
- prefix = session_credentials_prefix(scope_record)
225
- record_class_name = record.class.model_name.name.underscore
226
- controller.session["#{prefix}#{record_class_name}_credentials"] = record.persistence_token
227
- controller.session["#{prefix}#{record_class_name}_credentials_id"] = record.id
228
- end
229
-
230
- def unset_session
231
- controller.session["user_credentials"] = controller.session["user_credentials_id"] = nil
232
- end
233
- end