Module: Booth::Test::Helpers

Instance Method Summary collapse

Instance Method Details

#assert_logged_in(credential:) ⇒ Object



28
29
30
# File 'lib/booth/test/helpers.rb', line 28

def assert_logged_in(credential:)
  ::Booth::Test::Support::AssertLoggedIn.call(page:, scope:, credential:)
end

#assert_logged_outObject



24
25
26
# File 'lib/booth/test/helpers.rb', line 24

def assert_logged_out
  ::Booth::Test::Support::AssertLoggedOut.call(page:, scope:)
end

#assert_userland_partial(controller:, step:) ⇒ Object



32
33
34
# File 'lib/booth/test/helpers.rb', line 32

def assert_userland_partial(controller:, step:)
  ::Booth::Test::Support::AssertPartial.call(page:, namespace: :userland, controller:, step:)
end

#create_virtual_authenticator(has_user_verification: true) ⇒ Object



57
58
59
60
# File 'lib/booth/test/helpers.rb', line 57

def create_virtual_authenticator(has_user_verification: true)
  setup_virtual_authenticator_environment
  ::Booth::Test::Webauthn::VirtualAuthenticators::Create.call(page:, has_user_verification:)
end

#extract_otp_secret_key_and_generate_codeObject



36
37
38
39
40
41
42
43
# File 'lib/booth/test/helpers.rb', line 36

def extract_otp_secret_key_and_generate_code
  secret_key = page.body.split('?secret=').last.split('&').first
  raise 'Expected an OTP secret but found none' if secret_key.blank?

  code = ::Booth::Models::Credential.new(otp_secret_key: secret_key).otp_code
  Booth.config.logger&.debug(to_s) { "Extracted OTP secret #{secret_key} and derived the code #{code}" }
  code
end

#setup_virtual_authenticator_environmentObject



49
50
51
52
53
54
55
# File 'lib/booth/test/helpers.rb', line 49

def setup_virtual_authenticator_environment
  # For some reason, the Chrome Virtual Authenticator Environment often leaks from one test to the next.
  # All kinds of errors in Webauth only cause one single generic `NotAllowedError` for privacy reasons
  # So it's impossible to debug the actual cause. I just found out after many hours that disabling first, works.
  ::Booth::Test::Webauthn::Disable.call devtools: page.driver.browser.devtools
  ::Booth::Test::Webauthn::Enable.call devtools: page.driver.browser.devtools
end

#soft_reset_sessionObject



45
46
47
# File 'lib/booth/test/helpers.rb', line 45

def soft_reset_session
  ::Booth::Test::Support::SoftResetSession.call(page:)
end