-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathfingerprint_spec.rb
More file actions
431 lines (375 loc) · 11.1 KB
/
Copy pathfingerprint_spec.rb
File metadata and controls
431 lines (375 loc) · 11.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
# encoding: utf-8
require "logstash/devutils/rspec/spec_helper"
require "logstash/filters/fingerprint"
describe LogStash::Filters::Fingerprint do
describe "fingerprint ipaddress with IPV4_NETWORK method" do
config <<-CONFIG
filter {
fingerprint {
source => ["clientip"]
method => "IPV4_NETWORK"
key => 24
}
}
CONFIG
sample("clientip" => "233.255.13.44") do
insist { subject.get("fingerprint") } == "233.255.13.0"
end
end
describe "fingerprint ipaddress with IPV6_NETWORK method" do
config <<-CONFIG
filter {
fingerprint {
source => ["clientip"]
method => "IPV6_NETWORK"
key => 112
}
}
CONFIG
sample("clientip" => "2001:db8:85a3::8a2e:370:7334") do
insist { subject.get("fingerprint") } == "2001:db8:85a3::8a2e:370:0"
end
end
describe "fingerprint string with MURMUR3 method" do
config <<-CONFIG
filter {
fingerprint {
source => ["clientip"]
method => "MURMUR3"
}
}
CONFIG
sample("clientip" => "123.52.122.33") do
insist { subject.get("fingerprint") } == 1541804874
end
end
describe "fingerprint string with SHA1 algorithm" do
config <<-CONFIG
filter {
fingerprint {
source => ["clientip"]
method => 'SHA1'
}
}
CONFIG
sample("clientip" => "123.123.123.123") do
insist { subject.get("fingerprint") } == "3a5076c520b4b463f43806896ea0b3978d09dcae"
end
end
describe "fingerprint string with SHA1 HMAC algorithm" do
config <<-CONFIG
filter {
fingerprint {
source => ["clientip"]
key => "longencryptionkey"
method => 'SHA1'
}
}
CONFIG
sample("clientip" => "123.123.123.123") do
insist { subject.get("fingerprint") } == "fdc60acc4773dc5ac569ffb78fcb93c9630797f4"
end
end
describe "fingerprint string with SHA1 HMAC algorithm on all event fields" do
config <<-CONFIG
filter {
fingerprint {
concatenate_all_fields => true
key => "longencryptionkey"
method => 'SHA1'
}
}
CONFIG
# The @timestamp field is specified in this sample event as we need the event contents to be constant for the tests
sample("@timestamp" => "2017-07-26T14:44:27.064Z", "clientip" => "123.123.123.123", "message" => "This is a test message", "log_level" => "INFO", "offset" => 123456789, "type" => "test") do
insist { subject.get("fingerprint") } == "d7c617f4d40b2cb677a7003af68a41c415f58031"
end
end
describe "fingerprint string with SHA1 algorithm and base64 encoding" do
config <<-CONFIG
filter {
fingerprint {
source => ["clientip"]
method => 'SHA1'
base64encode => true
}
}
CONFIG
sample("clientip" => "123.123.123.123") do
insist { subject.get("fingerprint") } == "OlB2xSC0tGP0OAaJbqCzl40J3K4="
end
end
describe "fingerprint string with SHA1 HMAC algorithm and base64 encoding" do
config <<-CONFIG
filter {
fingerprint {
source => ["clientip"]
key => "longencryptionkey"
method => 'SHA1'
base64encode => true
}
}
CONFIG
sample("clientip" => "123.123.123.123") do
insist { subject.get("fingerprint") } == "/cYKzEdz3FrFaf+3j8uTyWMHl/Q="
end
end
describe "fingerprint string with SHA256 algorithm" do
config <<-CONFIG
filter {
fingerprint {
source => ["clientip"]
method => 'SHA256'
}
}
CONFIG
sample("clientip" => "123.123.123.123") do
insist { subject.get("fingerprint") } == "4dabcab210766e35f03e77120e6986d6e6d4752b2a9ff22980b9253d026080d8"
end
end
describe "fingerprint string with SHA256 HMAC algorithm" do
config <<-CONFIG
filter {
fingerprint {
source => ["clientip"]
key => "longencryptionkey"
method => 'SHA256'
}
}
CONFIG
sample("clientip" => "123.123.123.123") do
insist { subject.get("fingerprint") } == "345bec3eff242d53b568916c2610b3e393d885d6b96d643f38494fd74bf4a9ca"
end
end
describe "fingerprint string with SHA256 HMAC algorithm and base64 encoding" do
config <<-CONFIG
filter {
fingerprint {
source => ["clientip"]
key => "longencryptionkey"
method => 'SHA256'
base64encode => true
}
}
CONFIG
sample("clientip" => "123.123.123.123") do
insist { subject.get("fingerprint") } == "NFvsPv8kLVO1aJFsJhCz45PYhda5bWQ/OElP10v0qco="
end
end
describe "fingerprint string with SHA384 algorithm" do
config <<-CONFIG
filter {
fingerprint {
source => ["clientip"]
method => 'SHA384'
}
}
CONFIG
sample("clientip" => "123.123.123.123") do
insist { subject.get("fingerprint") } == "fd605b0a3af3e04ce0d7a0b0d9c48d67a12dab811f60072e6eae84e35d567793ffb68a1807536f11c90874065c2a4392"
end
end
describe "fingerprint string with SHA384 HMAC algorithm" do
config <<-CONFIG
filter {
fingerprint {
source => ["clientip"]
key => "longencryptionkey"
method => 'SHA384'
}
}
CONFIG
sample("clientip" => "123.123.123.123") do
insist { subject.get("fingerprint") } == "22d4c0e8c4fbcdc4887d2038fca7650f0e2e0e2457ff41c06eb2a980dded6749561c814fe182aff93e2538d18593947a"
end
end
describe "fingerprint string with SHA384 HMAC algorithm and base64 encoding" do
config <<-CONFIG
filter {
fingerprint {
source => ["clientip"]
key => "longencryptionkey"
method => 'SHA384'
base64encode => true
}
}
CONFIG
sample("clientip" => "123.123.123.123") do
insist { subject.get("fingerprint") } == "ItTA6MT7zcSIfSA4/KdlDw4uDiRX/0HAbrKpgN3tZ0lWHIFP4YKv+T4lONGFk5R6"
end
end
describe "fingerprint string with SHA512 algorithm" do
config <<-CONFIG
filter {
fingerprint {
source => ["clientip"]
method => 'SHA512'
}
}
CONFIG
sample("clientip" => "123.123.123.123") do
insist { subject.get("fingerprint") } == "5468e2dc64ea92b617782aae884b35af60041ac9e168a283615b6a462c54c13d42fa9542cce9b7d76a8124ac6616818905e3e5dd35d6e519f77c3b517558639a"
end
end
describe "fingerprint string with SHA512 HMAC algorithm" do
config <<-CONFIG
filter {
fingerprint {
source => ["clientip"]
key => "longencryptionkey"
method => 'SHA512'
}
}
CONFIG
sample("clientip" => "123.123.123.123") do
insist { subject.get("fingerprint") } == "11c19b326936c08d6c50a3c847d883e5a1362e6a64dd55201a25f2c1ac1b673f7d8bf15b8f112a4978276d573275e3b14166e17246f670c2a539401c5bfdace8"
end
end
describe "fingerprint string with SHA512 HMAC algorithm and base64 encoding" do
config <<-CONFIG
filter {
fingerprint {
source => ["clientip"]
key => "longencryptionkey"
method => 'SHA512'
base64encode => true
}
}
CONFIG
sample("clientip" => "123.123.123.123") do
insist { subject.get("fingerprint") } == "EcGbMmk2wI1sUKPIR9iD5aE2Lmpk3VUgGiXywawbZz99i/FbjxEqSXgnbVcydeOxQWbhckb2cMKlOUAcW/2s6A=="
end
end
describe "fingerprint string with MD5 algorithm" do
config <<-CONFIG
filter {
fingerprint {
source => ["clientip"]
method => 'MD5'
}
}
CONFIG
sample("clientip" => "123.123.123.123") do
insist { subject.get("fingerprint") } == "ccdd8d3d940a01b2fb3258c059924c0d"
end
end
describe "fingerprint string with MD5 HMAC algorithm" do
config <<-CONFIG
filter {
fingerprint {
source => ["clientip"]
key => "longencryptionkey"
method => 'MD5'
}
}
CONFIG
sample("clientip" => "123.123.123.123") do
insist { subject.get("fingerprint") } == "9336c879e305c9604a3843fc3e75948f"
end
end
describe "fingerprint string with MD5 HMAC algorithm and base64 encoding" do
config <<-CONFIG
filter {
fingerprint {
source => ["clientip"]
key => "longencryptionkey"
method => 'MD5'
base64encode => true
}
}
CONFIG
sample("clientip" => "123.123.123.123") do
insist { subject.get("fingerprint") } == "kzbIeeMFyWBKOEP8PnWUjw=="
end
end
describe "Test field with multiple values" do
config <<-CONFIG
filter {
fingerprint {
source => ["clientip"]
key => "longencryptionkey"
method => 'MD5'
}
}
CONFIG
sample("clientip" => [ "123.123.123.123", "223.223.223.223" ]) do
insist { subject.get("fingerprint")} == [ "9336c879e305c9604a3843fc3e75948f", "7a6c66b8d3f42a7d650e3354af508df3" ]
end
end
describe "Concatenate multiple values into 1" do
config <<-CONFIG
filter {
fingerprint {
source => ['field1', 'field2']
key => "longencryptionkey"
method => 'MD5'
}
}
CONFIG
sample("field1" => "test1", "field2" => "test2") do
insist { subject.get("fingerprint")} == "872da745e45192c2a1d4bf7c1ff8a370"
end
end
describe "PUNCTUATION method" do
config <<-CONFIG
filter {
fingerprint {
source => 'field1'
method => 'PUNCTUATION'
}
}
CONFIG
sample("field1" => "PHP Warning: json_encode() [<a href='function.json-encode'>function.json-encode</a>]: Invalid UTF-8 sequence in argument in /var/www/htdocs/test.php on line 233") do
insist { subject.get("fingerprint") } == ":_()[<='.-'>.-</>]:-////."
end
sample("field1" => "Warning: Ruby(ルビ) is an awesome language.") do
insist { subject.get("fingerprint") } == ":()."
end
end
context 'Timestamps' do
epoch_time = Time.at(0).gmtime
describe 'OpenSSL Fingerprinting' do
config <<-CONFIG
filter {
fingerprint {
source => ['@timestamp']
key => '0123'
method => 'SHA1'
}
}
CONFIG
sample("@timestamp" => epoch_time) do
insist { subject.get("fingerprint") } == '1d5379ec92d86a67cfc642d55aa050ca312d3b9a'
end
end
describe 'MURMUR3 Fingerprinting' do
config <<-CONFIG
filter {
fingerprint {
source => ['@timestamp']
method => 'MURMUR3'
}
}
CONFIG
sample("@timestamp" => epoch_time) do
insist { subject.get("fingerprint") } == 743372282
end
end
end
describe "execution triggers addition of fields and tags" do
config <<-CONFIG
filter {
fingerprint {
source => 'field1'
method => 'PUNCTUATION'
add_field => { 'myfield' => 'myvalue' }
add_tag => ['mytag']
}
}
CONFIG
sample("field1" => "Hello, World!") do
insist { subject.get("myfield") } == "myvalue"
insist { subject.get("tags") } == ["mytag"]
end
end
end