rodauth 2.47.0 → 2.48.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 680f1b9dda9f8dd15399a7a7d1a990ea65299b6d9fb1d42646f9d8661a14b927
4
- data.tar.gz: e7dd526eb3f3d0cfb1d7b470bd2e9d604e6fe7784657fe6449e1d2b9b128c9f3
3
+ metadata.gz: b9a5a66fe82750a982d493fd5e6558b4fef6f94f1761257b3242ff53014eb81b
4
+ data.tar.gz: ecd3f766f3b4d96acd2c7e651d71d1ad0cbb4e60e49db3d5e396a304866b733f
5
5
  SHA512:
6
- metadata.gz: 79f9aa12624e42d2520e01b3a760d1b7bbda370aa7e11fa8987cd3f67a62d15a160ceda4c997afbb636caabc8282f5dfb36689d538e86dc8aea3a178902fb0b3
7
- data.tar.gz: d183b0f9f350b2321c1ee2cb33ad36d789541d77c2a6ba27082f205dd61fabc0566e881a359d9490bfcccfae853d3e2b3acb30eee02884885e3ebe2838fef358
6
+ metadata.gz: 4471aa257cc7761633fca706db570b61cf4315f22d512c90a2419666f2c1bfd97647196a71fa8fd0d85f1cf16cede1beb69dce20ba6d98a29c52727aa6342c37
7
+ data.tar.gz: 0c3ac3e520ab620528ec8dd125cdee8092adea4ad6a2e1c877e30a10598219d0ad8abcb15eb40e1509561587323d8f05f653b68b3d7d112bd2cf44c9a6b8e6e5
@@ -2,11 +2,11 @@
2
2
 
3
3
  require 'argon2'
4
4
 
5
- # :nocov:
5
+ # simplecov:disable
6
6
  if !defined?(Argon2::VERSION) || Argon2::VERSION < '2'
7
7
  raise LoadError, "argon2 version 1.x not supported as it does not support argon2id hashes"
8
8
  end
9
- # :nocov:
9
+ # simplecov:enable
10
10
 
11
11
  module Rodauth
12
12
  Feature.define(:argon2, :Argon2) do
@@ -36,12 +36,12 @@ module Rodauth
36
36
  def argon2_salt_option
37
37
  :salt_do_not_supply
38
38
  end
39
- # :nocov:
39
+ # simplecov:disable
40
40
  else
41
41
  def argon2_salt_option
42
42
  :salt_for_testing_purposes_only
43
43
  end
44
- # :nocov:
44
+ # simplecov:enable
45
45
  end
46
46
 
47
47
  def password_hash_cost
@@ -78,7 +78,7 @@ module Rodauth
78
78
  def argon2_hash_cost
79
79
  { t_cost: 1, m_cost: 5, p_cost: 1 }
80
80
  end
81
- # :nocov:
81
+ # simplecov:disable
82
82
  else
83
83
  def argon2_hash_cost
84
84
  { t_cost: 2, m_cost: 16, p_cost: 1 }
@@ -102,7 +102,7 @@ module Rodauth
102
102
  end
103
103
  end
104
104
  end
105
- # :nocov:
105
+ # simplecov:enable
106
106
 
107
107
  def argon2_hash_algorithm?(hash)
108
108
  hash.start_with?('$argon2id$')
@@ -83,9 +83,9 @@ module Rodauth
83
83
 
84
84
  def audit_log_ds
85
85
  ds = db[audit_logging_table]
86
- # :nocov:
86
+ # simplecov:disable
87
87
  if db.database_type == :postgres
88
- # :nocov:
88
+ # simplecov:enable
89
89
  # For PostgreSQL, use RETURNING NULL. This allows the feature
90
90
  # to be used with INSERT but not SELECT permissions on the
91
91
  # table, useful for audit logging where the database user
@@ -2,7 +2,7 @@
2
2
 
3
3
  begin
4
4
  require "rack/version"
5
- # :nocov:
5
+ # simplecov:disable
6
6
  rescue LoadError
7
7
  require "rack"
8
8
  else
@@ -13,7 +13,7 @@ else
13
13
  require "rack"
14
14
  end
15
15
  end
16
- # :nocov:
16
+ # simplecov:enable
17
17
 
18
18
  module Rodauth
19
19
  Feature.define(:base, :Base) do
@@ -443,9 +443,9 @@ module Rodauth
443
443
  if use_request_specific_csrf_tokens?
444
444
  scope.csrf_tag(path)
445
445
  else
446
- # :nocov:
446
+ # simplecov:disable
447
447
  scope.csrf_tag
448
- # :nocov:
448
+ # simplecov:enable
449
449
  end
450
450
  end
451
451
 
@@ -623,7 +623,7 @@ module Rodauth
623
623
  def convert_response_header_key(key)
624
624
  key
625
625
  end
626
- # :nocov:
626
+ # simplecov:disable
627
627
  else
628
628
  def set_response_header(key, value)
629
629
  response.headers[convert_response_header_key(key)] = value
@@ -650,13 +650,13 @@ module Rodauth
650
650
  mixed_case_headers.fetch(key, key)
651
651
  end
652
652
  end
653
- # :nocov:
653
+ # simplecov:enable
654
654
 
655
655
  if RUBY_VERSION >= '2.1'
656
656
  def button_fixed_locals
657
657
  '(value:, opts:)'
658
658
  end
659
- # :nocov:
659
+ # simplecov:disable
660
660
  else
661
661
  # Work on Ruby 2.0 when using Tilt 2.6+, as Ruby 2.0 does
662
662
  # not support required keyword arguments.
@@ -664,7 +664,7 @@ module Rodauth
664
664
  '(value: nil, opts: nil)'
665
665
  end
666
666
  end
667
- # :nocov:
667
+ # simplecov:enable
668
668
 
669
669
  def missing_recommended_configuration(msg)
670
670
  # RODAUTH3: switch to raise ConfigurationError
@@ -674,7 +674,6 @@ module Rodauth
674
674
  def account_reload(current_retrieval_type, new_retrieval_type)
675
675
  return unless @current_route
676
676
 
677
-
678
677
  if current_retrieval_type == new_retrieval_type
679
678
  warn "account retrieved multiple times during rodauth route with retrieval type #{current_retrieval_type}"
680
679
  else
@@ -828,9 +827,9 @@ module Rodauth
828
827
  when :postgres, :mysql, :mssql
829
828
  true
830
829
  else
831
- # :nocov:
830
+ # simplecov:disable
832
831
  false
833
- # :nocov:
832
+ # simplecov:enable
834
833
  end
835
834
  end
836
835
 
@@ -844,9 +843,9 @@ module Rodauth
844
843
 
845
844
  def function_name(name)
846
845
  if db.database_type == :mssql
847
- # :nocov:
846
+ # simplecov:disable
848
847
  "dbo.#{name}"
849
- # :nocov:
848
+ # simplecov:enable
850
849
  else
851
850
  name
852
851
  end
@@ -864,9 +863,9 @@ module Rodauth
864
863
  elsif use_database_authentication_functions?
865
864
  db.get(Sequel.function(function_name(:rodauth_get_salt), account_id_or_session_value))
866
865
  else
867
- # :nocov:
866
+ # simplecov:disable
868
867
  password_hash_ds.get(password_hash_column)
869
- # :nocov:
868
+ # simplecov:enable
870
869
  end
871
870
  end
872
871
 
@@ -977,9 +976,9 @@ module Rodauth
977
976
  # UniqueConstraintViolation.
978
977
  def unique_constraint_violation_class
979
978
  if db.adapter_scheme == :jdbc && db.database_type == :sqlite
980
- # :nocov:
979
+ # simplecov:disable
981
980
  Sequel::ConstraintViolation
982
- # :nocov:
981
+ # simplecov:enable
983
982
  else
984
983
  Sequel::UniqueConstraintViolation
985
984
  end
@@ -995,9 +994,9 @@ module Rodauth
995
994
  # CURRENT_TIMESTAMP.
996
995
  def set_deadline_value(hash, column, interval)
997
996
  if set_deadline_values?
998
- # :nocov:
997
+ # simplecov:disable
999
998
  hash[column] = Sequel.date_add(Sequel::CURRENT_TIMESTAMP, interval)
1000
- # :nocov:
999
+ # simplecov:enable
1001
1000
  end
1002
1001
  end
1003
1002
 
@@ -1023,9 +1022,9 @@ module Rodauth
1023
1022
  end
1024
1023
  end
1025
1024
 
1026
- # :nocov:
1025
+ # simplecov:disable
1027
1026
  if RUBY_VERSION >= '4.0'
1028
- # :nocov:
1027
+ # simplecov:enable
1029
1028
  def instance_variables_to_inspect
1030
1029
  instance_variables.reject{|v| instance_variable_get(v).nil?}
1031
1030
  end
@@ -59,11 +59,11 @@ module Rodauth
59
59
  database_function_password_match?(:rodauth_previous_password_hash_match, hash_id, password, salt)
60
60
  end
61
61
  else
62
- # :nocov:
62
+ # simplecov:disable
63
63
  previous_password_ds.select_map(previous_password_hash_column).any? do |hash|
64
64
  password_hash_match?(hash, password)
65
65
  end
66
- # :nocov:
66
+ # simplecov:enable
67
67
  end
68
68
 
69
69
  return true unless match
@@ -4,13 +4,14 @@ module Rodauth
4
4
  Feature.define(:http_basic_auth, :HttpBasicAuth) do
5
5
  auth_value_method :http_basic_auth_realm, "protected"
6
6
  auth_value_method :require_http_basic_auth?, false
7
+ auth_value_method :logged_in_fallback_to_http_basic_auth?, true # RODAUTH3: false
7
8
 
8
9
  uses_instance_variables(:@checked_http_basic_auth)
9
10
 
10
11
  def logged_in?
11
12
  ret = super
12
13
 
13
- if !ret && @checked_http_basic_auth.nil?
14
+ if !ret && logged_in_fallback_to_http_basic_auth? && @checked_http_basic_auth.nil?
14
15
  http_basic_auth
15
16
  ret = super
16
17
  end
@@ -33,6 +34,10 @@ module Rodauth
33
34
  end
34
35
  end
35
36
 
37
+ def account_from_session
38
+ @checked_http_basic_auth ? @account : super
39
+ end
40
+
36
41
  def http_basic_auth
37
42
  unless @checked_http_basic_auth.nil?
38
43
  return (@checked_http_basic_auth ? true : nil)
@@ -113,12 +113,12 @@ module Rodauth
113
113
  secrets.compact!
114
114
  secrets
115
115
  end
116
- # :nocov:
116
+ # simplecov:disable
117
117
  else
118
118
  def _jwt_decode_secrets
119
119
  jwt_secret
120
120
  end
121
- # :nocov:
121
+ # simplecov:enable
122
122
  end
123
123
 
124
124
  def jwt_payload
@@ -187,11 +187,11 @@ module Rodauth
187
187
  with_sql(:update_sql, account_login_failures_number_column=>Sequel.expr(account_login_failures_number_column)+1).
188
188
  single_value
189
189
  else
190
- # :nocov:
190
+ # simplecov:disable
191
191
  if ds.update(account_login_failures_number_column=>Sequel.expr(account_login_failures_number_column)+1) > 0
192
192
  ds.get(account_login_failures_number_column)
193
193
  end
194
- # :nocov:
194
+ # simplecov:enable
195
195
  end
196
196
 
197
197
  unless number
@@ -81,10 +81,10 @@ module Rodauth
81
81
  if @existing_password_hash_or_salt
82
82
  existing_expression = if use_database_authentication_functions?
83
83
  Sequel.function(function_name(:rodauth_get_salt), :id)
84
- # :nocov:
84
+ # simplecov:disable
85
85
  else
86
86
  password_hash_column
87
- # :nocov:
87
+ # simplecov:enable
88
88
  end
89
89
  ds = ds.where(existing_expression => @existing_password_hash_or_salt)
90
90
  end
@@ -159,12 +159,12 @@ module Rodauth
159
159
  def login_confirmation_matches?(login, login_confirmation)
160
160
  login.casecmp?(login_confirmation)
161
161
  end
162
- # :nocov:
162
+ # simplecov:disable
163
163
  else
164
164
  def login_confirmation_matches?(login, login_confirmation)
165
165
  login.casecmp(login_confirmation) == 0
166
166
  end
167
- # :nocov:
167
+ # simplecov:enable
168
168
  end
169
169
 
170
170
  def login_meets_length_requirements?(login)
@@ -223,11 +223,11 @@ module Rodauth
223
223
  BCrypt::Engine::MIN_COST
224
224
  end
225
225
  else
226
- # :nocov:
226
+ # simplecov:disable
227
227
  def password_hash_cost
228
228
  BCrypt::Engine::DEFAULT_COST
229
229
  end
230
- # :nocov:
230
+ # simplecov:enable
231
231
  end
232
232
 
233
233
  def extract_password_hash_cost(hash)
@@ -270,17 +270,17 @@ module Rodauth
270
270
  return false unless otp_exists?
271
271
  ot_pass = ot_pass.gsub(/\s+/, '')
272
272
  if drift = otp_drift
273
- # :nocov:
273
+ # simplecov:disable
274
274
  if otp.respond_to?(:verify_with_drift)
275
275
  otp.verify_with_drift(ot_pass, drift)
276
- # :nocov:
276
+ # simplecov:enable
277
277
  else
278
278
  otp.verify(ot_pass, :drift_behind=>drift, :drift_ahead=>drift, :after=>otp_last_use)
279
279
  end
280
- # :nocov:
280
+ # simplecov:disable
281
281
  elsif otp.respond_to?(:verify_with_drift)
282
282
  otp.verify(ot_pass)
283
- # :nocov:
283
+ # simplecov:enable
284
284
  else
285
285
  otp.verify(ot_pass, :after=>otp_last_use)
286
286
  end
@@ -413,11 +413,11 @@ module Rodauth
413
413
  ROTP::Base32.random_base32.downcase
414
414
  end
415
415
  else
416
- # :nocov:
416
+ # simplecov:disable
417
417
  def otp_new_secret
418
418
  ROTP::Base32.random.downcase
419
419
  end
420
- # :nocov:
420
+ # simplecov:enable
421
421
  end
422
422
 
423
423
  def base32_encode(data, length)
@@ -181,9 +181,9 @@ module Rodauth
181
181
  end
182
182
 
183
183
  @otp_unlock_data = nil
184
- # :nocov:
184
+ # simplecov:disable
185
185
  if otp_unlock_data
186
- # :nocov:
186
+ # simplecov:enable
187
187
  if otp_unlock_num_successes >= otp_unlock_auths_required
188
188
  # At least the requisite number of consecutive successful unlock
189
189
  # authentications. Unlock OTP authentication.
@@ -33,9 +33,9 @@ module Rodauth
33
33
  # nothing
34
34
  when nil
35
35
  default_dictionary_file = '/usr/share/dict/words'
36
- # :nocov:
36
+ # simplecov:disable
37
37
  if File.file?(default_dictionary_file)
38
- # :nocov:
38
+ # simplecov:enable
39
39
  words = File.read(default_dictionary_file)
40
40
  end
41
41
  else
@@ -34,8 +34,9 @@ module Rodauth
34
34
  private
35
35
 
36
36
  def new_password_matches_current_password?(_)
37
+ last_password_entry = session[last_password_entry_session_key]
37
38
  if v = super
38
- session.delete(last_password_entry_session_key)
39
+ set_session_value(last_password_entry_session_key, last_password_entry)
39
40
  end
40
41
  v
41
42
  end
@@ -70,9 +70,9 @@ module Rodauth
70
70
  if [remember_remember_param_value, remember_forget_param_value, remember_disable_param_value].include?(remember)
71
71
  transaction do
72
72
  before_remember
73
- # :nocov:
73
+ # simplecov:disable
74
74
  case remember
75
- # :nocov:
75
+ # simplecov:enable
76
76
  when remember_remember_param_value
77
77
  remember_login
78
78
  when remember_forget_param_value
@@ -290,9 +290,9 @@ module Rodauth
290
290
  # it is safe for the second one to use the webauthn user id inserted by the other request.
291
291
  # If there is still no webauthn user id at this point, then we'll just reraise the
292
292
  # exception.
293
- # :nocov:
293
+ # simplecov:disable
294
294
  raise e unless webauthn_id = webauthn_user_ids_ds.get(webauthn_user_ids_webauthn_id_column)
295
- # :nocov:
295
+ # simplecov:enable
296
296
  end
297
297
  end
298
298
 
@@ -419,7 +419,7 @@ module Rodauth
419
419
  name: webauthn_rp_name,
420
420
  )
421
421
  end
422
- # :nocov:
422
+ # simplecov:disable
423
423
  else
424
424
  def webauthn_relying_party
425
425
  WebAuthn::RelyingParty.new(
@@ -428,7 +428,7 @@ module Rodauth
428
428
  name: webauthn_rp_name,
429
429
  )
430
430
  end
431
- # :nocov:
431
+ # simplecov:enable
432
432
  end
433
433
 
434
434
  def webauthn_create_relying_party_opts
@@ -443,7 +443,7 @@ module Rodauth
443
443
  def _override_webauthn_credential_response_verify(webauthn_credential)
444
444
  # no need to override
445
445
  end
446
- # :nocov:
446
+ # simplecov:disable
447
447
  else
448
448
  def webauthn_create_relying_party_opts
449
449
  {:rp => {:name=>webauthn_rp_name, :id=>webauthn_rp_id}}
@@ -466,7 +466,7 @@ module Rodauth
466
466
  super(expected_challenge, expected_origin || origin, **kw)
467
467
  end
468
468
  end
469
- # :nocov:
469
+ # simplecov:enable
470
470
  end
471
471
 
472
472
  def webauthn_modification_authenticated?
@@ -6,7 +6,7 @@ module Rodauth
6
6
  MAJOR = 2
7
7
 
8
8
  # The minor version of Rodauth, updated for new feature releases of Rodauth.
9
- MINOR = 47
9
+ MINOR = 48
10
10
 
11
11
  # The patch version of Rodauth, updated only for bug fixes from the last
12
12
  # feature release.
data/lib/rodauth.rb CHANGED
@@ -38,9 +38,9 @@ module Rodauth
38
38
  when false
39
39
  # nothing
40
40
  when :rack_csrf
41
- # :nocov:
41
+ # simplecov:disable
42
42
  app.plugin :csrf
43
- # :nocov:
43
+ # simplecov:enable
44
44
  else
45
45
  app.plugin :route_csrf
46
46
  end
@@ -186,9 +186,9 @@ module Rodauth
186
186
  feature.module_eval(&block)
187
187
  configuration.def_configuration_methods(feature)
188
188
 
189
- # :nocov:
189
+ # simplecov:disable
190
190
  if constant
191
- # :nocov:
191
+ # simplecov:enable
192
192
  Rodauth.const_set(constant, feature)
193
193
  Rodauth::FeatureConfiguration.const_set(constant, configuration)
194
194
  end
@@ -211,9 +211,9 @@ module Rodauth
211
211
  if RUBY_VERSION >= '2.5'
212
212
  DEPRECATED_ARGS = [{:uplevel=>1}]
213
213
  else
214
- # :nocov:
214
+ # simplecov:disable
215
215
  DEPRECATED_ARGS = []
216
- # :nocov:
216
+ # simplecov:enable
217
217
  end
218
218
  def def_deprecated_alias(new, old)
219
219
  configuration_module_eval do
@@ -348,7 +348,7 @@ module Rodauth
348
348
  auth_private_methods(meth)
349
349
  end
350
350
 
351
- # :nocov:
351
+ # simplecov:disable
352
352
  def auth_cached_method(meth, iv=:"@#{meth}") # :nodoc:
353
353
  # Non-shape friendly historical method.
354
354
  # RODAUTH3: Remove
@@ -363,7 +363,7 @@ module Rodauth
363
363
  alias_method(meth, meth)
364
364
  auth_private_methods(meth)
365
365
  end
366
- # :nocov:
366
+ # simplecov:enable
367
367
 
368
368
  [:notice_flash, :error_flash, :button].each do |meth|
369
369
  define_method(meth) do |v, name=feature_name|
@@ -377,11 +377,11 @@ module Rodauth
377
377
 
378
378
  def initialize(auth, &block)
379
379
  @auth = auth
380
- # :nocov:
380
+ # simplecov:disable
381
381
  # Only for backwards compatibility
382
382
  # RODAUTH3: Remove
383
383
  apply(&block) if block
384
- # :nocov:
384
+ # simplecov:enable
385
385
  end
386
386
 
387
387
  def apply(&block)
@@ -471,12 +471,12 @@ module Rodauth
471
471
 
472
472
  ivs
473
473
  end
474
- # :nocov:
474
+ # simplecov:disable
475
475
  else
476
476
  def make_shape_friendly # :nodoc:
477
477
  end
478
478
  end
479
- # :nocov:
479
+ # simplecov:enable
480
480
  end
481
481
 
482
482
  def self.inherited(subclass)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rodauth
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.47.0
4
+ version: 2.48.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Evans
@@ -407,7 +407,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
407
407
  - !ruby/object:Gem::Version
408
408
  version: '0'
409
409
  requirements: []
410
- rubygems_version: 4.0.16
410
+ rubygems_version: 4.0.20
411
411
  specification_version: 4
412
412
  summary: Authentication and Account Management Framework for Rack Applications
413
413
  test_files: []