Sha256: bdb243982b62b8ce1e4d52b3a058aafd86f35c0e07cac265d8b6219663b1024c

Contents?: true

Size: 1.51 KB

Versions: 5

Compression:

Stored size: 1.51 KB

Contents

require 'spec_helper'
require 'fernet'
require 'json'
require 'base64'

describe Fernet::Verifier do
  it 'verifies tokens according to the spec' do
    path = File.expand_path(
      './../fernet-spec/verify.json', File.dirname(__FILE__)
    )
    verify_json  = JSON.parse(File.read(path))

    verify_json.each do |test_data|
      token   = test_data['token']
      ttl     = test_data['ttl_sec']
      now     = DateTime.parse(test_data['now']).to_time
      secret  = test_data['secret']
      message = test_data['src']

      verifier = Fernet::Verifier.new(token: token,
                                      secret: secret,
                                      now: now,
                                      ttl: ttl)
      expect(
        verifier.message
      ).to eq(message)
    end
  end

  context 'invalid tokens' do
    path = File.expand_path(
      './../fernet-spec/invalid.json', File.dirname(__FILE__)
    )
    invalid_json = JSON.parse(File.read(path))
    invalid_json.each do |test_data|
      it "detects #{test_data['desc']}" do
        token  = test_data['token']
        ttl    = test_data['ttl_sec']
        now    = DateTime.parse(test_data['now']).to_time
        secret = test_data['secret']

        verifier = Fernet::Verifier.new(token: token,
                                        secret: secret,
                                        now: now,
                                        ttl: ttl)

        expect { verifier.message }.to raise_error(Fernet::Token::InvalidToken)
      end
    end
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
fernet-2.1.1 spec/acceptance/verify_spec.rb
fernet-2.1 spec/acceptance/verify_spec.rb
fernet-2.0 spec/acceptance/verify_spec.rb
fernet-2.0.rc2 spec/acceptance/verify_spec.rb
fernet-2.0.rc1 spec/acceptance/verify_spec.rb