spec/symmetric_spec.rb in slosilo-3.0.0 vs spec/symmetric_spec.rb in slosilo-3.0.1
- old
+ new
@@ -12,12 +12,33 @@
it "encrypts with AES-256-GCM" do
allow(subject).to receive_messages random_iv: iv
expect(subject.encrypt(plaintext, key: key, aad: auth_data)).to eq(ciphertext)
end
end
-
+
describe '#decrypt' do
+
+ it "doesn't fail when called by multiple threads" do
+ threads = []
+
+ begin
+ # Verify we can successfuly decrypt using many threads without OpenSSL
+ # errors.
+ 1000.times do
+ threads << Thread.new do
+ 100.times do
+ expect(
+ subject.decrypt(ciphertext, key: key, aad: auth_data)
+ ).to eq(plaintext)
+ end
+ end
+ end
+ ensure
+ threads.each(&:join)
+ end
+ end
+
it "decrypts with AES-256-GCM" do
expect(subject.decrypt(ciphertext, key: key, aad: auth_data)).to eq(plaintext)
end
@@ -54,10 +75,10 @@
it "raises an exception" do
expect{ subject.decrypt(ciphertext, key: key, aad: auth_data)}.to raise_exception OpenSSL::Cipher::CipherError
end
end
end
-
+
describe '#random_iv' do
it "generates a random iv" do
expect_any_instance_of(OpenSSL::Cipher).to receive(:random_iv).and_return :iv
expect(subject.random_iv).to eq(:iv)
end