Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/fluent/plugin/filter_pan_anonymizer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,13 @@ def initialize
def configure(conf)
super

formats = conf.each_element.map do |i|
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't enough to check @pan_configs? I think formats directives are only in <pan> section.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, fluentd can't parse a regexp array correctly.

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
Expand Down
62 changes: 62 additions & 0 deletions test/plugin/test_filter_pan_anonymizer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,26 @@ def filter(conf, messages)
create_driver(conf)
end
end
test 'regexp has ,' do
conf = %[
<pan>
formats /[0-9]{6}[0-9]{3,9}[0-9]{4}/
</pan>
]
assert_nothing_raised(Fluent::ConfigError) do
create_driver(conf)
end
end
test 'regexp has "," and multi formats fields' do
conf = %[
<pan>
formats /[0-9]{6}[0-9]{3,9}[0-9]{4}/, /[0-9]{15}\d*/
</pan>
]
assert_nothing_raised(Fluent::ConfigError) do
create_driver(conf)
end
end
end

sub_test_case 'normal case' do
Expand Down Expand Up @@ -165,6 +185,48 @@ def filter(conf, messages)
filtered = filter(conf, messages)
assert_equal(expected, filtered)
end
test "formats has ','" do
conf = %[
<pan>
formats /([0-9]{6})[0-9]{3,9}([0-9]{4})/
checksum_algorithm luhn
mask xxxx
</pan>
]
messages = [
{
"key": "4019249331712145"
}
]
expected = [
{
"key": "xxxx"
}
]
filtered = filter(conf, messages)
assert_equal(expected, filtered)
end
test "formats has ',' and mult formats fields" do
conf = %[
<pan>
formats /([0-9]{6})[0-9]{3,9}([0-9]{4})/ , /[0-9]{15}/
checksum_algorithm luhn
mask xxxx
</pan>
]
messages = [
{
"key": "4019249331712145"
}
]
expected = [
{
"key": "xxxx"
}
]
filtered = filter(conf, messages)
assert_equal(expected, filtered)
end
end

sub_test_case 'checksum_algorithm' do
Expand Down