authlogic 4.1.0 → 4.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +0 -4
  4. data/.rubocop_todo.yml +32 -33
  5. data/CHANGELOG.md +15 -0
  6. data/Rakefile +2 -4
  7. data/authlogic.gemspec +2 -1
  8. data/lib/authlogic/acts_as_authentic/base.rb +13 -13
  9. data/lib/authlogic/acts_as_authentic/logged_in_status.rb +3 -3
  10. data/lib/authlogic/acts_as_authentic/login.rb +4 -4
  11. data/lib/authlogic/acts_as_authentic/password.rb +99 -98
  12. data/lib/authlogic/acts_as_authentic/persistence_token.rb +3 -3
  13. data/lib/authlogic/acts_as_authentic/queries/find_with_case.rb +32 -32
  14. data/lib/authlogic/acts_as_authentic/restful_authentication.rb +14 -14
  15. data/lib/authlogic/acts_as_authentic/session_maintenance.rb +60 -60
  16. data/lib/authlogic/acts_as_authentic/single_access_token.rb +6 -6
  17. data/lib/authlogic/authenticates_many/association.rb +3 -3
  18. data/lib/authlogic/config.rb +9 -9
  19. data/lib/authlogic/controller_adapters/abstract_adapter.rb +28 -8
  20. data/lib/authlogic/controller_adapters/rails_adapter.rb +3 -3
  21. data/lib/authlogic/crypto_providers/aes256.rb +20 -20
  22. data/lib/authlogic/crypto_providers/bcrypt.rb +8 -8
  23. data/lib/authlogic/crypto_providers/scrypt.rb +8 -8
  24. data/lib/authlogic/session/activation.rb +3 -3
  25. data/lib/authlogic/session/brute_force_protection.rb +32 -32
  26. data/lib/authlogic/session/callbacks.rb +49 -35
  27. data/lib/authlogic/session/cookies.rb +58 -49
  28. data/lib/authlogic/session/foundation.rb +3 -3
  29. data/lib/authlogic/session/id.rb +9 -4
  30. data/lib/authlogic/session/klass.rb +6 -6
  31. data/lib/authlogic/session/magic_columns.rb +5 -17
  32. data/lib/authlogic/session/params.rb +3 -0
  33. data/lib/authlogic/session/password.rb +105 -104
  34. data/lib/authlogic/session/perishable_token.rb +5 -5
  35. data/lib/authlogic/session/persistence.rb +5 -4
  36. data/lib/authlogic/session/priority_record.rb +8 -8
  37. data/lib/authlogic/session/scopes.rb +23 -23
  38. data/lib/authlogic/session/timeout.rb +11 -11
  39. data/lib/authlogic/session/unauthorized_record.rb +6 -6
  40. data/lib/authlogic/session/validation.rb +9 -9
  41. data/lib/authlogic/test_case.rb +5 -0
  42. data/lib/authlogic/test_case/mock_request.rb +2 -2
  43. data/lib/authlogic/version.rb +4 -3
  44. data/test/acts_as_authentic_test/password_test.rb +23 -23
  45. data/test/test_helper.rb +96 -93
  46. metadata +18 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0699061fb6cde9b757291441d3cf7a6621c8f9db98904d98b2864f93297fd0ea
4
- data.tar.gz: c95d14549fa390d839b165a223c887562f7a48bd06f545e93faff8e2617207f4
3
+ metadata.gz: c0ca1b9d96dbb4d00cf0cad78c6a10bfbc8f893c931834eb560e2fa1a2db10b5
4
+ data.tar.gz: 274d571aafec37f865edd29222343e88545877ef79caade6f87bfca9b27f50da
5
5
  SHA512:
6
- metadata.gz: 0cf20428fcff91acadf3724ce63cc30e526019a8cc12d59d7d16e00c9c9e8e15cd3a62208f1ad641bcec0da54456809e98f2594df151826fca85de59aae1f651
7
- data.tar.gz: b5d8d535a6633ed8b33805f54e70200e406d9a39061cc87f50852c74df99f3ac33bfb25fbcd47c16eda4467cd02a7f159efb5c35b1ef51f5520b93352b6c2b1d
6
+ metadata.gz: 96c6ea47f5a5b6f98e4fadc427d0e1bbfa6b86f2d4a250757270fa375e0cda5a22a5e4fb7704a14e74a63ba87ef617a2adc489ea7ced107864635f98fa736c35
7
+ data.tar.gz: 7c3905f05ebb0c4e2694a57ef5e5c04a8cb2c2de97f8b4af965bbf5b41f71aba63646c9fcedc44d3e2916b178855ff56296ca97ecdd151a24d1abb72cc3133df
data/.gitignore CHANGED
@@ -1,5 +1,6 @@
1
1
  .DS_Store
2
2
  .swp
3
+ *.gem
3
4
  *.log
4
5
  *.sqlite3
5
6
  pkg/*
@@ -28,10 +28,6 @@ AllCops:
28
28
  Layout/AlignParameters:
29
29
  EnforcedStyle: with_fixed_indentation
30
30
 
31
- # This project uses rails-style method indentation, ie. indent after `private`.
32
- Layout/IndentationConsistency:
33
- EnforcedStyle: rails
34
-
35
31
  Layout/MultilineMethodCallIndentation:
36
32
  EnforcedStyle: indented
37
33
 
@@ -1,25 +1,18 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2017-11-08 17:51:32 -0500 using RuboCop version 0.51.0.
3
+ # on 2018-05-22 23:50:03 -0400 using RuboCop version 0.56.0.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
7
7
  # versions of RuboCop, may require this file to be generated again.
8
8
 
9
- # Offense count: 58
9
+ # Offense count: 10
10
10
  Metrics/AbcSize:
11
- Max: 28
11
+ Max: 18.5
12
12
 
13
- # Offense count: 3
14
- Metrics/PerceivedComplexity:
15
- Max: 8
16
-
17
- Naming/MemoizedInstanceVariableName:
18
- Enabled: false
19
-
20
- # Offense count: 60
13
+ # Offense count: 59
21
14
  # Cop supports --auto-correct.
22
- # Configuration parameters: EnforcedStyle, SupportedStyles.
15
+ # Configuration parameters: EnforcedStyle.
23
16
  # SupportedStyles: prefer_alias, prefer_alias_method
24
17
  Style/Alias:
25
18
  Enabled: false
@@ -29,38 +22,44 @@ Style/ClassVars:
29
22
  Exclude:
30
23
  - 'lib/authlogic/i18n.rb'
31
24
 
32
- # Offense count: 31
25
+ # Offense count: 22
33
26
  Style/Documentation:
34
27
  Exclude:
35
- # Permanent exclusion
36
- - test/**/*
28
+ # Permanent
29
+ - 'test/**/*'
37
30
 
38
- # Temporary exclustions
39
- - lib/authlogic/config.rb
40
- - lib/authlogic/controller_adapters/sinatra_adapter.rb
41
- - lib/authlogic/crypto_providers.rb
42
- - lib/authlogic/i18n/translator.rb
43
- - lib/authlogic/session/activation.rb
44
- - lib/authlogic/session/active_record_trickery.rb
45
- - lib/authlogic/session/existence.rb
46
- - lib/authlogic/session/foundation.rb
47
- - lib/authlogic/session/klass.rb
48
- - lib/authlogic/session/persistence.rb
49
- - lib/authlogic/session/scopes.rb
50
- - lib/authlogic/test_case.rb
51
- - lib/authlogic/test_case/mock_cookie_jar.rb
52
- - lib/authlogic/version.rb
31
+ # TODO
32
+ - 'lib/authlogic/config.rb'
33
+ - 'lib/authlogic/controller_adapters/sinatra_adapter.rb'
34
+ - 'lib/authlogic/crypto_providers.rb'
35
+ - 'lib/authlogic/i18n/translator.rb'
36
+ - 'lib/authlogic/session/activation.rb'
37
+ - 'lib/authlogic/session/active_record_trickery.rb'
38
+ - 'lib/authlogic/session/existence.rb'
39
+ - 'lib/authlogic/session/foundation.rb'
40
+ - 'lib/authlogic/session/klass.rb'
41
+ - 'lib/authlogic/session/persistence.rb'
42
+ - 'lib/authlogic/session/scopes.rb'
43
+ - 'lib/authlogic/test_case.rb'
44
+ - 'lib/authlogic/test_case/mock_cookie_jar.rb'
45
+ - 'lib/authlogic/version.rb'
53
46
 
54
47
  # Offense count: 4
55
- Style/MethodMissing:
48
+ Style/MethodMissingSuper:
56
49
  Exclude:
57
50
  - 'lib/authlogic/controller_adapters/abstract_adapter.rb'
58
51
  - 'lib/authlogic/controller_adapters/sinatra_adapter.rb'
59
52
  - 'lib/authlogic/test_case/mock_request.rb'
60
53
 
61
- # Offense count: 7
54
+ # Offense count: 3
55
+ Style/MissingRespondToMissing:
56
+ Exclude:
57
+ - 'lib/authlogic/controller_adapters/sinatra_adapter.rb'
58
+ - 'lib/authlogic/test_case/mock_request.rb'
59
+
60
+ # Offense count: 10
62
61
  # Cop supports --auto-correct.
63
- # Configuration parameters: SupportedStyles.
62
+ # Configuration parameters: .
64
63
  # SupportedStyles: compact, exploded
65
64
  Style/RaiseArgs:
66
65
  EnforcedStyle: compact
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
6
+ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
7
+
3
8
  ## Unreleased
4
9
 
5
10
  * Breaking Changes
@@ -9,6 +14,16 @@
9
14
  * Fixed
10
15
  * None
11
16
 
17
+ ## 4.1.1 (2018-05-23)
18
+
19
+ * Breaking Changes
20
+ * None
21
+ * Added
22
+ * None
23
+ * Fixed
24
+ * [#606](https://github.com/binarylogic/authlogic/pull/606) - Interpreter
25
+ warnings about undefined instance variables
26
+
12
27
  ## 4.1.0 (2018-04-24)
13
28
 
14
29
  * Breaking Changes
data/Rakefile CHANGED
@@ -9,10 +9,8 @@ Rake::TestTask.new(:test) do |test|
9
9
  test.pattern = "test/**/*_test.rb"
10
10
  test.verbose = false
11
11
 
12
- # Set interpreter warning level to 1 (medium). Level 2 produces hundreds of warnings
13
- # about uninitialized instance variables.
14
- # TODO: Find a good way to deal with the level 2 warnings.
15
- test.ruby_opts += ["-W1"]
12
+ # Set interpreter warning level to 2 (verbose)
13
+ test.ruby_opts += ["-W2"]
16
14
  end
17
15
 
18
16
  require "rubocop/rake_task"
@@ -27,7 +27,8 @@ require "authlogic/version"
27
27
  s.add_dependency "scrypt", ">= 1.2", "< 4.0"
28
28
  s.add_development_dependency "bcrypt", "~> 3.1"
29
29
  s.add_development_dependency "byebug", "~> 10.0"
30
- s.add_development_dependency "rubocop", "~> 0.54.0"
30
+ s.add_development_dependency "minitest-reporters", "~> 1.2"
31
+ s.add_development_dependency "rubocop", "~> 0.56.0"
31
32
  s.add_development_dependency "timecop", "~> 0.7"
32
33
 
33
34
  s.files = `git ls-files`.split("\n")
@@ -76,23 +76,23 @@ module Authlogic
76
76
 
77
77
  private
78
78
 
79
- def db_setup?
80
- column_names
81
- true
82
- rescue StandardError
83
- false
84
- end
79
+ def db_setup?
80
+ column_names
81
+ true
82
+ rescue StandardError
83
+ false
84
+ end
85
85
 
86
- def first_column_to_exist(*columns_to_check)
87
- if db_setup?
88
- columns_to_check.each do |column_name|
89
- if column_names.include?(column_name.to_s)
90
- return column_name.to_sym
91
- end
86
+ def first_column_to_exist(*columns_to_check)
87
+ if db_setup?
88
+ columns_to_check.each do |column_name|
89
+ if column_names.include?(column_name.to_s)
90
+ return column_name.to_sym
92
91
  end
93
92
  end
94
- columns_to_check.first && columns_to_check.first.to_sym
95
93
  end
94
+ columns_to_check.first && columns_to_check.first.to_sym
95
+ end
96
96
  end
97
97
  end
98
98
  end
@@ -73,9 +73,9 @@ module Authlogic
73
73
 
74
74
  private
75
75
 
76
- def logged_in_timeout
77
- self.class.logged_in_timeout
78
- end
76
+ def logged_in_timeout
77
+ self.class.logged_in_timeout
78
+ end
79
79
  end
80
80
  end
81
81
  end
@@ -186,10 +186,10 @@ module Authlogic
186
186
 
187
187
  private
188
188
 
189
- # @api private
190
- def find_with_case(field, value, sensitive)
191
- Queries::FindWithCase.new(self, field, value, sensitive).execute
192
- end
189
+ # @api private
190
+ def find_with_case(field, value, sensitive)
191
+ Queries::FindWithCase.new(self, field, value, sensitive).execute
192
+ end
193
193
  end
194
194
 
195
195
  # All methods relating to the login field
@@ -303,6 +303,7 @@ module Authlogic
303
303
  module InstanceMethods
304
304
  # The password
305
305
  def password
306
+ return nil unless defined?(@password)
306
307
  @password
307
308
  end
308
309
 
@@ -376,124 +377,124 @@ module Authlogic
376
377
 
377
378
  private
378
379
 
379
- def crypted_password_to_validate_against(check_against_database)
380
- if check_against_database && send("#{crypted_password_field}_changed?")
381
- send("#{crypted_password_field}_was")
382
- else
383
- send(crypted_password_field)
384
- end
380
+ def crypted_password_to_validate_against(check_against_database)
381
+ if check_against_database && send("#{crypted_password_field}_changed?")
382
+ send("#{crypted_password_field}_was")
383
+ else
384
+ send(crypted_password_field)
385
385
  end
386
+ end
386
387
 
387
- def check_passwords_against_database?
388
- self.class.check_passwords_against_database == true
389
- end
388
+ def check_passwords_against_database?
389
+ self.class.check_passwords_against_database == true
390
+ end
390
391
 
391
- def crypto_providers
392
- [crypto_provider] + transition_from_crypto_providers
393
- end
392
+ def crypto_providers
393
+ [crypto_provider] + transition_from_crypto_providers
394
+ end
394
395
 
395
- # Returns an array of arguments to be passed to a crypto provider, either its
396
- # `matches?` or its `encrypt` method.
397
- def encrypt_arguments(raw_password, check_against_database, arguments_type = nil)
398
- salt = nil
399
- if password_salt_field
400
- salt =
401
- if check_against_database && send("#{password_salt_field}_changed?")
402
- send("#{password_salt_field}_was")
403
- else
404
- send(password_salt_field)
405
- end
406
- end
396
+ # Returns an array of arguments to be passed to a crypto provider, either its
397
+ # `matches?` or its `encrypt` method.
398
+ def encrypt_arguments(raw_password, check_against_database, arguments_type = nil)
399
+ salt = nil
400
+ if password_salt_field
401
+ salt =
402
+ if check_against_database && send("#{password_salt_field}_changed?")
403
+ send("#{password_salt_field}_was")
404
+ else
405
+ send(password_salt_field)
406
+ end
407
+ end
407
408
 
408
- case arguments_type
409
- when :restful_authentication
410
- [REST_AUTH_SITE_KEY, salt, raw_password, REST_AUTH_SITE_KEY].compact
411
- when nil
412
- [raw_password, salt].compact
413
- else
414
- raise "Invalid encryptor arguments_type: #{arguments_type}"
415
- end
409
+ case arguments_type
410
+ when :restful_authentication
411
+ [REST_AUTH_SITE_KEY, salt, raw_password, REST_AUTH_SITE_KEY].compact
412
+ when nil
413
+ [raw_password, salt].compact
414
+ else
415
+ raise "Invalid encryptor arguments_type: #{arguments_type}"
416
416
  end
417
+ end
417
418
 
418
- # Given `encryptor`, does `attempted_password` match the `crypted` password?
419
- def encryptor_matches?(
420
- crypted,
421
- encryptor,
422
- index,
419
+ # Given `encryptor`, does `attempted_password` match the `crypted` password?
420
+ def encryptor_matches?(
421
+ crypted,
422
+ encryptor,
423
+ index,
424
+ attempted_password,
425
+ check_against_database
426
+ )
427
+ # The arguments_type for the transitioning from restful_authentication
428
+ acting_restful = act_like_restful_authentication? && index.zero?
429
+ transitioning = transition_from_restful_authentication? &&
430
+ index > 0 &&
431
+ encryptor == Authlogic::CryptoProviders::Sha1
432
+ restful = acting_restful || transitioning
433
+ arguments_type = restful ? :restful_authentication : nil
434
+ encryptor_args = encrypt_arguments(
423
435
  attempted_password,
424
- check_against_database
436
+ check_against_database,
437
+ arguments_type
425
438
  )
426
- # The arguments_type for the transitioning from restful_authentication
427
- acting_restful = act_like_restful_authentication? && index.zero?
428
- transitioning = transition_from_restful_authentication? &&
429
- index > 0 &&
430
- encryptor == Authlogic::CryptoProviders::Sha1
431
- restful = acting_restful || transitioning
432
- arguments_type = restful ? :restful_authentication : nil
433
- encryptor_args = encrypt_arguments(
434
- attempted_password,
435
- check_against_database,
436
- arguments_type
437
- )
438
- encryptor.matches?(crypted, *encryptor_args)
439
- end
439
+ encryptor.matches?(crypted, *encryptor_args)
440
+ end
440
441
 
441
- # Determines if we need to transition the password.
442
- #
443
- # - If the index > 0 then we are using an "transition from" crypto
444
- # provider.
445
- # - If the encryptor has a cost and the cost it outdated.
446
- # - If we aren't using database values
447
- # - If we are using database values, only if the password hasn't
448
- # changed so we don't overwrite any changes
449
- def transition_password?(index, encryptor, check_against_database)
442
+ # Determines if we need to transition the password.
443
+ #
444
+ # - If the index > 0 then we are using an "transition from" crypto
445
+ # provider.
446
+ # - If the encryptor has a cost and the cost it outdated.
447
+ # - If we aren't using database values
448
+ # - If we are using database values, only if the password hasn't
449
+ # changed so we don't overwrite any changes
450
+ def transition_password?(index, encryptor, check_against_database)
451
+ (
452
+ index > 0 ||
453
+ (encryptor.respond_to?(:cost_matches?) &&
454
+ !encryptor.cost_matches?(send(crypted_password_field)))
455
+ ) &&
450
456
  (
451
- index > 0 ||
452
- (encryptor.respond_to?(:cost_matches?) &&
453
- !encryptor.cost_matches?(send(crypted_password_field)))
454
- ) &&
455
- (
456
- !check_against_database ||
457
- !send("#{crypted_password_field}_changed?")
458
- )
459
- end
457
+ !check_against_database ||
458
+ !send("#{crypted_password_field}_changed?")
459
+ )
460
+ end
460
461
 
461
- def transition_password(attempted_password)
462
- self.password = attempted_password
463
- save(validate: false)
464
- end
462
+ def transition_password(attempted_password)
463
+ self.password = attempted_password
464
+ save(validate: false)
465
+ end
465
466
 
466
- def require_password?
467
- new_record? || password_changed? || send(crypted_password_field).blank?
468
- end
467
+ def require_password?
468
+ new_record? || password_changed? || send(crypted_password_field).blank?
469
+ end
469
470
 
470
- def ignore_blank_passwords?
471
- self.class.ignore_blank_passwords == true
472
- end
471
+ def ignore_blank_passwords?
472
+ self.class.ignore_blank_passwords == true
473
+ end
473
474
 
474
- def password_changed?
475
- @password_changed == true
476
- end
475
+ def password_changed?
476
+ defined?(@password_changed) && @password_changed == true
477
+ end
477
478
 
478
- def reset_password_changed
479
- @password_changed = nil
480
- end
479
+ def reset_password_changed
480
+ @password_changed = nil
481
+ end
481
482
 
482
- def crypted_password_field
483
- self.class.crypted_password_field
484
- end
483
+ def crypted_password_field
484
+ self.class.crypted_password_field
485
+ end
485
486
 
486
- def password_salt_field
487
- self.class.password_salt_field
488
- end
487
+ def password_salt_field
488
+ self.class.password_salt_field
489
+ end
489
490
 
490
- def crypto_provider
491
- self.class.crypto_provider
492
- end
491
+ def crypto_provider
492
+ self.class.crypto_provider
493
+ end
493
494
 
494
- def transition_from_crypto_providers
495
- self.class.transition_from_crypto_providers
496
- end
495
+ def transition_from_crypto_providers
496
+ self.class.transition_from_crypto_providers
497
+ end
497
498
  end
498
499
  end
499
500
  end