From 987b3f5f3b680b93fb1d2d6e1308126c488661cf Mon Sep 17 00:00:00 2001 From: ruitianzhong Date: Fri, 1 Mar 2024 19:51:33 +0800 Subject: [PATCH] add unit test for https * fix the wrong Content-Length in 952282712204824.bin, which leads to , and this test should fail but actually not because of there is not detection in unit test for it. * add unit test for gzipped http body and add detection for it. Signed-off-by: ruitianzhong --- pkg/event_processor/processor_test.go | 20 +++++++++++++++--- .../testdata/952253698000000.bin | 7 ++++++ .../testdata/952253698001000.bin | 7 ++++++ .../testdata/952253698002000.bin | Bin 0 -> 1145 bytes .../testdata/952282712204824.bin | 2 +- pkg/event_processor/testdata/all.json | 3 +++ 6 files changed, 35 insertions(+), 4 deletions(-) create mode 100644 pkg/event_processor/testdata/952253698000000.bin create mode 100644 pkg/event_processor/testdata/952253698001000.bin create mode 100644 pkg/event_processor/testdata/952253698002000.bin diff --git a/pkg/event_processor/processor_test.go b/pkg/event_processor/processor_test.go index de69604c1..5e547c7c2 100644 --- a/pkg/event_processor/processor_test.go +++ b/pkg/event_processor/processor_test.go @@ -1,6 +1,7 @@ package event_processor import ( + "bytes" "encoding/json" "fmt" "log" @@ -30,6 +31,8 @@ type SSLDataEventTmp struct { func TestEventProcessor_Serve(t *testing.T) { logger := log.Default() + var buf bytes.Buffer + logger.SetOutput(&buf) /* f, e := os.Create("./output.log") if e != nil { @@ -68,12 +71,23 @@ func TestEventProcessor_Serve(t *testing.T) { } tick := time.NewTicker(time.Second * 3) - select { - case <-tick.C: - } + <-tick.C + err = ep.Close() + lines = strings.Split(buf.String(), "\n") + ok := true + for _, line := range lines { + if strings.Contains(strings.ToLower(line), "dump") { + t.Log(line) + ok = false + } + } if err != nil { t.Fatalf("close error: %s", err.Error()) } + if !ok { + t.Fatalf("some errors occurred") + } + t.Log(buf.String()) t.Log("done") } diff --git a/pkg/event_processor/testdata/952253698000000.bin b/pkg/event_processor/testdata/952253698000000.bin new file mode 100644 index 000000000..a470d3a06 --- /dev/null +++ b/pkg/event_processor/testdata/952253698000000.bin @@ -0,0 +1,7 @@ +GET / HTTP/1.1 +Host: www.baidu.com +User-Agent: Wget/1.21.2 +Accept: */* +Accept-Encoding: gzip +Connection: Keep-Alive + diff --git a/pkg/event_processor/testdata/952253698001000.bin b/pkg/event_processor/testdata/952253698001000.bin new file mode 100644 index 000000000..17a1fc650 --- /dev/null +++ b/pkg/event_processor/testdata/952253698001000.bin @@ -0,0 +1,7 @@ +HTTP/1.1 200 OK +Content-Encoding: gzip +Content-Length: 1145 +Server: bfe +Date: Fri, 01 Mar 2024 08:24:27 GMT +Content-Type: text/html;charset=UTF-8 + diff --git a/pkg/event_processor/testdata/952253698002000.bin b/pkg/event_processor/testdata/952253698002000.bin new file mode 100644 index 0000000000000000000000000000000000000000..67748e3292c47b2fe4143a1dc0591d565f69c7d4 GIT binary patch literal 1145 zcmV-<1cv(`iwFP!00000|CCl+kJPpoe@EgwnEbW7AT;B-2*H0h3EFN!LP!M_Rw_>; z$9594iEV6W!tm6UO4X{Rw4xVLDz&Owwhxt{DpJu>;LA+d-KTzq%1LJD3aIlE`}myS z`JJ0R?y+|-ZCt%}`5cH%n)pYLxW^ieD_7UAZe9VGE;bszTgrhOQ$&0>r3Qi67}=mV zGS>I7;D&P3Fat?Jz3~jaX`nS*!!c5t8ZR?p&?4Q3sA3p!7c>KrSkG~#l-*aK5;=(dVeA8! zus&eK%N3H6s#~tf)nc#J3v0DEs3_g<1@i4K ztsWyc->ztQty6~YyILY%hwlUt&^;ziFISFV12E!k<&|kp4y(zesbD~gZYGpRwh*UI z0hAemMJf|&s3*d(6jXIRT=_1vP8YZi44-sea@SdqvXX|*YUYz2K5OrQIX}RKbwAdf zQGe;IVKEZzPIm^Q z5>BF2k~x%B2vZ~%@<@@K1So!ZTs(NO2%x{vyw3;~lK}fWA0Pbu)gl1HXn+=ilqXXl zPo5NC?o=RLXsnntb9mE(S6yR?h!}51EIeDTmQgC#j7+?=T4tr~Qg?l+bAG9FehOi! z6E1bb@oX-2N&ApviB>aA0)OxRv*P(T6+bvZuwD>>vy^hv%oQ{A_{xa5^Bud3x%c&N6_Mi8JH^Y}`;W@&p+cDDb)6wTU=t{HVzF$5l#&49E&tU=clUR;i@SFY z9)2=L8t(pnVdL`tqwQ9=)jr)V?*29MU?0=hy`GV_y*dhcVL_n%OJKkCKd*lS00960 LFbsj3iwOV#=Z+zf literal 0 HcmV?d00001 diff --git a/pkg/event_processor/testdata/952282712204824.bin b/pkg/event_processor/testdata/952282712204824.bin index 541c9f58d..4f617d461 100755 --- a/pkg/event_processor/testdata/952282712204824.bin +++ b/pkg/event_processor/testdata/952282712204824.bin @@ -2,7 +2,7 @@ HTTP/1.1 200 OK Server: nginx/1.14.0 (Ubuntu) Date: Wed, 29 Jun 2022 09:44:35 GMT Content-Type: text/html; charset=UTF-8 -Content-Length: 74332 +Content-Length: 20124 Connection: keep-alive Vary: Accept-Encoding, Cookie Cache-Control: max-age=3, must-revalidate diff --git a/pkg/event_processor/testdata/all.json b/pkg/event_processor/testdata/all.json index 7245fa2c5..affe41487 100755 --- a/pkg/event_processor/testdata/all.json +++ b/pkg/event_processor/testdata/all.json @@ -1,6 +1,9 @@ {"DataType":1,"Timestamp":952253291192473,"Pid":469929,"Tid":469929,"DataLen":240,"Comm":[119,103,101,116,0,0,0,0,0,0,0,0,0,0,0,0],"Fd":3,"Version":771} {"DataType":0,"Timestamp":952253597324253,"Pid":469929,"Tid":469929,"DataLen":308,"Comm":[119,103,101,116,0,0,0,0,0,0,0,0,0,0,0,0],"Fd":3,"Version":771} {"DataType":0,"Timestamp":952253597628796,"Pid":469929,"Tid":469929,"DataLen":191,"Comm":[119,103,101,116,0,0,0,0,0,0,0,0,0,0,0,0],"Fd":3,"Version":771} +{"DataType":1,"Timestamp":952253698000000,"Pid":469930,"Tid":469930,"DataLen":124,"Comm":[119,103,101,116,0,0,0,0,0,0,0,0,0,0,0,0],"Fd":3,"Version":771} +{"DataType":0,"Timestamp":952253698001000,"Pid":469930,"Tid":469930,"DataLen":154,"Comm":[119,103,101,116,0,0,0,0,0,0,0,0,0,0,0,0],"Fd":3,"Version":771} +{"DataType":0,"Timestamp":952253698002000,"Pid":469930,"Tid":469930,"DataLen":1145,"Comm":[119,103,101,116,0,0,0,0,0,0,0,0,0,0,0,0],"Fd":3,"Version":771} {"DataType":1,"Timestamp":952282673103459,"Pid":469953,"Tid":469953,"DataLen":77,"Comm":[99,117,114,108,0,0,0,0,0,0,0,0,0,0,0,0],"Fd":5,"Version":771} {"DataType":0,"Timestamp":952282712204824,"Pid":469953,"Tid":469953,"DataLen":4096,"Comm":[99,117,114,108,0,0,0,0,0,0,0,0,0,0,0,0],"Fd":5,"Version":771} {"DataType":0,"Timestamp":952282715334491,"Pid":469953,"Tid":469953,"DataLen":4096,"Comm":[99,117,114,108,0,0,0,0,0,0,0,0,0,0,0,0],"Fd":5,"Version":771}