Class: Booth::Testing::Userland::RegistrationWithoutPasskey

Inherits:
IncorporationTestCase show all
Defined in:
lib/booth/testing/userland/registration_without_passkey.rb

Instance Method Summary collapse

Methods included from Shortcuts

#assert_logged_in, #assert_logged_out, #assert_userland_view, #clear_cookies, #create_and_onboard, #decrypt_session_cookie, #login_with_passkey, #register_new_passkey, #virtual_authenticators, #visit_namespaced

Instance Method Details

#callObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/booth/testing/userland/registration_without_passkey.rb', line 7

def call
  before_test&.call

  # Register normally

  begin
    # Non-headless Chrome may cause Exception if HTTP status is 4xx
    visit_namespaced controller: :registrations, action: :new
  rescue Playwright::Error => e
    raise unless e.message.include?('ERR_HTTP_RESPONSE_CODE_FAILURE')
  end

  return log { 'Skipping self-registration tests' } if page.status_code == 410

  assert_userland_view controller: :registrations, step: :choose_username

  fill_in :username, with: 'alice'
  click_on :submit

  # Propagate login to other device

  code = nil
  using_session(:other_device) do
    # Login

    visit_namespaced controller: :logins, action: :new

    assert_userland_view controller: :logins, step: :enter_username

    fill_in :username, with: 'alice'
    click_on :submit

    assert_userland_view controller: :logins, step: :remote_session_available

    code = find('[data-booth="code"]').text
  end

  # Redeem remote code

  visit_namespaced controller: :remote_logins, action: :show

  # ------------- SIGNIFICANT TEST -----------------
  # After registering you are immediately logged in.
  # ------------------------------------------------

  assert_userland_view controller: :remote_logins, step: :remote_login

  fill_in :code, with: code
  click_on :submit

  assert_userland_view controller: :remote_logins, step: :remote_solved

  using_session(:other_device) do
    visit current_path

    # -------------------------- SIGNIFICANT TEST ---------------------------
    # You can remote-login even though you don't have any Authenticators yet.
    # -----------------------------------------------------------------------
    assert_logged_in username: 'alice'
  end

  # Try to Login without having any Authenticators

  clear_cookies

  visit_namespaced controller: :logins, action: :new

  assert_userland_view controller: :logins, step: :enter_username

  fill_in :username, with: 'alice'
  click_on :submit

  assert_userland_view controller: :logins, step: :remote_session_available

  click_on :skip

  # ------------------ SIGNIFICANT TEST --------------------
  # If you didn't register any Passkeys, you are locked out.
  # --------------------------------------------------------
  assert_userland_view controller: :logins, step: :no_authenticators

  visit_namespaced controller: :registrations, action: :new

  assert_userland_view controller: :registrations, step: :choose_username

  fill_in :username, with: 'alice'
  click_on :submit

  assert_userland_view controller: :registrations, step: :choose_username

  # ---------------- SIGNIFICANT TEST -------------------
  # You cannot register a username that is already taken.
  # -----------------------------------------------------
  assert_text I18n.t('booth.username_already_exists')
end