mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-09 14:18:58 +08:00
This patch will be followed by https://github.com/discourse/discourse/pull/34747. `SecureSession` doesn’t make a lot of sense anymore and can be confusing as the current cookie store used for the session is actually secure since it’s encrypted. Renaming it to `ServerSession` better conveys what it does: providing a session but on the server side only. This patch also makes some improvements, like injecting that server session into Rack-like request objects, allowing the server session to be available virtually everywhere.
26 lines
681 B
Ruby
26 lines
681 B
Ruby
# frozen_string_literal: true
|
|
|
|
RSpec.describe ServerSession do
|
|
subject(:session) { described_class.new("abc") }
|
|
|
|
it "operates correctly" do
|
|
session["hello"] = "world"
|
|
session["foo"] = "bar"
|
|
expect(session["hello"]).to eq("world")
|
|
expect(session["foo"]).to eq("bar")
|
|
|
|
session["hello"] = nil
|
|
expect(session["hello"]).to be_nil
|
|
end
|
|
|
|
it "can override expiry" do
|
|
key = SecureRandom.hex
|
|
|
|
session.set(key, "test2", expires: 5.minutes)
|
|
expect(session.ttl(key)).to be_within(1.second).of(5.minutes)
|
|
|
|
key = SecureRandom.hex
|
|
session.set(key, "test2")
|
|
expect(session.ttl(key)).to be_within(1.second).of(described_class.expiry)
|
|
end
|
|
end
|