Skip to content
This repository has been archived by the owner on Mar 16, 2022. It is now read-only.

Commit

Permalink
Test Sodium::OneTimeAuth
Browse files Browse the repository at this point in the history
  • Loading branch information
stouset committed Mar 22, 2013
1 parent f918090 commit 30760cc
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
2 changes: 1 addition & 1 deletion test/sodium/auth_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
47 changes: 47 additions & 0 deletions test/sodium/one_time_auth_test.rb
Original file line number Diff line number Diff line change
@@ -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.