diff options
author | Xabier de Zuazo <xabier@onddo.com> | 2014-07-09 09:58:59 +0200 |
---|---|---|
committer | Xabier de Zuazo <xabier@onddo.com> | 2014-07-09 09:58:59 +0200 |
commit | e11d4ad82fc57d9d7b96b788a024aa1d263f625e (patch) | |
tree | e69e0b9e46591cd721cc794ba558a75a97cfc75e /spec/unit/encrypted_data_bag_item_spec.rb | |
parent | 24af166939aea7dc0f360c4221c75774077873cc (diff) | |
download | chef-e11d4ad82fc57d9d7b96b788a024aa1d263f625e.tar.gz |
[CHEF-5356-gcm] Use rspec filters instead of conditionals and add some alternative tests using stubs
Diffstat (limited to 'spec/unit/encrypted_data_bag_item_spec.rb')
-rw-r--r-- | spec/unit/encrypted_data_bag_item_spec.rb | 35 |
1 files changed, 23 insertions, 12 deletions
diff --git a/spec/unit/encrypted_data_bag_item_spec.rb b/spec/unit/encrypted_data_bag_item_spec.rb index a02174ce78..84d7d19c7d 100644 --- a/spec/unit/encrypted_data_bag_item_spec.rb +++ b/spec/unit/encrypted_data_bag_item_spec.rb @@ -97,8 +97,7 @@ describe Chef::EncryptedDataBagItem::Encryptor do Chef::Config[:data_bag_encrypt_version] = 3 end - context "on supported platforms", - :if => (RUBY_VERSION >= "2" and OpenSSL::OPENSSL_VERSION_NUMBER >= 10001000) do + context "on supported platforms", :ruby_gte_20_and_openssl_gte_101 do it "creates a version 3 encryptor" do encryptor.should be_a_instance_of(Chef::EncryptedDataBagItem::Encryptor::Version3Encryptor) @@ -123,9 +122,25 @@ describe Chef::EncryptedDataBagItem::Encryptor do end # context on supported platforms context "on unsupported platforms" do + let(:aead_algorithm) { Chef::EncryptedDataBagItem::AEAD_ALGORITHM } + + it "throws an error warning about the Ruby version if it has no GCM support" do + # Force OpenSSL with AEAD support + OpenSSL::Cipher.stub(:ciphers).and_return([ aead_algorithm ]) + # Ruby with AEAD support + OpenSSL::Cipher.should_receive(:method_defined?).with(:auth_data=).and_return(false) + lambda { encryptor }.should raise_error(Chef::EncryptedDataBagItem::EncryptedDataBagRequirementsFailure, /requires Ruby/) + end + + it "throws an error warning about the OpenSSL version if it has no GCM support" do + # Force Ruby with AEAD support + OpenSSL::Cipher.stub(:method_defined?).with(:auth_data=).and_return(true) + # OpenSSL without AEAD support + OpenSSL::Cipher.should_receive(:ciphers).and_return([]) + lambda { encryptor }.should raise_error(Chef::EncryptedDataBagItem::EncryptedDataBagRequirementsFailure, /requires an OpenSSL/) + end - context "on platforms with old Ruby", - :if => RUBY_VERSION < "2" do + context "on platforms with old Ruby", :ruby_lt_20 do it "throws an error warning about the Ruby version" do lambda { encryptor }.should raise_error(Chef::EncryptedDataBagItem::EncryptedDataBagRequirementsFailure, /requires Ruby/) @@ -133,8 +148,7 @@ describe Chef::EncryptedDataBagItem::Encryptor do end # context on platforms with old Ruby - context "on platforms with old OpenSSL", - :if => OpenSSL::OPENSSL_VERSION_NUMBER < 10001000 do + context "on platforms with old OpenSSL", :openssl_lt_101 do it "throws an error warning about the OpenSSL version" do lambda { encryptor }.should raise_error(Chef::EncryptedDataBagItem::EncryptedDataBagRequirementsFailure, /requires an OpenSSL/) @@ -157,8 +171,7 @@ describe Chef::EncryptedDataBagItem::Decryptor do context "when decrypting a version 3 (JSON+aes-256-gcm+random iv+auth tag) encrypted value" do - context "on supported platforms", - :if => (RUBY_VERSION >= "2" and OpenSSL::OPENSSL_VERSION_NUMBER >= 10001000) do + context "on supported platforms", :ruby_gte_20_and_openssl_gte_101 do let(:encrypted_value) do Chef::EncryptedDataBagItem::Encryptor::Version3Encryptor.new(plaintext_data, encryption_key).for_encrypted_item @@ -196,8 +209,7 @@ describe Chef::EncryptedDataBagItem::Decryptor do } end - context "on platforms with old Ruby", - :if => RUBY_VERSION < "2" do + context "on platforms with old Ruby", :ruby_lt_20 do it "throws an error warning about the Ruby version" do lambda { decryptor }.should raise_error(Chef::EncryptedDataBagItem::EncryptedDataBagRequirementsFailure, /requires Ruby/) @@ -205,8 +217,7 @@ describe Chef::EncryptedDataBagItem::Decryptor do end # context on platforms with old Ruby - context "on platforms with old OpenSSL", - :if => OpenSSL::OPENSSL_VERSION_NUMBER < 10001000 do + context "on platforms with old OpenSSL", :openssl_lt_101 do it "throws an error warning about the OpenSSL version" do lambda { decryptor }.should raise_error(Chef::EncryptedDataBagItem::EncryptedDataBagRequirementsFailure, /requires an OpenSSL/) |