From 9aca8103b2c46609015688da711141214229af01 Mon Sep 17 00:00:00 2001 From: Hiroaki Sano Date: Wed, 26 Dec 2018 20:43:27 +0900 Subject: [PATCH 1/2] Add testing for not working case --- test/plugin/test_filter_pan_anonymizer.rb | 62 +++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/test/plugin/test_filter_pan_anonymizer.rb b/test/plugin/test_filter_pan_anonymizer.rb index 0b4ede8..a855230 100644 --- a/test/plugin/test_filter_pan_anonymizer.rb +++ b/test/plugin/test_filter_pan_anonymizer.rb @@ -120,6 +120,26 @@ def filter(conf, messages) create_driver(conf) end end + test 'regexp has ,' do + conf = %[ + + formats /[0-9]{6}[0-9]{3,9}[0-9]{4}/ + + ] + assert_nothing_raised(Fluent::ConfigError) do + create_driver(conf) + end + end + test 'regexp has "," and multi formats fields' do + conf = %[ + + formats /[0-9]{6}[0-9]{3,9}[0-9]{4}/, /[0-9]{15}\d*/ + + ] + assert_nothing_raised(Fluent::ConfigError) do + create_driver(conf) + end + end end sub_test_case 'normal case' do @@ -165,6 +185,48 @@ def filter(conf, messages) filtered = filter(conf, messages) assert_equal(expected, filtered) end + test "formats has ','" do + conf = %[ + + formats /([0-9]{6})[0-9]{3,9}([0-9]{4})/ + checksum_algorithm luhn + mask xxxx + + ] + messages = [ + { + "key": "4019249331712145" + } + ] + expected = [ + { + "key": "xxxx" + } + ] + filtered = filter(conf, messages) + assert_equal(expected, filtered) + end + test "formats has ',' and mult formats fields" do + conf = %[ + + formats /([0-9]{6})[0-9]{3,9}([0-9]{4})/ , /[0-9]{15}/ + checksum_algorithm luhn + mask xxxx + + ] + messages = [ + { + "key": "4019249331712145" + } + ] + expected = [ + { + "key": "xxxx" + } + ] + filtered = filter(conf, messages) + assert_equal(expected, filtered) + end end sub_test_case 'checksum_algorithm' do From 844d699fda107fd00dc54bcc8f1f6222199f8184 Mon Sep 17 00:00:00 2001 From: Hiroaki Sano Date: Wed, 26 Dec 2018 20:53:04 +0900 Subject: [PATCH 2/2] Fix bug #3 --- lib/fluent/plugin/filter_pan_anonymizer.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/fluent/plugin/filter_pan_anonymizer.rb b/lib/fluent/plugin/filter_pan_anonymizer.rb index be83696..4394434 100644 --- a/lib/fluent/plugin/filter_pan_anonymizer.rb +++ b/lib/fluent/plugin/filter_pan_anonymizer.rb @@ -20,8 +20,13 @@ def initialize def configure(conf) super + formats = conf.each_element.map do |i| + next if i["formats"].nil? + i["formats"].scan(/\/[^\/]*\//).map do |j| j.delete("/") end.map do |j| Regexp.new(j) end + end.flatten + @pan_masker = @pan_configs.map do |i| - i[:formats].map do |format| + formats.map do |format| Fluent::PAN::Masker.new(format, i[:checksum_algorithm], i[:mask], i[:force]) end end.flatten