fluent-plugin-email-obfuscate 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b5589da8d1f315ff538febbe33596f14c9f716d1
4
- data.tar.gz: e78e4f9b610888244cfd4a2e5716f42f3a433743
3
+ metadata.gz: 7ecc5c56f7719e9bae0229b222a93f9802999dc8
4
+ data.tar.gz: 5fa7276948f2f1ea0ec8fbecda015b30870f419f
5
5
  SHA512:
6
- metadata.gz: df54f8e6f6ac2edd5a5717f5be94a67a8ca9c240078b21ebe103fba1397afc0e2bac8de6297418f496001b3c9898df6e223a7f93a2e9510fa24590426905f029
7
- data.tar.gz: f3f6bbe3a21a66a5360821b76e6f6420f3f6c20eea9586763060e6f4c7f2122d2b19acb0d8ad8331720fc3f4297d2b3a317c43ad1c0690b46c0538f48d71b756
6
+ metadata.gz: 6b28e85baf32c876efb6c184b3da1ea7c29317e0a52b8651b8a31fac4a58dd071f1944df3f10a59c500884bf32b63bff7bf57a083c8c0760b85e0dc67c7da26b
7
+ data.tar.gz: 8c3a7376acfa39ad45450493ef81d9fa74936de85e06f45e069470aaad8e7a6472929507ec8cc8a2da5d6ab50dfbf76d09b39f354613c53ed36be03e6e0076d7
@@ -1,4 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.3
3
+ - 2.6
4
+ - 2.5
4
5
  - 2.4
6
+ - 2.3
data/README.md CHANGED
@@ -82,11 +82,12 @@ Use `email_obfuscate` filter.
82
82
 
83
83
  ### mode (default: partial_name)
84
84
 
85
- mode | Action | Example
86
- :-- | :-- | :--
87
- `domain_only` | Only replace all characters in the domain part | `testuser@*******.***`
88
- `partial_name` | Replace all characters in domain and partially in the name | `testu***@*******.***`
89
- `full` | Replace all characters in name and domain part of address | `********@*******.***`
85
+ mode | Action | Example
86
+ :-- | :-- | :--
87
+ `domain_only` | Only replace all characters in the domain part | `testuser@*******.***`
88
+ `partial_name` | Replace all characters in domain and partially in the name | `testu***@*******.***`
89
+ `name_substring` | Replace all characters in name and maintain surrounding context | `My old email address ********@example.com does not work any more`
90
+ `full` | Replace all characters in name and domain part of address | `********@*******.***`
90
91
 
91
92
  _Note: `.` and `@` are never replaced_
92
93
 
@@ -102,12 +103,12 @@ Input | Action
102
103
 
103
104
  ## Todo
104
105
 
105
- * Add tests!
106
106
  * Support configuration of which fields to act upon
107
+ * Fine grained configuration of email delimiters
107
108
  * . . .
108
109
 
109
110
  ## Copyright
110
111
 
111
- * Copyright(c) 2018 JamesJJ
112
+ * Copyright(c) 2018-2019 JamesJJ
112
113
  * License
113
114
  * Apache License, Version 2.0
@@ -3,7 +3,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
 
4
4
  Gem::Specification.new do |spec|
5
5
  spec.name = "fluent-plugin-email-obfuscate"
6
- spec.version = "0.0.4"
6
+ spec.version = "0.0.5"
7
7
  spec.authors = ["JamesJJ"]
8
8
  spec.email = ["jj@fcg.fyi"]
9
9
 
@@ -20,9 +20,10 @@ module Fluent
20
20
  class EmailObfuscateFilter < Fluent::Plugin::Filter
21
21
  Fluent::Plugin.register_filter("email_obfuscate", self)
22
22
 
23
- config_param :mode, :enum, list: [:partial_name, :full, :domain_only], default: :partial_name,
23
+ config_param :mode, :enum, list: [:name_substring, :partial_name, :full, :domain_only], default: :partial_name,
24
24
  desc: <<-DESC
25
25
  'full' will replace all characters.
26
+ 'name_substring' will replace the 'name' half of the address, and attempt to retain surrounding context.
26
27
  'partial_name' will replace all characters in the 'domain' half of the address, and a subset of the 'name'.
27
28
  'domain_only' will only replace characters in the 'domain' half of the address.
28
29
  '.' and '@' are never replaced.
@@ -59,6 +60,8 @@ DESC
59
60
  m[1] + m[2].tr("@.a-zA-Z0-9", "@.*")
60
61
  when :full
61
62
  m[1].gsub(/./, '*') + m[2].tr("@.a-zA-Z0-9", "@.*")
63
+ when :name_substring
64
+ m[1].gsub(/./, '*') + m[2]
62
65
  else
63
66
  hide_partial(m[1]) + m[2].tr("@.a-zA-Z0-9", "@.*")
64
67
  end
@@ -75,8 +78,15 @@ DESC
75
78
  def deep_process(o)
76
79
  case o
77
80
  when String
78
- os = o.scan(/<([^<>]+@[^<>]+)>/)
79
- o = os.length.zero? ? obfuscate(o) : deep_process(os).join(", ")
81
+ case @mode
82
+ when :name_substring
83
+ o = o.gsub(/([a-zA-Z0-9_+\.\-]+@[a-zA-Z0-9\.\-]+)/) { |om|
84
+ obfuscate(om)
85
+ }
86
+ else
87
+ os = o.scan(/<([^<>]+@[^<>]+)>/)
88
+ o = os.length.zero? ? obfuscate(o) : deep_process(os).join(", ")
89
+ end
80
90
  when Array
81
91
  o.map! do |obj|
82
92
  deep_process(obj)
@@ -27,7 +27,8 @@ class EmailObfuscateFilterTest < Test::Unit::TestCase
27
27
  "field": "name3@example.museum"
28
28
  }
29
29
  },
30
- "email_string": "Jane Doe <jane@example.name>, John Smith <john@example.name>"
30
+ "email_string": "Jane Doe <jane@example.name>, John Smith <john@example.name>",
31
+ "email_string_with_trailing_text": "Jane Doe <jane@example.name>, John Smith <john@example.name> trailing text is here"
31
32
  }
32
33
  end
33
34
 
@@ -46,7 +47,9 @@ class EmailObfuscateFilterTest < Test::Unit::TestCase
46
47
  list1: ["user*@*******.***", "user*@*******.***"],
47
48
  a: {nested:
48
49
  {field: "name*@*******.******"}},
49
- email_string: "jane@*******.****, john@*******.****"}]
50
+ email_string: "jane@*******.****, john@*******.****",
51
+ email_string_with_trailing_text: "jane@*******.****, john@*******.****"}
52
+ ]
50
53
  assert_equal expected, d.filtered.map{|e| e.last}
51
54
  end
52
55
 
@@ -59,7 +62,9 @@ class EmailObfuscateFilterTest < Test::Unit::TestCase
59
62
  list1: ["*****@*******.***", "*****@*******.***"],
60
63
  a: {nested:
61
64
  {field: "*****@*******.******"}},
62
- email_string: "****@*******.****, ****@*******.****"}]
65
+ email_string: "****@*******.****, ****@*******.****",
66
+ email_string_with_trailing_text: "****@*******.****, ****@*******.****"}
67
+ ]
63
68
  assert_equal expected, d.filtered.map{|e| e.last}
64
69
  end
65
70
 
@@ -72,12 +77,29 @@ class EmailObfuscateFilterTest < Test::Unit::TestCase
72
77
  list1: ["user1@*******.***", "user2@*******.***"],
73
78
  a: {nested:
74
79
  {field: "name3@*******.******"}},
75
- email_string: "jane@*******.****, john@*******.****"}]
80
+ email_string: "jane@*******.****, john@*******.****",
81
+ email_string_with_trailing_text: "jane@*******.****, john@*******.****"}
82
+ ]
83
+ assert_equal expected, d.filtered.map{|e| e.last}
84
+ end
85
+
86
+ test "filter_name_substring" do
87
+ d = create_driver(CONF + %[mode name_substring])
88
+ d.run(default_tag: 'test') do
89
+ d.feed(sample_records)
90
+ end
91
+ expected = [{f1: "*******@example.net",
92
+ list1: ["*****@example.com", "*****@example.org"],
93
+ a: {nested:
94
+ {field: "*****@example.museum"}},
95
+ email_string: "Jane Doe <****@example.name>, John Smith <****@example.name>",
96
+ email_string_with_trailing_text: "Jane Doe <****@example.name>, John Smith <****@example.name> trailing text is here"}
97
+ ]
76
98
  assert_equal expected, d.filtered.map{|e| e.last}
77
99
  end
78
100
 
79
101
  test "suffix whitelist" do
80
- d = create_driver(CONF + %[suffix_whitelist [".example.com", "@example.com"]])
102
+ d = create_driver(CONF + %[suffix_whitelist [".example.com", "@example.com"]\nmode partial_name])
81
103
  sample_records = {
82
104
  "f1": "myEmail@example.net",
83
105
  "list1": [
@@ -102,6 +124,35 @@ class EmailObfuscateFilterTest < Test::Unit::TestCase
102
124
  assert_equal expected, d.filtered.map{|e| e.last}
103
125
  end
104
126
 
127
+ test "suffix whitelist mode name_substring" do
128
+ d = create_driver(CONF + %[suffix_whitelist [".example.com", "@example.com"]\nmode name_substring])
129
+ sample_records = {
130
+ "f1": "myEmail@example.net",
131
+ "list1": [
132
+ "user1@example.com",
133
+ "user2@subdomain.example.com"
134
+ ],
135
+ "a": {
136
+ "nested": {
137
+ "field": "name3@example.museum"
138
+ }
139
+ },
140
+ "email_string": "Jane Doe <jane@example.name>, John Smith <john@example.name> and some trailing text"
141
+ }
142
+ d.run(default_tag: 'test') do
143
+ d.feed(sample_records)
144
+ end
145
+ expected = [{f1: "*******@example.net",
146
+ list1: ["user1@example.com", "user2@subdomain.example.com"],
147
+ a: {nested:
148
+ {field: "*****@example.museum"}},
149
+ email_string: "Jane Doe <****@example.name>, John Smith <****@example.name> and some trailing text"}]
150
+
151
+
152
+ assert_equal expected, d.filtered.map{|e| e.last}
153
+ end
154
+
155
+
105
156
  private
106
157
 
107
158
  def create_driver(conf = CONF)
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
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - JamesJJ
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-03 00:00:00.000000000 Z
11
+ date: 2019-05-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler