Skip to content

Commit

Permalink
add unit test for https
Browse files Browse the repository at this point in the history
* 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 <ruitian-zhong@outlook.com>
  • Loading branch information
ruitianzhong authored and cfc4n committed Mar 2, 2024
1 parent e07cf53 commit 987b3f5
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 4 deletions.
20 changes: 17 additions & 3 deletions pkg/event_processor/processor_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package event_processor

import (
"bytes"
"encoding/json"
"fmt"
"log"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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")
}
7 changes: 7 additions & 0 deletions pkg/event_processor/testdata/952253698000000.bin
Original file line number Diff line number Diff line change
@@ -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

7 changes: 7 additions & 0 deletions pkg/event_processor/testdata/952253698001000.bin
Original file line number Diff line number Diff line change
@@ -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

Binary file added pkg/event_processor/testdata/952253698002000.bin
Binary file not shown.
2 changes: 1 addition & 1 deletion pkg/event_processor/testdata/952282712204824.bin
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions pkg/event_processor/testdata/all.json
Original file line number Diff line number Diff line change
@@ -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}
Expand Down

0 comments on commit 987b3f5

Please sign in to comment.