This repository has been archived by the owner on Mar 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
48 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |