From 57f957a342a965c127eb94b060de07a3522134c8 Mon Sep 17 00:00:00 2001 From: TAGOMORI Satoshi Date: Mon, 30 Jan 2017 17:04:51 +0900 Subject: [PATCH] add validator for usage of storage plugins --- lib/fluent/plugin_helper/storage.rb | 6 ++++++ test/plugin_helper/test_storage.rb | 11 +++++++++++ 2 files changed, 17 insertions(+) diff --git a/lib/fluent/plugin_helper/storage.rb b/lib/fluent/plugin_helper/storage.rb index a41c594c47..78dd5ef6d0 100644 --- a/lib/fluent/plugin_helper/storage.rb +++ b/lib/fluent/plugin_helper/storage.rb @@ -33,6 +33,9 @@ def storage_create(usage: '', type: nil, conf: nil, default_type: nil) if conf && !conf.arg.empty? usage = conf.arg end + if !usage.empty? && usage !~ /^[a-zA-Z][-_.a-zA-Z0-9]*$/ + raise Fluent::ConfigError, "Argument in uses invalid characters: '#{usage}'" + end s = @_storages[usage] if s && s.running @@ -98,6 +101,9 @@ def configure(conf) super @storage_configs.each do |section| + if !section.usage.empty? && section.usage !~ /^[a-zA-Z][-_.a-zA-Z0-9]*$/ + raise Fluent::ConfigError, "Argument in uses invalid characters: '#{section.usage}'" + end if @_storages[section.usage] raise Fluent::ConfigError, "duplicated storages configured: #{section.usage}" end diff --git a/test/plugin_helper/test_storage.rb b/test/plugin_helper/test_storage.rb index 7f36329acc..f77a95ccab 100644 --- a/test/plugin_helper/test_storage.rb +++ b/test/plugin_helper/test_storage.rb @@ -135,6 +135,17 @@ class Dummy2 < Fluent::Plugin::TestBase end end + test 'raises config error if config argument has invalid characters' do + d = Dummy.new + assert_raise Fluent::ConfigError.new("Argument in uses invalid characters: 'yaa y'") do + d.configure(config_element('root', '', {}, [config_element('storage', 'yaa y', {'@type' => 'local'})])) + end + d.configure(config_element()) + assert_raise Fluent::ConfigError.new("Argument in uses invalid characters: 'a,b'") do + d.storage_create(usage: 'a,b', type: 'local') + end + end + test 'can be configured without storage sections' do d = Dummy.new assert_nothing_raised do