Module: Practical::Test::Helpers::Passkey::System::Base

Included in:
RackTest, Selenium
Defined in:
app/lib/practical/test/helpers/passkey/system/base.rb

Instance Method Summary collapse

Instance Method Details

#administrator_webauthn_clientObject



14
15
16
# File 'app/lib/practical/test/helpers/passkey/system/base.rb', line 14

def administrator_webauthn_client
  @webauthn_client ||= WebAuthn::FakeClient.new(admin_relying_party_origin, authenticator: fake_authenticator)
end

#create_webauthn_credential_from_scratch(webauthn_client:, rp_id: nil, relying_party:) ⇒ Object



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
# File 'app/lib/practical/test/helpers/passkey/system/base.rb', line 25

def create_webauthn_credential_from_scratch(webauthn_client:, rp_id: nil, relying_party:)
  rp_id ||= relying_party.id || URI.parse(webauthn_client.origin).host

  create_result = webauthn_client.create(rp_id: rp_id)

  attestation_object =
    if webauthn_client.encoding
      relying_party.encoder.decode(create_result["response"]["attestationObject"])
    else
      create_result["response"]["attestationObject"]
    end

  client_data_json =
    if webauthn_client.encoding
      relying_party.encoder.decode(create_result["response"]["clientDataJSON"])
    else
      create_result["response"]["clientDataJSON"]
    end

  response = WebAuthn::AuthenticatorAttestationResponse.new(
    attestation_object: attestation_object,
    client_data_json: client_data_json,
    relying_party: relying_party
  )

  return response.credential
end

#fake_authenticatorObject



6
7
8
# File 'app/lib/practical/test/helpers/passkey/system/base.rb', line 6

def fake_authenticator
  @fake_authenticator ||= WebAuthn::FakeAuthenticator.new
end

#user_relying_partyObject



18
19
20
21
22
23
# File 'app/lib/practical/test/helpers/passkey/system/base.rb', line 18

def user_relying_party
  return WebAuthn::RelyingParty.new(
    allowed_origins: relying_party_origin,
    name: I18n.translate("app_title.text")
  )
end

#user_webauthn_clientObject



10
11
12
# File 'app/lib/practical/test/helpers/passkey/system/base.rb', line 10

def user_webauthn_client
  @webauthn_client ||= WebAuthn::FakeClient.new(relying_party_origin, authenticator: fake_authenticator)
end