Finished phase005
CI / scan_ruby (push) Failing after 1m5s
CI / scan_js (push) Failing after 6s
CI / lint (push) Failing after 1m29s

This commit is contained in:
2026-09-16 15:34:50 -06:00
parent a3a65c24ed
commit 0826d267f2
38 changed files with 1596 additions and 9 deletions
+53
View File
@@ -0,0 +1,53 @@
require "rails_helper"
RSpec.describe AccessKey do
it "creates a current access key when one does not exist" do
expect { described_class.current }.to change(described_class, :count).by(1)
expect(described_class.current.raw_key).to be_present
end
it "matches the submitted raw key" do
access_key = described_class.current
expect(access_key.matches?(access_key.raw_key)).to be(true)
expect(access_key.matches?("wrong-key")).to be(false)
end
it "rotates the key and invalidates user sessions" do
old_key = described_class.current
user = create(:user)
UserSession.create_for!(user)
expect do
described_class.rotate!
end.to change(described_class, :count).by(1).and change(UserSession, :count).to(0)
expect(described_class.current.raw_key).not_to eq(old_key.raw_key)
end
it "does not auto-rotate when auto rotation is disabled" do
access_key = described_class.current
access_key.update!(generated_at: 31.days.ago)
access_key.disable_auto_rotation!
expect do
described_class.rotate_if_needed!
end.not_to change(described_class, :count)
end
it "auto-rotates when enabled and expired" do
access_key = described_class.current
access_key.update!(generated_at: 31.days.ago)
expect do
described_class.rotate_if_needed!
end.to change(described_class, :count).by(1)
end
it "uses the configured auto rotation frequency" do
access_key = described_class.current
access_key.update!(generated_at: 10.days.ago, auto_rotation_frequency_days: 7)
expect(access_key).to be_expired
end
end