FIX: inconsistency in S3 inventory config (#11112)

Ensures it matches S3 inventory config generation in our hosting.
This commit is contained in:
Penar Musaraj 2020-11-05 08:39:40 -05:00 committed by GitHub
parent 2686d14b9a
commit 9f6c4ad71a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 1 deletions

View File

@ -270,7 +270,7 @@ class S3Inventory
def inventory_configuration
filter_prefix = type
filter_prefix = File.join(bucket_folder_path, filter_prefix) if bucket_folder_path.present?
filter_prefix = bucket_folder_path if bucket_folder_path.present?
{
destination: {

View File

@ -187,4 +187,25 @@ describe "S3Inventory" do
expect(db2.lines.count).to eq(1)
files.values.each { |f| f.close; f.unlink }
end
context "s3 inventory configuration" do
let(:bucket_name) { "s3-upload-bucket" }
let(:subfolder_path) { "subfolder" }
before do
SiteSetting.s3_upload_bucket = "#{bucket_name}/#{subfolder_path}"
end
it "is formatted correctly for subfolders" do
s3_helper = S3Helper.new(SiteSetting.Upload.s3_upload_bucket.downcase, "", client: client)
config = S3Inventory.new(s3_helper, :upload).send(:inventory_configuration)
expect(config[:destination][:s3_bucket_destination][:bucket]).to eq("arn:aws:s3:::#{bucket_name}")
expect(config[:destination][:s3_bucket_destination][:prefix]).to eq("#{subfolder_path}/inventory/1")
expect(config[:id]).to eq("#{subfolder_path}-original")
expect(config[:schedule][:frequency]).to eq("Daily")
expect(config[:included_object_versions]).to eq("Current")
expect(config[:optional_fields]).to eq(["ETag"])
expect(config[:filter][:prefix]).to eq(subfolder_path)
end
end
end