mirror of
https://github.com/discourse/discourse.git
synced 2024-12-17 00:03:43 +08:00
71 lines
2.0 KiB
Ruby
71 lines
2.0 KiB
Ruby
require "s3_helper"
|
|
require "rails_helper"
|
|
|
|
describe "S3Helper" do
|
|
|
|
it "can correctly set the purge policy" do
|
|
|
|
stub_request(:get, "http://169.254.169.254/latest/meta-data/iam/security-credentials/").
|
|
to_return(status: 404, body: "", headers: {})
|
|
|
|
lifecycle = <<~XML
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
<LifecycleConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
|
|
<Rule>
|
|
<ID>old_rule</ID>
|
|
<Prefix>projectdocs/</Prefix>
|
|
<Status>Enabled</Status>
|
|
<Expiration>
|
|
<Days>3650</Days>
|
|
</Expiration>
|
|
</Rule>
|
|
<Rule>
|
|
<ID>purge-tombstone</ID>
|
|
<Prefix>test/</Prefix>
|
|
<Status>Enabled</Status>
|
|
<Expiration>
|
|
<Days>3650</Days>
|
|
</Expiration>
|
|
</Rule>
|
|
</LifecycleConfiguration>
|
|
XML
|
|
|
|
stub_request(:get, "https://bob.s3.amazonaws.com/?lifecycle").
|
|
to_return(status: 200, body: lifecycle, headers: {})
|
|
|
|
stub_request(:put, "https://bob.s3.amazonaws.com/?lifecycle").
|
|
with do |req|
|
|
|
|
hash = Hash.from_xml(req.body.to_s)
|
|
rules = hash["LifecycleConfiguration"]["Rule"]
|
|
|
|
expect(rules.length).to eq(2)
|
|
|
|
# fixes the bad filter
|
|
expect(rules[0]["Filter"]["Prefix"]).to eq("projectdocs/")
|
|
end.to_return(status: 200, body: "", headers: {})
|
|
|
|
SiteSetting.enable_s3_uploads = true
|
|
SiteSetting.s3_access_key_id = "abc"
|
|
SiteSetting.s3_secret_access_key = "def"
|
|
|
|
helper = S3Helper.new('bob', 'tomb')
|
|
helper.update_tombstone_lifecycle(100)
|
|
end
|
|
|
|
describe '#list' do
|
|
it 'creates the prefix correctly' do
|
|
{
|
|
'some/bucket' => 'bucket/testing',
|
|
'some' => 'testing'
|
|
}.each do |bucket_name, prefix|
|
|
s3_helper = S3Helper.new(bucket_name)
|
|
bucket = stub('s3_bucket')
|
|
s3_helper.expects(:s3_bucket).returns(bucket)
|
|
bucket.expects(:objects).with(prefix: prefix)
|
|
s3_helper.list('testing')
|
|
end
|
|
end
|
|
end
|
|
end
|