spec/shared/authenticator.rb in rbnacl-3.3.0 vs spec/shared/authenticator.rb in rbnacl-3.4.0

- old
+ new

@@ -1,8 +1,8 @@ # encoding: binary RSpec.shared_examples "authenticator" do - let(:key) { vector :auth_key } + let(:key) { vector "auth_key_#{described_class.key_bytes}".to_sym } let(:message) { vector :auth_message } context ".new" do it "accepts a key" do expect { described_class.new(key) }.to_not raise_error @@ -15,15 +15,15 @@ it "raises TypeError on a nil key" do expect { described_class.new(nil) }.to raise_error(TypeError) end it "raises ArgumentError on a key which is too long" do - expect { described_class.new("\0" * 33) }.to raise_error(ArgumentError) + expect { described_class.new("\0" * described_class.key_bytes.succ) }.to raise_error(ArgumentError) end it "raises ArgumentError on a key which is too short" do - expect { described_class.new("\0" * 31) }.to raise_error(ArgumentError) + expect { described_class.new("\0" * described_class.key_bytes.pred) }.to raise_error(ArgumentError) end end context ".auth" do it "produces an authenticator" do @@ -33,11 +33,11 @@ it "raises TypeError on a nil key" do expect { described_class.auth(nil, message) }.to raise_error(TypeError) end it "raises ArgumentError on a key which is too long" do - expect { described_class.auth("\0" * 33, message) }.to raise_error(ArgumentError) + expect { described_class.auth("\0" * described_class.key_bytes.succ, message) }.to raise_error(ArgumentError) end end context ".verify" do it "verify an authenticator" do @@ -47,10 +47,10 @@ it "raises TypeError on a nil key" do expect { described_class.verify(nil, tag, message) }.to raise_error(TypeError) end it "raises ArgumentError on a key which is too long" do - expect { described_class.verify("\0" * 33, tag, message) }.to raise_error(ArgumentError) + expect { described_class.verify("\0" * described_class.key_bytes.succ, tag, message) }.to raise_error(ArgumentError) end it "fails to validate an invalid authenticator" do expect { described_class.verify(key, tag, message + "\0") }.to raise_error(RbNaCl::BadAuthenticatorError) end