Skip to content

Commit 4eb9ea8

Browse files
committed
Add top level session spec to validate existing formats.
1 parent 8f94577 commit 4eb9ea8

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

test/spec_session.rb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# frozen_string_literal: true
2+
3+
# Released under the MIT License.
4+
# Copyright, 2024, by Samuel Williams.
5+
6+
require "minitest/autorun"
7+
require "rack/session/encryptor"
8+
9+
describe Rack::Session do
10+
describe "with an encryptor" do
11+
let(:secret) { "." * 64 }
12+
let(:encryptor) { Rack::Session::Encryptor.new(secret) }
13+
14+
def self.test_session_cookie(value, cookie)
15+
it "decrypts the cookie to produce #{value.inspect}" do
16+
_(encryptor.decrypt(cookie)).must_equal value
17+
rescue => error
18+
warn "Decryption failed for: #{value.inspect}"
19+
pp encryptor.encrypt(value)
20+
raise error
21+
end
22+
23+
it "encrypts and decrypts #{value.inspect} round-trip" do
24+
encrypted = encryptor.encrypt(value)
25+
_(encryptor.decrypt(encrypted)).must_equal value
26+
end
27+
end
28+
29+
test_session_cookie({}, "AbGjZyIjUxHlH1vpbU0yDc8N8MB0SV723Fj2uGYWrXxHuh99KpUiavHdw2gG1IW7e2OISpZetJzALqc_LxtVigllj9HZ7mzF1KvHPabLvfJcJ0gB_MqHGTKUMPlsSs9L9frJJuazsd1aW-7C33LB6Eg=")
30+
test_session_cookie({"a" => 10}, "AbxvYQw-Fz0HW2g6uo3uSVheVv1-QaWGtg2LSVsTYq1Sds8xNLjGDCKvwACHJN1tiBA_jOoiP64kmjZRGnTBl0pv9SqsKwaRBKnY1Q5Rkc621pVlRlr98ehyYhfJT_svoUJXCYfrWgoGO_n8zj4Cgi4=")
31+
test_session_cookie({"a" => 10, "b" => 20}, "ATfvdnPvcdW4ohIm7MnIdBLKwvqK4j58Rt9hQZhkifZq9IW15sDUViOMM0ClaLONci1fChW0pTuLmFxK3tQ0ch7GxiTVNqfNI1GFlC2epQr-bkuWNF0AbpC4FzBhn94RVQ1MLdd1pPaFQF6E40VvUjw=")
32+
test_session_cookie({a: 10, b: 20}, "AV6-1fg2bphnDYJvj4B34LiDed0QLzBsxboLVerKCk2Nv9_HBaOeTOCJMrkW946IHS3HxXJ10hFrXTlHTJLn9m96SRlGODJjGTu1ltTcFpiQo-dikKvCDmuIP-4t0cxEVl2pYfgO3wexd9MrJzOKuzQ=")
33+
end
34+
end

0 commit comments

Comments
 (0)