Class: Booth::Testing::Userland::LoginRemotely

Inherits:
IncorporationTestCase show all
Defined in:
lib/booth/testing/userland/login_remotely.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
# File 'lib/booth/testing/userland/login_remotely.rb', line 7

def call
  before_test&.call

  create_and_onboard(username: 'alice')
  virtual_authenticators.create
  register_new_passkey(username: 'alice')

  visit_namespaced controller: :remote_logins, action: :show

  # ---------------- SIGNIFICANT TEST ------------------
  # Can only enter a code when there is a pending Remote
  # ----------------------------------------------------
  assert_userland_view controller: :remote_logins, step: :no_remote

  code = nil
  using_session(:other_device) do
    # Login on other device

    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

  assert_userland_view controller: :remote_logins, step: :remote_login

  fill_in :code, with: code
  click_on :submit

  # ------ SIGNIFICANT TEST ------
  # Remote logins can be redeemed.
  # ------------------------------
  assert_userland_view controller: :remote_logins, step: :remote_solved

  using_session(:other_device) do
    visit current_path

    # ------------ SIGNIFICANT TEST --------------
    # Webauth sudo is required after remote login.
    # --------------------------------------------
    assert_logged_in username: 'alice'
  end

  using_session(:yet_another_device) do
    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

    ::Booth::Models::Remote.sole.update!(created_at: 21.minutes.ago)

    visit_namespaced controller: :logins, action: :new

    assert_userland_view controller: :logins, step: :remote_session_expired

    travel 19.minutes

    visit_namespaced controller: :logins, action: :new

    # --- SIGNIFICANT TEST ----
    # Remote logins can expire.
    # -------------------------
    assert_userland_view controller: :logins, step: :remote_session_expired

    travel 2.minutes

    visit_namespaced controller: :logins, action: :new

    assert_userland_view controller: :logins, step: :enter_username

    # ---------- SIGNIFICANT TEST -----------
    # Login procedures as a whole can expire.
    # ---------------------------------------
    assert_text(/20 min/i) # Flash message
  end
end