Module: Practical::Test::Helpers::Passkey::System::RackTest

Includes:
Base
Defined in:
app/lib/practical/test/helpers/passkey/system/rack_test.rb

Instance Method Summary collapse

Instance Method Details

#create_passkey_for_administrator_and_return_webauthn_credential(administrator:) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/lib/practical/test/helpers/passkey/system/rack_test.rb', line 27

def create_passkey_for_administrator_and_return_webauthn_credential(administrator:)
  webauthn_credential = create_webauthn_credential_from_scratch(webauthn_client: administrator_webauthn_client,
                                                                rp_id: admin_relying_party_id,
                                                                relying_party: admin_relying_party
                                                               )
  fake_authenticator.instance_variable_get("@credentials")[admin_relying_party_id]
                                                          [webauthn_credential.id]
                                                          [:credential_key]

  administrator.passkeys.create!(
    label: SecureRandom.hex,
    external_id: Base64.strict_encode64(webauthn_credential.id),
    public_key: Base64.strict_encode64(webauthn_credential.public_key),
    sign_count: 0
  )

  return webauthn_credential
end

#create_passkey_for_user_and_return_webauthn_credential(user:) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/lib/practical/test/helpers/passkey/system/rack_test.rb', line 8

def create_passkey_for_user_and_return_webauthn_credential(user:)
  webauthn_credential = create_webauthn_credential_from_scratch(webauthn_client: user_webauthn_client,
                                                                rp_id: user_relying_party_id,
                                                                relying_party: user_relying_party
                                                               )
  fake_authenticator.instance_variable_get("@credentials")[user_relying_party_id]
                                                          [webauthn_credential.id]
                                                          [:credential_key]

  user.passkeys.create!(
    label: SecureRandom.hex,
    external_id: Base64.strict_encode64(webauthn_credential.id),
    public_key: Base64.strict_encode64(webauthn_credential.public_key),
    sign_count: 0
  )

  return webauthn_credential
end