mirror of
https://github.com/discourse/discourse.git
synced 2025-02-10 05:14:59 +00:00
006a5166e5
They're both constant per-instance values, there is no need to store them in the session. This also makes the code a bit more readable by moving the `session_challenge_key` method up to the `DiscourseWebauthn` module.
26 lines
881 B
Ruby
26 lines
881 B
Ruby
# frozen_string_literal: true
|
|
|
|
RSpec.describe DiscourseWebauthn::ChallengeGenerator do
|
|
it "generates a DiscourseWebauthn::ChallengeGenerator::ChallengeSession with a challenge" do
|
|
session = DiscourseWebauthn::ChallengeGenerator.generate
|
|
expect(session).to be_a(DiscourseWebauthn::ChallengeGenerator::ChallengeSession)
|
|
expect(session.challenge).not_to eq(nil)
|
|
end
|
|
|
|
describe "ChallengeSession" do
|
|
describe "#commit_to_session" do
|
|
let(:user) { Fabricate(:user) }
|
|
|
|
it "stores the challenge in the provided session object" do
|
|
secure_session = {}
|
|
generated_session = DiscourseWebauthn::ChallengeGenerator.generate
|
|
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
|