2020-01-09 19:45:56 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2023-08-18 08:39:10 -04:00
|
|
|
RSpec.describe DiscourseWebauthn::ChallengeGenerator do
|
|
|
|
it "generates a DiscourseWebauthn::ChallengeGenerator::ChallengeSession with correct params" do
|
|
|
|
session = DiscourseWebauthn::ChallengeGenerator.generate
|
|
|
|
expect(session).to be_a(DiscourseWebauthn::ChallengeGenerator::ChallengeSession)
|
2020-01-09 19:45:56 -05:00
|
|
|
expect(session.challenge).not_to eq(nil)
|
|
|
|
expect(session.rp_id).to eq(Discourse.current_hostname)
|
|
|
|
expect(session.rp_name).to eq(SiteSetting.title)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "ChallengeSession" do
|
|
|
|
describe "#commit_to_session" do
|
|
|
|
let(:user) { Fabricate(:user) }
|
|
|
|
|
2021-05-20 21:43:47 -04:00
|
|
|
it "stores the challenge, rp id, and rp name in the provided session object" do
|
2020-01-09 19:45:56 -05:00
|
|
|
secure_session = {}
|
2023-08-18 08:39:10 -04:00
|
|
|
generated_session = DiscourseWebauthn::ChallengeGenerator.generate
|
2020-01-09 19:45:56 -05:00
|
|
|
generated_session.commit_to_session(secure_session, user)
|
|
|
|
|
|
|
|
expect(secure_session["staged-webauthn-challenge-#{user&.id}"]).to eq(
|
|
|
|
generated_session.challenge,
|
|
|
|
)
|
|
|
|
expect(secure_session["staged-webauthn-rp-id-#{user&.id}"]).to eq(generated_session.rp_id)
|
|
|
|
expect(secure_session["staged-webauthn-rp-name-#{user&.id}"]).to eq(
|
|
|
|
generated_session.rp_name,
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|