spec/secret_spec.rb in fernet-2.0.rc1 vs spec/secret_spec.rb in fernet-2.0.rc2
- old
+ new
@@ -1,30 +1,35 @@
require 'spec_helper'
require 'fernet/secret'
describe Fernet::Secret do
- it "expects base64 encoded 32 byte strings" do
- secret = Base64.urlsafe_encode64("A"*32)
- expect do
- Fernet::Secret.new(secret)
- end.to_not raise_error
+ it "can resolve a URL safe base64 encoded 32 byte string" do
+ resolves_input(Base64.urlsafe_encode64("A"*16 + "B"*16))
end
- it "extracts encryption and signing keys" do
- secret = Base64.urlsafe_encode64("A"*16 + "B"*16)
- fernet_secret = Fernet::Secret.new(secret)
- expect(
- fernet_secret.signing_key
- ).to eq("A"*16)
+ it "can resolve a base64 encoded 32 byte string" do
+ resolves_input(Base64.encode64("A"*16 + "B"*16))
+ end
- expect(
- fernet_secret.encryption_key
- ).to eq("B"*16)
+ it "can resolve a 32 byte string without encoding" do
+ resolves_input("A"*16 + "B"*16)
end
it "fails loudly when an invalid secret is provided" do
secret = Base64.urlsafe_encode64("bad")
expect do
Fernet::Secret.new(secret)
end.to raise_error(Fernet::Secret::InvalidSecret)
+ end
+
+ def resolves_input(input)
+ secret = Fernet::Secret.new(input)
+
+ expect(
+ secret.signing_key
+ ).to eq("A"*16)
+
+ expect(
+ secret.encryption_key
+ ).to eq("B"*16)
end
end