Sha256: 19a3f7c54e548d63926f8ec7b5c2c4a445c93dfdf5c192cd1c1679a6cc016181

Contents?: true

Size: 1.19 KB

Versions: 1

Compression:

Stored size: 1.19 KB

Contents

require 'spec_helper'
require 'fernet'

describe Fernet do
  let(:token_data) do
    { email: 'harold@heroku.com', id: '123', arbitrary: 'data' }
  end

  let(:secret) { 'sekrit123' }

  it 'can verify tokens it generates' do
    token = Fernet.generate(secret) do |generator|
      generator.data = token_data
    end

    Fernet.verify(secret, token) do |verifier|
      verifier.data['email'] == 'harold@heroku.com'
    end.should be_true
  end

  it 'fails with a bad secret' do
    token = Fernet.generate(secret) do |generator|
      generator.data = token_data
    end

    Fernet.verify('bad', token) do |verifier|
      verifier.data['email'] == 'harold@heroku.com'
    end.should be_false
  end

  it 'fails with a bad custom verification' do
    token = Fernet.generate(secret) do |generator|
      generator.data = token_data
    end

    Fernet.verify('bad', token) do |verifier|
      verifier.data['email'] == 'harold@gmail.com'
    end.should be_false
  end

  it 'fails if the token is too old' do
    token = Fernet.generate(secret) do |generator|
      generator.data = token_data
    end

    Fernet.verify('bad', token) do |verifier|
      verifier.seconds_valid = 0
    end.should be_false
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fernet-0.0.1 spec/fernet_spec.rb