spec/outputs/s3_spec.rb in logstash-output-s3-4.0.3 vs spec/outputs/s3_spec.rb in logstash-output-s3-4.0.5

- old
+ new

@@ -23,11 +23,11 @@ subject { described_class.new(options) } before do allow(subject).to receive(:bucket_resource).and_return(mock_bucket) - allow(LogStash::Outputs::S3::WriteBucketPermissionValidator).to receive(:valid?).with(mock_bucket).and_return(true) + allow_any_instance_of(LogStash::Outputs::S3::WriteBucketPermissionValidator).to receive(:valid?).with(mock_bucket).and_return(true) end context "#register configuration validation" do describe "signature version" do it "should set the signature version if specified" do @@ -59,10 +59,71 @@ expect(s3.upload_options).to include(:acl => "private") end end end + describe "Service Side Encryption" do + + context "when configured" do + it "should be configure" do + s3 = described_class.new(options.merge({ "server_side_encryption" => true })) + expect(s3.upload_options).to include(:server_side_encryption => "AES256") + end + end + + context "when algorithm is configured" do + ["AES256", "aws:kms"].each do |sse| + it "should return the configured SSE: #{sse}" do + s3 = described_class.new(options.merge({ "server_side_encryption" => true, "server_side_encryption_algorithm" => sse })) + expect(s3.upload_options).to include(:server_side_encryption => sse) + end + end + end + + context "when using SSE with KMS and custom key" do + it "should return the configured KMS key" do + s3 = described_class.new(options.merge({ "server_side_encryption" => true, "server_side_encryption_algorithm" => "aws:kms", "ssekms_key_id" => "test"})) + expect(s3.upload_options).to include(:server_side_encryption => "aws:kms") + expect(s3.upload_options).to include(:ssekms_key_id => "test") + end + end + + context "when using SSE with KMS but no custom key" do + it "should return the configured KMS key" do + s3 = described_class.new(options.merge({ "server_side_encryption" => true, "server_side_encryption_algorithm" => "aws:kms"})) + expect(s3.upload_options).to include(:server_side_encryption => "aws:kms") + expect(s3.upload_options).to include(:ssekms_key_id => nil) + end + end + + context "when not configured" do + it "should not be configured" do + s3 = described_class.new(options) + expect(s3.upload_options).to include(:server_side_encryption => nil) + expect(s3.upload_options).to include(:ssekms_key_id => nil) + end + end + end + + describe "Storage Class" do + context "when configured" do + ["STANDARD", "REDUCED_REDUNDANCY", "STANDARD_IA"].each do |storage_class| + it "should return the configured storage class: #{storage_class}" do + s3 = described_class.new(options.merge({ "storage_class" => storage_class })) + expect(s3.upload_options).to include(:storage_class => storage_class) + end + end + end + + context "when not configured" do + it "uses STANDARD as the default" do + s3 = described_class.new(options) + expect(s3.upload_options).to include(:storage_class => "STANDARD") + end + end + end + describe "temporary directory" do let(:temporary_directory) { Stud::Temporary.pathname } let(:options) { super.merge({ "temporary_directory" => temporary_directory }) } it "creates the directory when it doesn't exist" do @@ -82,10 +143,10 @@ expect { s3.register }.to raise_error(LogStash::ConfigurationError) end it "allow to not validate credentials" do s3 = described_class.new(options.merge({"validate_credentials_on_root_bucket" => false})) - expect(LogStash::Outputs::S3::WriteBucketPermissionValidator).not_to receive(:valid?).with(any_args) + expect_any_instance_of(LogStash::Outputs::S3::WriteBucketPermissionValidator).not_to receive(:valid?).with(any_args) s3.register end end context "receiving events" do