test/test_out_s3.rb in fluent-plugin-s3-1.2.1 vs test/test_out_s3.rb in fluent-plugin-s3-1.3.0
- old
+ new
@@ -8,10 +8,11 @@
require 'test/unit/rr'
require 'zlib'
require 'fileutils'
require 'timecop'
require 'uuidtools'
+require 'ostruct'
include Fluent::Test::Helpers
class S3OutputTest < Test::Unit::TestCase
def setup
@@ -425,10 +426,11 @@
end
end
def setup_mocks(exists_return = false)
@s3_client = stub(Aws::S3::Client.new(stub_responses: true))
+ stub(@s3_client).config { OpenStruct.new({region: "us-east-1"}) }
# aws-sdk-s3 calls Client#put_object inside Object#put
mock(@s3_client).put_object(anything).at_least(0) { MockResponse.new({}) }
mock(Aws::S3::Client).new(anything).at_least(0) { @s3_client }
@s3_resource = mock(Aws::S3::Resource.new(client: @s3_client))
mock(Aws::S3::Resource).new(client: @s3_client) { @s3_resource }
@@ -462,10 +464,11 @@
@s3_bucket.object(s3path) { s3obj }
end
def setup_mocks_hardened_policy()
@s3_client = stub(Aws::S3::Client.new(:stub_responses => true))
+ stub(@s3_client).config { OpenStruct.new({region: "us-east-1"}) }
mock(@s3_client).put_object(anything).at_least(0) { MockResponse.new({}) }
mock(Aws::S3::Client).new(anything).at_least(0) { @s3_client }
@s3_resource = mock(Aws::S3::Resource.new(:client => @s3_client))
mock(Aws::S3::Resource).new(:client => @s3_client) { @s3_resource }
@s3_bucket = mock(Aws::S3::Bucket.new(:name => "test",
@@ -554,9 +557,35 @@
s3_region ap-northeast-1
<assume_role_credentials>
role_arn test_arn
role_session_name test_session
</assume_role_credentials>
+ ]
+ d = create_time_sliced_driver(config)
+ assert_nothing_raised { d.run {} }
+ client = d.instance.instance_variable_get(:@s3).client
+ credentials = client.config.credentials
+ assert_equal(expected_credentials, credentials)
+ end
+
+ def test_web_identity_credentials
+ expected_credentials = Aws::Credentials.new("test_key", "test_secret")
+ mock(Aws::AssumeRoleWebIdentityCredentials).new(
+ role_arn: "test_arn",
+ role_session_name: "test_session",
+ web_identity_token_file: "test_file",
+ client: anything
+ ){
+ expected_credentials
+ }
+
+ config = CONFIG_TIME_SLICE.split("\n").reject{|x| x =~ /.+aws_.+/}.join("\n")
+ config += %[
+ <web_identity_credentials>
+ role_arn test_arn
+ role_session_name test_session
+ web_identity_token_file test_file
+ </web_identity_credentials>
]
d = create_time_sliced_driver(config)
assert_nothing_raised { d.run {} }
client = d.instance.instance_variable_get(:@s3).client
credentials = client.config.credentials