-
Notifications
You must be signed in to change notification settings - Fork 424
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(test): e2e integration test for new helpers
- Loading branch information
Showing
8 changed files
with
201 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,6 +61,8 @@ env: | |
ICMPv6 | ||
DNS | ||
HTTP | ||
HTTPRequest | ||
HTTPResponse | ||
INSTTESTS: > | ||
PROCESS_EXECUTE_FAILED | ||
VFS_WRITE | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/aquasecurity/tracee/signatures/helpers" | ||
"github.com/aquasecurity/tracee/types/detect" | ||
"github.com/aquasecurity/tracee/types/protocol" | ||
"github.com/aquasecurity/tracee/types/trace" | ||
) | ||
|
||
// | ||
// HOWTO: The way to trigger this test signature is to execute: | ||
// | ||
// curl google.com | ||
// | ||
// This will cause it trigger once and reset it status. | ||
|
||
type e2eHTTPRequest struct { | ||
cb detect.SignatureHandler | ||
} | ||
|
||
func (sig *e2eHTTPRequest) Init(ctx detect.SignatureContext) error { | ||
sig.cb = ctx.Callback | ||
return nil | ||
} | ||
|
||
func (sig *e2eHTTPRequest) GetMetadata() (detect.SignatureMetadata, error) { | ||
return detect.SignatureMetadata{ | ||
ID: "HTTPRequest", | ||
EventName: "HTTPRequest", | ||
Version: "0.1.0", | ||
Name: "Network HTTP Request Test", | ||
Description: "Network E2E Tests: HTTP Request", | ||
Tags: []string{"e2e", "network"}, | ||
}, nil | ||
} | ||
|
||
func (sig *e2eHTTPRequest) GetSelectedEvents() ([]detect.SignatureEventSelector, error) { | ||
return []detect.SignatureEventSelector{ | ||
{Source: "tracee", Name: "net_packet_http_request"}, | ||
}, nil | ||
} | ||
|
||
func (sig *e2eHTTPRequest) OnEvent(event protocol.Event) error { | ||
eventObj, ok := event.Payload.(trace.Event) | ||
if !ok { | ||
return fmt.Errorf("failed to cast event's payload") | ||
} | ||
|
||
if eventObj.ProcessName != "curl" { | ||
return nil | ||
} | ||
|
||
if eventObj.EventName == "net_packet_http_request" { | ||
// validate tast context | ||
if eventObj.HostName == "" { | ||
return nil | ||
} | ||
|
||
httpRequest, err := helpers.GetProtoHTTPRequestByName(eventObj, "http_request") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if !strings.HasPrefix(httpRequest.Protocol, "HTTP/") { | ||
return nil | ||
} | ||
|
||
m, _ := sig.GetMetadata() | ||
sig.cb(&detect.Finding{ | ||
SigMetadata: m, | ||
Event: event, | ||
Data: map[string]interface{}{}, | ||
}) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (sig *e2eHTTPRequest) OnSignal(s detect.Signal) error { | ||
return nil | ||
} | ||
|
||
func (sig *e2eHTTPRequest) Close() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/aquasecurity/tracee/signatures/helpers" | ||
"github.com/aquasecurity/tracee/types/detect" | ||
"github.com/aquasecurity/tracee/types/protocol" | ||
"github.com/aquasecurity/tracee/types/trace" | ||
) | ||
|
||
// | ||
// HOWTO: The way to trigger this test signature is to execute: | ||
// | ||
// curl google.com | ||
// | ||
// This will cause it trigger once and reset it status. | ||
|
||
type e2eHTTPResponse struct { | ||
cb detect.SignatureHandler | ||
} | ||
|
||
func (sig *e2eHTTPResponse) Init(ctx detect.SignatureContext) error { | ||
sig.cb = ctx.Callback | ||
return nil | ||
} | ||
|
||
func (sig *e2eHTTPResponse) GetMetadata() (detect.SignatureMetadata, error) { | ||
return detect.SignatureMetadata{ | ||
ID: "HTTPResponse", | ||
EventName: "HTTPResponse", | ||
Version: "0.1.0", | ||
Name: "Network HTTP Response Test", | ||
Description: "Network E2E Tests: HTTP Response", | ||
Tags: []string{"e2e", "network"}, | ||
}, nil | ||
} | ||
|
||
func (sig *e2eHTTPResponse) GetSelectedEvents() ([]detect.SignatureEventSelector, error) { | ||
return []detect.SignatureEventSelector{ | ||
{Source: "tracee", Name: "net_packet_http_response"}, | ||
}, nil | ||
} | ||
|
||
func (sig *e2eHTTPResponse) OnEvent(event protocol.Event) error { | ||
eventObj, ok := event.Payload.(trace.Event) | ||
if !ok { | ||
return fmt.Errorf("failed to cast event's payload") | ||
} | ||
|
||
if eventObj.EventName == "net_packet_http_response" { | ||
// validate tast context | ||
if eventObj.HostName == "" { | ||
return nil | ||
} | ||
|
||
httpResponse, err := helpers.GetProtoHTTPResponseByName(eventObj, "http_response") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if !strings.HasPrefix(httpResponse.Protocol, "HTTP/") { | ||
return nil | ||
} | ||
|
||
m, _ := sig.GetMetadata() | ||
sig.cb(&detect.Finding{ | ||
SigMetadata: m, | ||
Event: event, | ||
Data: map[string]interface{}{}, | ||
}) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (sig *e2eHTTPResponse) OnSignal(s detect.Signal) error { | ||
return nil | ||
} | ||
|
||
func (sig *e2eHTTPResponse) Close() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/bin/bash | ||
|
||
HOST="google.com" | ||
|
||
exit_err() { | ||
echo -n "ERROR: " | ||
echo $@ | ||
exit 1 | ||
} | ||
|
||
command -v curl > /dev/null || exit_err "missing curl tool" | ||
|
||
curl $HOST |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/bin/bash | ||
|
||
HOST="google.com" | ||
|
||
exit_err() { | ||
echo -n "ERROR: " | ||
echo $@ | ||
exit 1 | ||
} | ||
|
||
command -v curl > /dev/null || exit_err "missing curl tool" | ||
|
||
curl $HOST |