11package util
22
33// DCSO FEVER
4- // Copyright (c) 2020, DCSO GmbH
4+ // Copyright (c) 2020, 2021, DCSO GmbH
55
66import (
77 "encoding/json"
@@ -17,12 +17,13 @@ import (
1717)
1818
1919func makeTestHTTPEvent (host string , url string ) types.Entry {
20+ testTime , _ := time .Parse ("2006-Jan-02" , "2013-Feb-03" )
2021 e := types.Entry {
2122 SrcIP : fmt .Sprintf ("10.0.0.%d" , rand .Intn (5 )+ 1 ),
2223 SrcPort : int64 (rand .Intn (60000 ) + 1025 ),
2324 DestIP : fmt .Sprintf ("10.0.0.%d" , rand .Intn (50 )),
2425 DestPort : 80 ,
25- Timestamp : time . Now () .Format (types .SuricataTimestampFormat ),
26+ Timestamp : testTime .Format (types .SuricataTimestampFormat ),
2627 EventType : "http" ,
2728 Proto : "TCP" ,
2829 HTTPHost : host ,
@@ -100,6 +101,24 @@ func checkAlertifierAlerts(t *testing.T, a *types.Entry, msg string, ioc string)
100101 if resAlert .ExtraInfo .VastIOC != ioc {
101102 t .Fatalf ("wrong ioc ('%s' <-> '%s')" , resAlert .ExtraInfo .VastIOC , ioc )
102103 }
104+ eventTimeVal , _ , _ , err := jsonparser .Get ([]byte (a .JSONLine ), "timestamp_event" )
105+ if err != nil {
106+ t .Fatal (err )
107+ }
108+ if string (eventTimeVal ) != "2013-02-03T00:00:00+0000" {
109+ t .Fatalf ("wrong event timestamp ('%s' <-> '%s')" , string (eventTimeVal ), "2013-02-03T00:00:00+0000" )
110+ }
111+ alertTimeVal , _ , _ , err := jsonparser .Get ([]byte (a .JSONLine ), "timestamp" )
112+ if err != nil {
113+ t .Fatal (err )
114+ }
115+ alertTime , err := time .Parse (types .SuricataTimestampFormat , string (alertTimeVal ))
116+ if err != nil {
117+ t .Fatal (err )
118+ }
119+ if ! alertTime .Add (48 * time .Hour ).After (time .Now ()) {
120+ t .Fatalf ("wrong alert unexpected ('%s' < '%s')" , alertTime .Add (48 * time .Hour ), time .Now ())
121+ }
103122}
104123
105124func testExtraModifier (inputAlert * types.Entry , ioc string ) error {
0 commit comments