fluent-plugin-email-obfuscate 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +4 -0
- data/README.md +1 -0
- data/fluent-plugin-email-obfuscate.gemspec +1 -1
- data/lib/fluent/plugin/filter_email_obfuscate.rb +3 -8
- data/test/plugin/test_filter_email_obfuscate.rb +95 -3
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b5589da8d1f315ff538febbe33596f14c9f716d1
|
4
|
+
data.tar.gz: e78e4f9b610888244cfd4a2e5716f42f3a433743
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df54f8e6f6ac2edd5a5717f5be94a67a8ca9c240078b21ebe103fba1397afc0e2bac8de6297418f496001b3c9898df6e223a7f93a2e9510fa24590426905f029
|
7
|
+
data.tar.gz: f3f6bbe3a21a66a5360821b76e6f6420f3f6c20eea9586763060e6f4c7f2122d2b19acb0d8ad8331720fc3f4297d2b3a317c43ad1c0690b46c0538f48d71b756
|
data/.gitignore
CHANGED
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -4,6 +4,7 @@
|
|
4
4
|
|
5
5
|
[](https://www.codefactor.io/repository/github/JamesJJ/fluent-plugin-email-obfuscate)
|
6
6
|
[](https://badge.fury.io/rb/fluent-plugin-email-obfuscate)
|
7
|
+
[](https://travis-ci.com/JamesJJ/fluent-plugin-email-obfuscate)
|
7
8
|
|
8
9
|
This filter attempts to parse each field in the record, and will obfuscate all or part of any email addresses it finds, by replacing with the same number of asterisks.
|
9
10
|
|
@@ -20,7 +20,7 @@ module Fluent
|
|
20
20
|
class EmailObfuscateFilter < Fluent::Plugin::Filter
|
21
21
|
Fluent::Plugin.register_filter("email_obfuscate", self)
|
22
22
|
|
23
|
-
config_param :mode, :
|
23
|
+
config_param :mode, :enum, list: [:partial_name, :full, :domain_only], default: :partial_name,
|
24
24
|
desc: <<-DESC
|
25
25
|
'full' will replace all characters.
|
26
26
|
'partial_name' will replace all characters in the 'domain' half of the address, and a subset of the 'name'.
|
@@ -38,11 +38,6 @@ DESC
|
|
38
38
|
|
39
39
|
def configure(conf)
|
40
40
|
super
|
41
|
-
|
42
|
-
if conf.has_key?('mode')
|
43
|
-
raise ConfigError, "'mode' must be one of: domain_only, full, partial_name" unless
|
44
|
-
['domain_only', 'full', 'partial_name'].include?(conf.dig('mode'))
|
45
|
-
end
|
46
41
|
end
|
47
42
|
|
48
43
|
def hide_partial(str)
|
@@ -60,9 +55,9 @@ DESC
|
|
60
55
|
def obfuscate(str)
|
61
56
|
strmatch = str.match(/^([^@]+)(@.+)$/) { |m|
|
62
57
|
case @mode
|
63
|
-
when
|
58
|
+
when :domain_only
|
64
59
|
m[1] + m[2].tr("@.a-zA-Z0-9", "@.*")
|
65
|
-
when
|
60
|
+
when :full
|
66
61
|
m[1].gsub(/./, '*') + m[2].tr("@.a-zA-Z0-9", "@.*")
|
67
62
|
else
|
68
63
|
hide_partial(m[1]) + m[2].tr("@.a-zA-Z0-9", "@.*")
|
@@ -6,13 +6,105 @@ class EmailObfuscateFilterTest < Test::Unit::TestCase
|
|
6
6
|
Fluent::Test.setup
|
7
7
|
end
|
8
8
|
|
9
|
-
|
10
|
-
|
9
|
+
CONF = %[
|
10
|
+
]
|
11
|
+
|
12
|
+
def test_configure
|
13
|
+
d = create_driver
|
14
|
+
assert_equal :partial_name, d.instance.mode
|
15
|
+
assert_equal [], d.instance.suffix_whitelist
|
16
|
+
end
|
17
|
+
|
18
|
+
def sample_records
|
19
|
+
{
|
20
|
+
"f1": "myEmail@example.net",
|
21
|
+
"list1": [
|
22
|
+
"user1@example.com",
|
23
|
+
"user2@example.org"
|
24
|
+
],
|
25
|
+
"a": {
|
26
|
+
"nested": {
|
27
|
+
"field": "name3@example.museum"
|
28
|
+
}
|
29
|
+
},
|
30
|
+
"email_string": "Jane Doe <jane@example.name>, John Smith <john@example.name>"
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
34
|
+
test "invalid mode" do
|
35
|
+
assert_raise(Fluent::ConfigError) do
|
36
|
+
create_driver(CONF + %[mode invalid])
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
test "filter" do
|
41
|
+
d = create_driver
|
42
|
+
d.run(default_tag: 'test') do
|
43
|
+
d.feed(sample_records)
|
44
|
+
end
|
45
|
+
expected = [{f1: "myEma**@*******.***",
|
46
|
+
list1: ["user*@*******.***", "user*@*******.***"],
|
47
|
+
a: {nested:
|
48
|
+
{field: "name*@*******.******"}},
|
49
|
+
email_string: "jane@*******.****, john@*******.****"}]
|
50
|
+
assert_equal expected, d.filtered.map{|e| e.last}
|
51
|
+
end
|
52
|
+
|
53
|
+
test "filter_full" do
|
54
|
+
d = create_driver(CONF + %[mode full])
|
55
|
+
d.run(default_tag: 'test') do
|
56
|
+
d.feed(sample_records)
|
57
|
+
end
|
58
|
+
expected = [{f1: "*******@*******.***",
|
59
|
+
list1: ["*****@*******.***", "*****@*******.***"],
|
60
|
+
a: {nested:
|
61
|
+
{field: "*****@*******.******"}},
|
62
|
+
email_string: "****@*******.****, ****@*******.****"}]
|
63
|
+
assert_equal expected, d.filtered.map{|e| e.last}
|
64
|
+
end
|
65
|
+
|
66
|
+
test "filter_domain_only" do
|
67
|
+
d = create_driver(CONF + %[mode domain_only])
|
68
|
+
d.run(default_tag: 'test') do
|
69
|
+
d.feed(sample_records)
|
70
|
+
end
|
71
|
+
expected = [{f1: "myEmail@*******.***",
|
72
|
+
list1: ["user1@*******.***", "user2@*******.***"],
|
73
|
+
a: {nested:
|
74
|
+
{field: "name3@*******.******"}},
|
75
|
+
email_string: "jane@*******.****, john@*******.****"}]
|
76
|
+
assert_equal expected, d.filtered.map{|e| e.last}
|
77
|
+
end
|
78
|
+
|
79
|
+
test "suffix whitelist" do
|
80
|
+
d = create_driver(CONF + %[suffix_whitelist [".example.com", "@example.com"]])
|
81
|
+
sample_records = {
|
82
|
+
"f1": "myEmail@example.net",
|
83
|
+
"list1": [
|
84
|
+
"user1@example.com",
|
85
|
+
"user2@subdomain.example.com"
|
86
|
+
],
|
87
|
+
"a": {
|
88
|
+
"nested": {
|
89
|
+
"field": "name3@example.museum"
|
90
|
+
}
|
91
|
+
},
|
92
|
+
"email_string": "Jane Doe <jane@example.name>, John Smith <john@example.name>"
|
93
|
+
}
|
94
|
+
d.run(default_tag: 'test') do
|
95
|
+
d.feed(sample_records)
|
96
|
+
end
|
97
|
+
expected = [{f1: "myEma**@*******.***",
|
98
|
+
list1: ["user1@example.com", "user2@subdomain.example.com"],
|
99
|
+
a: {nested:
|
100
|
+
{field: "name*@*******.******"}},
|
101
|
+
email_string: "jane@*******.****, john@*******.****"}]
|
102
|
+
assert_equal expected, d.filtered.map{|e| e.last}
|
11
103
|
end
|
12
104
|
|
13
105
|
private
|
14
106
|
|
15
|
-
def create_driver(conf)
|
107
|
+
def create_driver(conf = CONF)
|
16
108
|
Fluent::Test::Driver::Filter.new(Fluent::Plugin::EmailObfuscateFilter).configure(conf)
|
17
109
|
end
|
18
110
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-email-obfuscate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- JamesJJ
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-10-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -80,6 +80,7 @@ extensions: []
|
|
80
80
|
extra_rdoc_files: []
|
81
81
|
files:
|
82
82
|
- ".gitignore"
|
83
|
+
- ".travis.yml"
|
83
84
|
- Gemfile
|
84
85
|
- LICENSE
|
85
86
|
- README.md
|
@@ -109,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
109
110
|
version: '0'
|
110
111
|
requirements: []
|
111
112
|
rubyforge_project:
|
112
|
-
rubygems_version: 2.
|
113
|
+
rubygems_version: 2.5.2.3
|
113
114
|
signing_key:
|
114
115
|
specification_version: 4
|
115
116
|
summary: Fluentd filter plugin to obfuscate email addresses
|