discourse/spec/components/secure_session_spec.rb
Sam Saffron 91daafc674 DEV: correct implementation of expiry api
Previously we were always hard-coding expiry, this allows the secure session
to correctly handle custom expiry times

Also adds a ttl method for looking up time to live
2019-11-11 11:18:12 +11:00

30 lines
655 B
Ruby

# frozen_string_literal: true
require 'rails_helper'
describe SecureSession do
it "operates correctly" do
s = SecureSession.new("abc")
s["hello"] = "world"
s["foo"] = "bar"
expect(s["hello"]).to eq("world")
expect(s["foo"]).to eq("bar")
s["hello"] = nil
expect(s["hello"]).to eq(nil)
end
it "can override expiry" do
s = SecureSession.new("abc")
key = SecureRandom.hex
s.set(key, "test2", expires: 5.minutes)
expect(s.ttl(key)).to be_within(1.second).of (5.minutes)
key = SecureRandom.hex
s.set(key, "test2")
expect(s.ttl(key)).to be_within(1.second).of (SecureSession.expiry)
end
end