Browse files

Test Sodium::OneTimeAuth

  • Loading branch information...
1 parent f918090 commit 30760cce97f31d6d28b616ffead41302c8f80f41 @stouset committed Mar 22, 2013
Showing with 48 additions and 1 deletion.
  1. +1 −1 test/sodium/auth_test.rb
  2. +47 −0 test/sodium/one_time_auth_test.rb
View
2 test/sodium/auth_test.rb
@@ -33,7 +33,7 @@
must_raise Sodium::LengthError
end
- it 'must raise when verifying an invalid authenticators' do
+ it 'must raise when verifying an invalid authenticator' do
lambda { self.subject.verify('message', 'blaaah') }.
must_raise Sodium::LengthError
end
View
47 test/sodium/one_time_auth_test.rb
@@ -0,0 +1,47 @@
+require 'test_helper'
+
+describe Sodium::OneTimeAuth do
+ subject { self.klass.new(self.key) }
+ let(:klass) { Sodium::OneTimeAuth }
+ let(:key) { self.klass.key }
+
+ it 'must default to the Poly1305 implementation' do
+ self.klass.implementation.
+ must_equal Sodium::OneTimeAuth::Poly1305
+ end
+
+ it 'must allow access to alternate implementations' do
+ self.klass.implementation(:foo).
+ must_equal nil
+ end
+
+ it 'must instantiate the default implementation' do
+ self.subject.
+ must_be_kind_of Sodium::OneTimeAuth::Poly1305
+ end
+
+ it 'must mint keys from the default implementation' do
+ sodium_mock_default(self.klass) do |klass, mock|
+ mock.expect :[], 0, [:KEYBYTES]
+
+ klass.key.length.must_equal 0
+ end
+ end
+
+ it 'must raise when instantiating with an invalid key' do
+ lambda { self.klass.new(self.key[0..-2]) }.
+ must_raise Sodium::LengthError
+ end
+
+ it 'must raise when verifying an invalid authenticator' do
+ lambda { self.subject.verify('message', 'blaah') }.
+ must_raise Sodium::LengthError
+ end
+
+ it 'must raise when failing to generate an authenticator' do
+ sodium_stub_failure(self.klass, :nacl) do
+ lambda { self.subject.one_time_auth('message') }.
+ must_raise Sodium::CryptoError
+ end
+ end
+end

0 comments on commit 30760cc

Please sign in to comment.