forked from toshihirock/node-elb-log-parser
-
Notifications
You must be signed in to change notification settings - Fork 9
/
test.js
422 lines (407 loc) · 23.1 KB
/
test.js
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
var tap = require('tap')
var parse = require('./index.js')
tap.test('http traffic', function (t) {
var parsed = parse(
'http 2015-05-13T23:39:43.945958Z my-loadbalancer 192.168.131.39:2817 10.0.0.1:80 0.000073 0.001048 0.000057 200 200 0 29 "GET http://www.example.com:80/ HTTP/1.1" "curl/7.38.0" - - arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/my-targets/73e2d6bc24d8a067 "Root=1-58337262-36d228ad5d99923122bbe354"'
)
t.equal(parsed.type, 'http', 'we have type')
t.equal(parsed.timestamp, '2015-05-13T23:39:43.945958Z', 'we have timestamp')
t.equal(parsed.elb, 'my-loadbalancer', 'we have ELB')
t.equal(parsed.client, '192.168.131.39', 'we have client')
t.equal(parsed.client_port, 2817, 'we have client_port')
t.equal(parsed.target, '10.0.0.1', 'we have target')
t.equal(parsed.target_port, 80, 'we have target_port')
t.equal(
parsed.request_processing_time,
0.000073,
'we have request_processing_time'
)
t.equal(
parsed.target_processing_time,
0.001048,
'we have target_processing_time'
)
t.equal(
parsed.response_processing_time,
0.000057,
'we have response_processing_time'
)
t.equal(parsed.elb_status_code, 200, 'we have elb_status_code')
t.equal(parsed.target_status_code, 200, 'we have target_status_code')
t.equal(parsed.received_bytes, 0, 'we have received_bytes')
t.equal(parsed.sent_bytes, 29, 'we have sent_bytes')
t.equal(
parsed.request,
'GET http://www.example.com:80/ HTTP/1.1',
'we have request'
)
t.equal(parsed.request_method, 'GET', 'we have request_method')
t.equal(
parsed.request_uri,
'http://www.example.com:80/',
'we have request_uri'
)
t.equal(
parsed.request_http_version,
'HTTP/1.1',
'we have request_http_version'
)
t.equal(parsed.request_uri_scheme, 'http:', 'we have request_uri_scheme')
t.equal(
parsed.request_uri_host,
'www.example.com',
'we have request_uri_host'
)
t.equal(parsed.request_uri_port, 80, 'we have request_uri_port')
t.equal(parsed.request_uri_path, '/', 'we have request_uri_path')
t.equal(parsed.request_uri_query, null, 'we have request_uri_query')
t.equal(parsed.user_agent, 'curl/7.38.0', 'we have user_anget')
t.equal(parsed.ssl_cipher, '-', 'we have ssl_cipher')
t.equal(parsed.ssl_protocol, '-', 'we have ssl_protocol')
t.equal(
parsed.target_group_arn,
'arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/my-targets/73e2d6bc24d8a067',
'we have target_group_arn'
)
t.equal(
parsed.trace_id,
'Root=1-58337262-36d228ad5d99923122bbe354',
'we have trace_id'
)
t.end()
})
tap.test('https traffic', function (t) {
var parsed = parse(
'https 2018-07-02T22:23:00.186641Z app/my-loadbalancer/50dc6c495c0c9188 192.168.131.39:2817 10.0.0.1:80 0.086 0.048 0.037 200 200 0 57 "GET https://www.example.com:443/ HTTP/1.1" "curl/7.46.0" ECDHE-RSA-AES128-GCM-SHA256 TLSv1.2 arn:aws:elasticloadbalancing:us-east-2:123456789012:targetgroup/my-targets/73e2d6bc24d8a067 "Root=1-58337281-1d84f3d73c47ec4e58577259" "www.example.com" "arn:aws:acm:us-east-2:123456789012:certificate/12345678-1234-1234-1234-123456789012"1 2018-07-02T22:22:48.364000Z "authenticate,forward" "-" "-"'
)
t.equal(parsed.type, 'https', 'we have type')
t.equal(parsed.timestamp, '2018-07-02T22:23:00.186641Z', 'we have timestamp')
t.equal(parsed.elb, 'app/my-loadbalancer/50dc6c495c0c9188', 'we have elb')
t.equal(parsed.client, '192.168.131.39', 'we have client')
t.equal(parsed.client_port, 2817, 'we have client_port')
t.equal(parsed.target, '10.0.0.1', 'we have target')
t.equal(parsed.request_processing_time, 0.086, 'we have request_processing_time')
t.equal(parsed.target_processing_time, 0.048, 'we have target_processing_time')
t.equal(parsed.response_processing_time, 0.037, 'we have response_processing_time')
t.equal(parsed.elb_status_code, 200, 'we have elb_status_code')
t.equal(parsed.target_status_code, 200, 'we have target_status_code')
t.equal(parsed.received_bytes, 0, 'we have received_bytes')
t.equal(parsed.sent_bytes, 57, 'we have sent_bytes')
t.equal(parsed.request, 'GET https://www.example.com:443/ HTTP/1.1', 'we have request')
t.equal(parsed.user_agent, 'curl/7.46.0', 'we have user_agent')
t.equal(parsed.ssl_cipher, 'ECDHE-RSA-AES128-GCM-SHA256', 'we have ssl_cipher')
t.equal(parsed.ssl_protocol, 'TLSv1.2', 'we have ssl_protocol')
t.equal(parsed.target_group_arn, 'arn:aws:elasticloadbalancing:us-east-2:123456789012:targetgroup/my-targets/73e2d6bc24d8a067', 'we have target_group_arn')
t.equal(parsed.trace_id, 'Root=1-58337281-1d84f3d73c47ec4e58577259', 'we have trace_id')
t.equal(parsed.domain_name, 'www.example.com', 'we have domain_name')
t.equal(parsed.chosen_cert_arn, 'arn:aws:acm:us-east-2:123456789012:certificate/12345678-1234-1234-1234-123456789012', 'we have chosen_cert_arn')
t.equal(parsed.target_port, 80, 'we have target_port')
t.equal(parsed.request_method, 'GET', 'we have request_method')
t.equal(parsed.request_uri, 'https://www.example.com:443/', 'we have request_uri')
t.equal(parsed.request_http_version, 'HTTP/1.1', 'we have request_http_version')
t.equal(parsed.request_uri_scheme, 'https:', 'we have request_uri_scheme')
t.equal(parsed.request_uri_host, 'www.example.com', 'we have request_uri_host')
t.equal(parsed.request_uri_port, 443, 'we have request_uri_port')
t.equal(parsed.request_uri_path, '/', 'we have request_uri_path')
t.equal(parsed.request_uri_query, null, 'we have request_uri_query')
t.end()
})
tap.test('https traffic', function (t) {
var parsed = parse(
'https 2015-05-13T23:39:43.945958Z my-loadbalancer 192.168.131.39:2817 10.0.0.1:80 0.000086 0.001048 0.001337 200 200 0 57 "GET https://mytest-111.ap-northeast-1.elb.amazonaws.com:443/p/a/t/h?foo=bar&hoge=fuga HTTP/1.1" "curl/7.38.0" DHE-RSA-AES128-SHA TLSv1.2 arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/my-targets/73e2d6bc24d8a067 "Root=1-58337262-36d228ad5d99923122bbe354"'
)
t.equal(parsed.timestamp, '2015-05-13T23:39:43.945958Z', 'we have timestamp')
t.equal(parsed.elb, 'my-loadbalancer', 'we have ELB')
t.equal(parsed.client, '192.168.131.39', 'we have client')
t.equal(parsed.client_port, 2817, 'we have client_port')
t.equal(parsed.target, '10.0.0.1', 'we have target')
t.equal(parsed.target_port, 80, 'we have target_port')
t.equal(
parsed.request_processing_time,
0.000086,
'we have request_processing_time'
)
t.equal(
parsed.target_processing_time,
0.001048,
'we have target_processing_time'
)
t.equal(
parsed.response_processing_time,
0.001337,
'we have response_processing_time'
)
t.equal(parsed.elb_status_code, 200, 'we have elb_status_code')
t.equal(parsed.target_status_code, 200, 'we have target_status_code')
t.equal(parsed.received_bytes, 0, 'we have received_bytes')
t.equal(parsed.sent_bytes, 57, 'we have sent_bytes')
t.equal(
parsed.request,
'GET https://mytest-111.ap-northeast-1.elb.amazonaws.com:443/p/a/t/h?foo=bar&hoge=fuga HTTP/1.1',
'we have request'
)
t.equal(parsed.request_method, 'GET', 'we have request_method')
t.equal(
parsed.request_uri,
'https://mytest-111.ap-northeast-1.elb.amazonaws.com:443/p/a/t/h?foo=bar&hoge=fuga',
'we have request_uri'
)
t.equal(
parsed.request_http_version,
'HTTP/1.1',
'we have request_http_version'
)
t.equal(parsed.request_uri_scheme, 'https:', 'we have request_uri_scheme')
t.equal(
parsed.request_uri_host,
'mytest-111.ap-northeast-1.elb.amazonaws.com',
'we have request_uri_host'
)
t.equal(parsed.request_uri_port, 443, 'we have request_uri_port')
t.equal(parsed.request_uri_path, '/p/a/t/h', 'we have request_uri_path')
t.equal(
parsed.request_uri_query,
'foo=bar&hoge=fuga',
'we have request_uri_query'
)
t.equal(parsed.user_agent, 'curl/7.38.0', 'we have user_anget')
t.equal(parsed.ssl_cipher, 'DHE-RSA-AES128-SHA', 'we have ssl_cipher')
t.equal(parsed.ssl_protocol, 'TLSv1.2', 'we have ssl_protocol')
t.end()
})
tap.test('tcp traffic', function (t) {
var parsed = parse(
'http 2015-05-13T23:39:43.945958Z my-loadbalancer 192.168.131.39:2817 10.0.0.1:80 0.001069 0.000028 0.000041 - - 82 305 "- - - " "-" - - arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/my-targets/73e2d6bc24d8a067 "Root=1-58337262-36d228ad5d99923122bbe354"'
)
t.equal(parsed.request, '- - - ', 'we have request')
t.equal(parsed.user_agent, '-', 'we have user_anget')
t.end()
})
tap.test('ssl traffic', function (t) {
var parsed = parse(
'https 2015-05-13T23:39:43.945958Z my-loadbalancer 192.168.131.39:2817 10.0.0.1:80 0.001065 0.000015 0.000023 - - 57 502 "- - - " "-" ECDHE-ECDSA-AES128-GCM-SHA256 TLSv1.2 arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/my-targets/73e2d6bc24d8a067 "Root=1-58337262-36d228ad5d99923122bbe354"'
)
t.equal(
parsed.ssl_cipher,
'ECDHE-ECDSA-AES128-GCM-SHA256',
'we have ssl_cipher'
)
t.equal(parsed.ssl_protocol, 'TLSv1.2', 'we have ssl_protocol')
t.end()
})
tap.test('ipv6 client', function (t) {
var parsed = parse(
'https 2015-05-13T23:39:43.945958Z my-loadbalancer 2001:db8:85a3:0:0:8a2e:370:7334:2817 10.0.0.1:80 0.001065 0.000015 0.000023 - - 57 502 "- - - " "-" ECDHE-ECDSA-AES128-GCM-SHA256 TLSv1.2 arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/my-targets/73e2d6bc24d8a067 "Root=1-58337262-36d228ad5d99923122bbe354"'
)
t.equal(parsed.client, '2001:db8:85a3:0:0:8a2e:370:7334', 'we have ipv6 client')
t.equal(parsed.client_port, 2817, 'we have ipv6 client_port')
t.end()
})
tap.test("doesn't receive traffic ", function (t) {
var parsed = parse(
'http 2015-05-13T23:39:43.945958Z my-loadbalancer 192.168.131.39:2817 - 0.001065 0.000015 0.000023 - - 57 502 "- - - " "-" ECDHE-ECDSA-AES128-GCM-SHA256 TLSv1.2 arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/my-targets/73e2d6bc24d8a067 "Root=1-58337262-36d228ad5d99923122bbe354"'
)
t.equal(parsed.target, '-', 'we have target')
t.equal(parsed.target_port, -1, 'we have target_port')
t.end()
})
tap.test('websockets', function (t) {
var parsed = parse(
'ws 2018-07-02T22:23:00.186641Z app/my-loadbalancer/50dc6c495c0c9188 10.0.0.140:40914 10.0.1.192:8010 0.001 0.003 0.000 101 101 218 587 "GET http://10.0.0.30:80/ HTTP/1.1" "-" - - arn:aws:elasticloadbalancing:us-east-2:123456789012:targetgroup/my-targets/73e2d6bc24d8a067 "Root=1-58337364-23a8c76965a2ef7629b185e3" "-" "-" 1 2018-07-02T22:22:48.364000Z "forward" "-" "-"'
)
t.equal(parsed.type, 'ws', 'we have type')
t.equal(parsed.timestamp, '2018-07-02T22:23:00.186641Z', 'we have timestamp')
t.equal(parsed.elb, 'app/my-loadbalancer/50dc6c495c0c9188', 'we have elb')
t.equal(parsed.client, '10.0.0.140', 'we have client')
t.equal(parsed.client_port, 40914, 'we have client_port')
t.equal(parsed.target, '10.0.1.192', 'we have target')
t.equal(
parsed.request_processing_time,
0.001,
'we have request_processing_time'
)
t.equal(
parsed.target_processing_time,
0.003,
'we have target_processing_time'
)
t.equal(
parsed.response_processing_time,
0,
'we have response_processing_time'
)
t.equal(parsed.elb_status_code, 101, 'we have elb_status_code')
t.equal(parsed.target_status_code, 101, 'we have target_status_code')
t.equal(parsed.received_bytes, 218, 'we have received_bytes')
t.equal(parsed.sent_bytes, 587, 'we have sent_bytes')
t.equal(
parsed.request,
'GET http://10.0.0.30:80/ HTTP/1.1',
'we have request'
)
t.equal(parsed.user_agent, '-', 'we have user_agent')
t.equal(parsed.ssl_cipher, '-', 'we have ssl_cipher')
t.equal(parsed.ssl_protocol, '-', 'we have ssl_protocol')
t.equal(
parsed.target_group_arn,
'arn:aws:elasticloadbalancing:us-east-2:123456789012:targetgroup/my-targets/73e2d6bc24d8a067',
'we have target_group_arn'
)
t.equal(
parsed.trace_id,
'Root=1-58337364-23a8c76965a2ef7629b185e3',
'we have trace_id'
)
t.equal(parsed.target_port, 8010, 'we have target_port')
t.equal(parsed.request_method, 'GET', 'we have request_method')
t.equal(parsed.request_uri, 'http://10.0.0.30:80/', 'we have request_uri')
t.equal(
parsed.request_http_version,
'HTTP/1.1',
'we have request_http_version'
)
t.equal(parsed.request_uri_scheme, 'http:', 'we have request_uri_scheme')
t.equal(parsed.request_uri_host, '10.0.0.30', 'we have request_uri_host')
t.equal(parsed.request_uri_port, 80, 'we have request_uri_port')
t.equal(parsed.request_uri_path, '/', 'we have request_uri_path')
t.equal(parsed.request_uri_query, null, 'we have request_uri_query')
t.end()
})
tap.test('secure websockets', function (t) {
var parsed = parse(
'wss 2018-07-02T22:23:00.186641Z app/my-loadbalancer/50dc6c495c0c9188 10.0.0.140:44244 10.0.0.171:8010 0.000 0.001 0.000 101 101 218 786 "GET https://10.0.0.30:443/ HTTP/1.1" "-" ECDHE-RSA-AES128-GCM-SHA256 TLSv1.2 arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/my-targets/73e2d6bc24d8a067 "Root=1-58337364-23a8c76965a2ef7629b185e3" "-" "-" 1 2018-07-02T22:22:48.364000Z "forward" "-" "-"'
)
t.equal(parsed.type, 'wss', 'we have type')
t.equal(parsed.timestamp, '2018-07-02T22:23:00.186641Z', 'we have timestamp')
t.equal(parsed.elb, 'app/my-loadbalancer/50dc6c495c0c9188', 'we have elb')
t.equal(parsed.client, '10.0.0.140', 'we have client')
t.equal(parsed.client_port, 44244, 'we have client_port')
t.equal(parsed.target, '10.0.0.171', 'we have target')
t.equal(parsed.request_processing_time, 0, 'we have request_processing_time')
t.equal(parsed.target_processing_time, 0.001, 'we have target_processing_time')
t.equal(parsed.response_processing_time, 0, 'we have response_processing_time')
t.equal(parsed.elb_status_code, 101, 'we have elb_status_code')
t.equal(parsed.target_status_code, 101, 'we have target_status_code')
t.equal(parsed.received_bytes, 218, 'we have received_bytes')
t.equal(parsed.sent_bytes, 786, 'we have sent_bytes')
t.equal(parsed.request, 'GET https://10.0.0.30:443/ HTTP/1.1', 'we have request')
t.equal(parsed.user_agent, '-', 'we have user_agent')
t.equal(parsed.ssl_cipher, 'ECDHE-RSA-AES128-GCM-SHA256', 'we have ssl_cipher')
t.equal(parsed.ssl_protocol, 'TLSv1.2', 'we have ssl_protocol')
t.equal(parsed.target_group_arn, 'arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/my-targets/73e2d6bc24d8a067', 'we have target_group_arn')
t.equal(parsed.trace_id, 'Root=1-58337364-23a8c76965a2ef7629b185e3', 'we have trace_id')
t.equal(parsed.target_port, 8010, 'we have target_port')
t.equal(parsed.request_method, 'GET', 'we have request_method')
t.equal(parsed.request_uri, 'https://10.0.0.30:443/', 'we have request_uri')
t.equal(parsed.request_http_version, 'HTTP/1.1', 'we have request_http_version')
t.equal(parsed.request_uri_scheme, 'https:', 'we have request_uri_scheme')
t.equal(parsed.request_uri_host, '10.0.0.30', 'we have request_uri_host')
t.equal(parsed.request_uri_port, 443, 'we have request_uri_port')
t.equal(parsed.request_uri_path, '/', 'we have request_uri_path')
t.equal(parsed.request_uri_query, null, 'we have request_uri_query')
t.equal(parsed.chosen_cert_arn, '-', 'we have chosen_cert_arn')
t.end()
})
tap.test('unsuccessful Lambda', function (t) {
var parsed = parse(
'http 2018-11-30T22:23:00.186641Z app/my-loadbalancer/50dc6c495c0c9188 192.168.131.39:2817 - 0.000 0.001 0.000 502 - 34 366 "GET http://www.example.com:80/ HTTP/1.1" "curl/7.46.0" - - arn:aws:elasticloadbalancing:us-east-2:123456789012:targetgroup/my-targets/73e2d6bc24d8a067 "Root=1-58337364-23a8c76965a2ef7629b185e3" "-" "-" 0 2018-11-30T22:22:48.364000Z "forward" "-" "LambdaInvalidResponse"'
)
t.equal(parsed.type, 'http', 'we have type')
t.equal(parsed.timestamp, '2018-11-30T22:23:00.186641Z', 'we have timestamp')
t.equal(parsed.elb, 'app/my-loadbalancer/50dc6c495c0c9188', 'we have elb')
t.equal(parsed.client, '192.168.131.39', 'we have client')
t.equal(parsed.client_port, 2817, 'we have client_port')
t.equal(parsed.target, '-', 'we have target')
t.equal(parsed.target_port, -1, 'we have target_port')
t.equal(parsed.request_processing_time, 0, 'we have request_processing_time')
t.equal(parsed.target_processing_time, 0.001, 'we have target_processing_time')
t.equal(parsed.response_processing_time, 0, 'we have response_processing_time')
t.equal(parsed.elb_status_code, 502, 'we have elb_status_code')
t.equal(parsed.target_status_code, '-', 'we have target_status_code')
t.equal(parsed.received_bytes, 34, 'we have received_bytes')
t.equal(parsed.sent_bytes, 366, 'we have sent_bytes')
t.equal(parsed.request_method, 'GET', 'we have request_method')
t.equal(parsed.request_uri, 'http://www.example.com:80/', 'we have request_uri')
t.equal(parsed.request_http_version, 'HTTP/1.1', 'we have request_http_version')
t.equal(parsed.request_uri_scheme, 'http:', 'we have request_uri_scheme')
t.equal(parsed.request_uri_host, 'www.example.com', 'we have request_uri_host')
t.equal(parsed.request_uri_port, 80, 'we have request_uri_port')
t.equal(parsed.request_uri_path, '/', 'we have request_uri_path')
t.equal(parsed.request_uri_query, null, 'we have request_uri_query')
t.equal(parsed.request, 'GET http://www.example.com:80/ HTTP/1.1', 'we have request')
t.equal(parsed.user_agent, 'curl/7.46.0', 'we have user_agent')
t.equal(parsed.ssl_cipher, '-', 'we have ssl_cipher')
t.equal(parsed.ssl_protocol, '-', 'we have ssl_protocol')
t.equal(parsed.target_group_arn, 'arn:aws:elasticloadbalancing:us-east-2:123456789012:targetgroup/my-targets/73e2d6bc24d8a067', 'we have target_group_arn')
t.equal(parsed.trace_id, 'Root=1-58337364-23a8c76965a2ef7629b185e3', 'we have trace_id')
t.equal(parsed.domain_name, '-', 'we have domain_name')
t.equal(parsed.chosen_cert_arn, '-', 'we have chosen_cert_arn')
t.equal(parsed.matched_rule_priority, 0, 'we have matched_rule_priority')
t.equal(parsed.request_creation_time, '2018-11-30T22:22:48.364000Z', 'we have request_creation_time')
t.equal(parsed.actions_executed, 'forward', 'we have actions_executed')
t.equal(parsed.redirect_url, '-', 'we have redirect_url')
t.equal(parsed.error_reason, 'LambdaInvalidResponse', 'we have error_reason')
t.end()
})
tap.test('successful Lambda', function (t) {
var parsed = parse(
'http 2018-11-30T22:23:00.186641Z app/my-loadbalancer/50dc6c495c0c9188 192.168.131.39:2817 - 0.000 0.001 0.000 200 200 34 366 "GET http://www.example.com:80/ HTTP/1.1" "curl/7.46.0" - - arn:aws:elasticloadbalancing:us-east-2:123456789012:targetgroup/my-targets/73e2d6bc24d8a067 "Root=1-58337364-23a8c76965a2ef7629b185e3" "-" "-" 0 2018-11-30T22:22:48.364000Z "forward" "-" "-"'
)
t.equal(parsed.type, 'http', 'we have type')
t.equal(parsed.timestamp, '2018-11-30T22:23:00.186641Z', 'we have timestamp')
t.equal(parsed.elb, 'app/my-loadbalancer/50dc6c495c0c9188', 'we have elb')
t.equal(parsed.client, '192.168.131.39', 'we have client')
t.equal(parsed.client_port, 2817, 'we have client_port')
t.equal(parsed.target, '-', 'we have target')
t.equal(parsed.target_port, -1, 'we have target_port')
t.equal(parsed.request_processing_time, 0, 'we have request_processing_time')
t.equal(parsed.target_processing_time, 0.001, 'we have target_processing_time')
t.equal(parsed.response_processing_time, 0, 'we have response_processing_time')
t.equal(parsed.elb_status_code, 200, 'we have elb_status_code')
t.equal(parsed.target_status_code, 200, 'we have target_status_code')
t.equal(parsed.received_bytes, 34, 'we have received_bytes')
t.equal(parsed.sent_bytes, 366, 'we have sent_bytes')
t.equal(parsed.request_method, 'GET', 'we have request_method')
t.equal(parsed.request_uri, 'http://www.example.com:80/', 'we have request_uri')
t.equal(parsed.request_http_version, 'HTTP/1.1', 'we have request_http_version')
t.equal(parsed.request_uri_scheme, 'http:', 'we have request_uri_scheme')
t.equal(parsed.request_uri_host, 'www.example.com', 'we have request_uri_host')
t.equal(parsed.request_uri_port, 80, 'we have request_uri_port')
t.equal(parsed.request_uri_path, '/', 'we have request_uri_path')
t.equal(parsed.request_uri_query, null, 'we have request_uri_query')
t.equal(parsed.request, 'GET http://www.example.com:80/ HTTP/1.1', 'we have request')
t.equal(parsed.user_agent, 'curl/7.46.0', 'we have user_agent')
t.equal(parsed.ssl_cipher, '-', 'we have ssl_cipher')
t.equal(parsed.ssl_protocol, '-', 'we have ssl_protocol')
t.equal(parsed.target_group_arn, 'arn:aws:elasticloadbalancing:us-east-2:123456789012:targetgroup/my-targets/73e2d6bc24d8a067', 'we have target_group_arn')
t.equal(parsed.trace_id, 'Root=1-58337364-23a8c76965a2ef7629b185e3', 'we have trace_id')
t.equal(parsed.domain_name, '-', 'we have domain_name')
t.equal(parsed.chosen_cert_arn, '-', 'we have chosen_cert_arn')
t.equal(parsed.matched_rule_priority, 0, 'we have matched_rule_priority')
t.equal(parsed.request_creation_time, '2018-11-30T22:22:48.364000Z', 'we have request_creation_time')
t.equal(parsed.actions_executed, 'forward', 'we have actions_executed')
t.equal(parsed.redirect_url, '-', 'we have redirect_url')
t.equal(parsed.error_reason, '-', 'we have error_reason')
t.end()
})
tap.test('classification and classification reason', function(t) {
var parsed = parse('http 2020-08-27T16:35:00.166351Z app/my-loadbalancer/50dc6c495c0c9188 192.168.131.39:2817 192.168.201.251:80 0.000 0.440 0.000 200 200 1107 11912 "GET http://example.com:80/path?foo=bar&baz=bak HTTP/1.1" "Fake/1.0.0 (Linux)" - - arn:aws:elasticloadbalancing:us-east-1:123456789012:targetgroup/my-tg/ffffffffffffffff "Self=1-00000000-111111111111111111111111;Root=1-00000000-222222222222222222222222" "-" "-" 0 2020-08-27T16:34:59.725000Z "forward" "-" "-" "192.168.201.251:80" "200" "-" "-"')
t.equal(parsed.classification, '-', 'we have classification')
t.equal(parsed.classification_reason, '-', 'we have classification_reason')
t.end()
})
tap.test('extra fields are ignored', function(t) {
var parsed = parse('http 2020-08-27T16:35:00.166351Z app/my-loadbalancer/50dc6c495c0c9188 192.168.131.39:2817 192.168.201.251:80 0.000 0.440 0.000 200 200 1107 11912 "GET http://example.com:80/path?foo=bar&baz=bak HTTP/1.1" "Fake/1.0.0 (Linux)" - - arn:aws:elasticloadbalancing:us-east-1:123456789012:targetgroup/my-tg/ffffffffffffffff "Self=1-00000000-111111111111111111111111;Root=1-00000000-222222222222222222222222" "-" "-" 0 2020-08-27T16:34:59.725000Z "forward" "-" "-" "192.168.201.251:80" "200" "-" "-" "FOO BAR" BAZ')
const seen = Object.values(parsed).filter(val => (val === 'FOO BAR' || val === 'BAZ'))
t.equal(seen.length, 0, 'Extra fields are ignored')
t.end()
})
tap.test('-1 xxxx_processing_time', function(t) {
var parsed = parse(
'http 2015-05-13T23:39:43.945958Z my-loadbalancer 192.168.131.39:2817 10.0.0.1:80 -1 -1 -1 200 200 0 29 "GET http://www.example.com:80/ HTTP/1.1" "curl/7.38.0" - - arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/my-targets/73e2d6bc24d8a067 "Root=1-58337262-36d228ad5d99923122bbe354"'
)
t.equal(parsed.request_processing_time, -1, 'we have -1 request_processing_time')
t.equal(parsed.target_processing_time, -1, 'we have -1 target_processing_time')
t.equal(parsed.response_processing_time, -1, 'we have -1 response_processing_time')
t.end()
})