spec/fernet_spec.rb in fernet-2.0.rc1 vs spec/fernet_spec.rb in fernet-2.0.rc2
- old
+ new
@@ -6,36 +6,25 @@
let(:secret) { 'JrdICDH6x3M7duQeM8dJEMK4Y5TkBIsYDw1lPy35RiY=' }
let(:bad_secret) { 'badICDH6x3M7duQeM8dJEMK4Y5TkBIsYDw1lPy35RiY=' }
it 'can verify tokens it generates' do
- token = Fernet.generate(secret) do |generator|
- generator.message = 'harold@heroku.com'
- end
+ token = Fernet.generate(secret, 'harold@heroku.com')
verifier = Fernet.verifier(secret, token)
expect(verifier).to be_valid
expect(verifier.message).to eq('harold@heroku.com')
end
- it 'can generate tokens without a block' do
+ it 'fails with a bad secret' do
token = Fernet.generate(secret, 'harold@heroku.com')
- verifier = Fernet.verifier(secret, token)
- expect(verifier).to be_valid
- expect(verifier.message).to eq('harold@heroku.com')
- end
- it 'fails with a bad secret' do
- token = Fernet.generate(secret) do |generator|
- generator.message = 'harold@heroku.com'
- end
-
verifier = Fernet.verifier(bad_secret, token)
expect(verifier.valid?).to be_false
expect {
verifier.message
- }.to raise_error
+ }.to raise_error Fernet::Token::InvalidToken
end
it 'fails if the token is too old' do
token = Fernet.generate(secret, 'harold@heroku.com', now: (Time.now - 61))
@@ -75,12 +64,10 @@
it 'allows overriding enforce_ttl on a verifier' do
Fernet::Configuration.run do |config|
config.enforce_ttl = true
config.ttl = 0
end
- token = Fernet.generate(secret) do |generator|
- generator.message = 'password1'
- end
+ token = Fernet.generate(secret, 'password1')
verifier = Fernet.verifier(secret, token)
verifier.enforce_ttl = false
expect(verifier.valid?).to be_true
expect(verifier.message).to eq('password1')
end