Skip to content

Commit df408c0

Browse files
eld120claude
andcommitted
Group the RequestStore examples by what they exercise
Four undifferentiated examples under one describe, where a lead example plus a context for the edge case says the same thing - matching bike_services/register_spec. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent bcde30f commit df408c0

1 file changed

Lines changed: 15 additions & 25 deletions

File tree

spec/services/saml/request_store_spec.rb

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,30 @@
33
RSpec.describe Saml::RequestStore do
44
let(:request_id) { "_abc-123" }
55
let(:org_slug) { "some-university" }
6+
let(:token) { described_class.create(request_id:, org_slug:) }
67

7-
describe "create and claim" do
8-
it "round trips the transaction" do
9-
token = described_class.create(request_id:, org_slug:)
8+
describe "create" do
9+
it "issues a distinct expiring token that round trips the transaction" do
1010
expect(token).to be_present
11+
expect(RedisPool.conn { |r| r.ttl("saml_request:#{token}") })
12+
.to be_within(5).of(described_class::TTL.to_i)
1113
expect(described_class.claim(token)).to eq({org_slug:, request_id:})
12-
end
13-
14-
it "only claims once" do
15-
token = described_class.create(request_id:, org_slug:)
16-
described_class.claim(token)
17-
expect(described_class.claim(token)).to be_nil
18-
end
19-
20-
it "issues a distinct token per request" do
21-
tokens = Array.new(3) { described_class.create(request_id:, org_slug:) }
22-
expect(tokens.uniq.count).to eq 3
23-
end
24-
25-
it "expires" do
26-
token = described_class.create(request_id:, org_slug:)
27-
ttl = RedisPool.conn { |r| r.ttl("saml_request:#{token}") }
28-
expect(ttl).to be_within(5).of(described_class::TTL.to_i)
14+
expect(described_class.create(request_id:, org_slug:)).to_not eq token
2915
end
3016
end
3117

3218
describe "claim" do
33-
it "is nil for a blank token" do
34-
expect(described_class.claim(nil)).to be_nil
35-
expect(described_class.claim("")).to be_nil
19+
it "succeeds once, the token being single use" do
20+
expect(described_class.claim(token)).to eq({org_slug:, request_id:})
21+
expect(described_class.claim(token)).to be_nil
3622
end
3723

38-
it "is nil for an unknown token" do
39-
expect(described_class.claim("not-a-real-token")).to be_nil
24+
context "a token we never issued" do
25+
it "is nil rather than raising" do
26+
expect(described_class.claim(nil)).to be_nil
27+
expect(described_class.claim("")).to be_nil
28+
expect(described_class.claim("not-a-real-token")).to be_nil
29+
end
4030
end
4131
end
4232
end

0 commit comments

Comments
 (0)