Files
codeocean/spec/lib/nonce_store_spec.rb
Sebastian Serth 99bd46af1a Align project files with CodeHarbor
Since both projects are developed together and by the same team, we also want to have the same code structure and utility methods available in both projects. Therefore, this commit changes many files, but without a functional change.
2023-10-11 00:18:33 +02:00

46 lines
1.1 KiB
Ruby

# frozen_string_literal: true
require 'rails_helper'
RSpec.describe NonceStore do
let(:nonce) { SecureRandom.hex }
before do
stub_const('Lti::MAXIMUM_SESSION_AGE', 1)
end
describe '.add' do
it 'stores a nonce in the cache' do
expect(Rails.cache).to receive(:write)
described_class.add(nonce)
end
end
describe '.delete' do
it 'deletes a nonce from the cache' do
expect(Rails.cache).to receive(:write)
described_class.add(nonce)
described_class.delete(nonce)
expect(described_class.has?(nonce)).to be false
end
end
describe '.has?' do
it 'returns true for present nonces' do
described_class.add(nonce)
expect(described_class.has?(nonce)).to be true
end
it 'returns false for expired nonces' do
described_class.add(nonce)
expect(described_class.has?(nonce)).to be true
sleep(Lti::MAXIMUM_SESSION_AGE)
expect(described_class.has?(nonce)).to be false
end
it 'returns false for absent nonces' do
expect(described_class.has?(nonce)).to be false
end
end
end