Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle deleted account when checking whether MFA is setup #390

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/rodauth/features/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ def password_hash_using_salt(password, salt)
# note that only the salt is returned.
def get_password_hash
if account_password_hash_column
account![account_password_hash_column]
account[account_password_hash_column] if account!
elsif use_database_authentication_functions?
db.get(Sequel.function(function_name(:rodauth_get_salt), account ? account_id : session_value))
else
Expand Down
3 changes: 1 addition & 2 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -475,8 +475,7 @@ def logout
else
BCrypt::Password.create('0123456789', :cost=>BCrypt::Engine::MIN_COST)
end
table = ENV['RODAUTH_SEPARATE_SCHEMA'] ? Sequel[:rodauth_test_password][:account_password_hashes] : :account_password_hashes
DB[table].insert(:id=>DB[:accounts].insert(:email=>'[email protected]', :status_id=>2, :ph=>hash), :password_hash=>hash)
DB[PASSWORD_HASH_TABLE].insert(:id=>DB[:accounts].insert(:email=>'[email protected]', :status_id=>2, :ph=>hash), :password_hash=>hash)
super(&block)
end
end
Expand Down
26 changes: 25 additions & 1 deletion spec/two_factor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require 'rotp'

describe 'Rodauth OTP feature' do
describe 'Rodauth two factor feature' do
secret_length = (ROTP::Base32.respond_to?(:random_base32) ? ROTP::Base32.random_base32 : ROTP::Base32.random).length

def reset_otp_last_use
Expand Down Expand Up @@ -714,6 +714,30 @@ def reset_otp_last_use
page.title.must_equal 'Authenticate Using Additional Factor'
end

it "should handle deleted account when checking rodauth.two_factor_authentication_setup?" do
rodauth do
enable :login, :logout, :two_factor_base
account_password_hash_column :ph
end
roda do |r|
r.rodauth
r.get('setup'){rodauth.two_factor_authentication_setup?.inspect}
""
end

visit '/setup'
page.body.must_equal 'false'

login
visit '/setup'
page.body.must_equal 'false'

DB[PASSWORD_HASH_TABLE].delete
DB[:accounts].delete
visit '/setup'
page.body.must_equal 'false'
end

it "should allow two factor authentication setup, login, removal without recovery" do
rodauth do
enable :login, :logout, :otp
Expand Down