Sha256: 813bbe3e9926f32cd8efd476c78cff352346b50e845176d7cabf2bf23a25e4f5

Contents?: true

Size: 1.6 KB

Versions: 11

Compression:

Stored size: 1.6 KB

Contents

RSpec.describe JWTKeeper::Datastore do
  include_context 'initialize config'
  let(:jti) { SecureRandom.uuid }

  describe '.rotate' do
    before { described_class.rotate(jti, 30) }

    it 'stores a token_id with a soft expiry' do
      expect(described_class.send(:get, jti)).to eq 'soft'
    end
  end

  describe '.pending?' do
    context 'with a missing token' do
      it 'returns false' do
        expect(described_class.pending?(jti)).to be false
      end
    end

    context 'with a revoked token' do
      before { described_class.revoke(jti, 30) }

      it 'returns false' do
        expect(described_class.pending?(jti)).to be false
      end
    end

    context 'with a pending token' do
      before { described_class.rotate(jti, 30) }

      it 'returns true' do
        expect(described_class.pending?(jti)).to be true
      end
    end
  end

  describe '.revoke' do
    before do
      described_class.revoke(jti, 30)
    end

    it 'stores a token_id with a hard expiry' do
      expect(described_class.send(:get, jti)).to eq 'hard'
    end
  end

  describe '.revoked?' do
    context 'with a missing token' do
      it 'returns false' do
        expect(described_class.revoked?(jti)).to be false
      end
    end

    context 'with a revoked token' do
      before { described_class.revoke(jti, 30) }

      it 'returns true' do
        expect(described_class.revoked?(jti)).to be true
      end
    end

    context 'with a pending token' do
      before { described_class.rotate(jti, 30) }

      it 'returns false' do
        expect(described_class.revoked?(jti)).to be false
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
jwt_keeper-6.0.0 spec/lib/jwt_keeper/datastore_spec.rb
jwt_keeper-5.0.1 spec/lib/jwt_keeper/datastore_spec.rb
jwt_keeper-5.0.0 spec/lib/jwt_keeper/datastore_spec.rb
jwt_keeper-4.0.1 spec/lib/jwt_keeper/datastore_spec.rb
jwt_keeper-4.0.0 spec/lib/jwt_keeper/datastore_spec.rb
jwt_keeper-3.3.0 spec/lib/jwt_keeper/datastore_spec.rb
jwt_keeper-3.2.0 spec/lib/jwt_keeper/datastore_spec.rb
jwt_keeper-3.1.0 spec/lib/jwt_keeper/datastore_spec.rb
jwt_keeper-3.0.1 spec/lib/jwt_keeper/datastore_spec.rb
jwt_keeper-3.0.0 spec/lib/jwt_keeper/datastore_spec.rb
jwt_keeper-2.0.0 spec/lib/keeper/datastore_spec.rb