2020-01-10 08:45:56 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2023-08-18 20:39:10 +08:00
|
|
|
RSpec.describe DiscourseWebauthn::ChallengeGenerator do
|
2023-08-31 21:11:23 +08:00
|
|
|
it "generates a DiscourseWebauthn::ChallengeGenerator::ChallengeSession with a challenge" do
|
2023-08-18 20:39:10 +08:00
|
|
|
session = DiscourseWebauthn::ChallengeGenerator.generate
|
|
|
|
expect(session).to be_a(DiscourseWebauthn::ChallengeGenerator::ChallengeSession)
|
2020-01-10 08:45:56 +08:00
|
|
|
expect(session.challenge).not_to eq(nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "ChallengeSession" do
|
|
|
|
describe "#commit_to_session" do
|
|
|
|
let(:user) { Fabricate(:user) }
|
|
|
|
|
2023-08-31 21:11:23 +08:00
|
|
|
it "stores the challenge in the provided session object" do
|
2020-01-10 08:45:56 +08:00
|
|
|
secure_session = {}
|
2023-08-18 20:39:10 +08:00
|
|
|
generated_session = DiscourseWebauthn::ChallengeGenerator.generate
|
2020-01-10 08:45:56 +08:00
|
|
|
generated_session.commit_to_session(secure_session, user)
|
|
|
|
|
|
|
|
expect(secure_session["staged-webauthn-challenge-#{user&.id}"]).to eq(
|
|
|
|
generated_session.challenge,
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|