spec/fernet_spec.rb in fernet-1.0 vs spec/fernet_spec.rb in fernet-1.1
- old
+ new
@@ -1,15 +1,15 @@
require 'spec_helper'
require 'fernet'
describe Fernet do
let(:token_data) do
- { email: 'harold@heroku.com', id: '123', arbitrary: 'data' }
+ { :email => 'harold@heroku.com', :id => '123', :arbitrary => 'data' }
end
- let(:secret) { 'JrdICDH6x3M7duQeM8dJEMK4Y5TkBIsYDw1lPy35RiY=' }
- let(:bad_secret) { 'jrdICDH6x3M7duQeM8dJEMK4Y5TkBIsYDw1lPy35RiY=' }
+ let(:secret) { 'JrdICDH6x3M7duQeM8dJEMK4Y5TkBIsYDw1lPy35RiY=' }
+ let(:bad_secret) { 'badICDH6x3M7duQeM8dJEMK4Y5TkBIsYDw1lPy35RiY=' }
it 'can verify tokens it generates' do
token = Fernet.generate(secret) do |generator|
generator.data = token_data
end
@@ -43,11 +43,11 @@
token = Fernet.generate(secret) do |generator|
generator.data = token_data
end
Fernet.verify(bad_secret, token) do |verifier|
- verifier.seconds_valid = 0
+ verifier.ttl = 0
end.should be_false
end
it 'verifies without a custom verification' do
token = Fernet.generate(secret) do |generator|
@@ -55,10 +55,24 @@
end
Fernet.verify(secret, token).should be_true
end
+ it 'can TTL enforcement' do
+ token = Fernet.generate(secret) do |generator|
+ generator.data = token_data
+ end
+
+ Fernet.verify(secret, token) do |verifier|
+ def verifier.now
+ Time.now + 99999999999
+ end
+ verifier.enforce_ttl = false
+ true
+ end.should be_true
+ end
+
it 'generates without custom data' do
token = Fernet.generate(secret)
Fernet.verify(secret, token).should be_true
end
@@ -86,7 +100,6 @@
Fernet.verify(secret, token, false) do |verifier|
verifier.data['password'].should == 'password1'
end
end
-
end