Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Rocketchat output test #113

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions outputs/rocketchat_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package outputs

import (
"encoding/json"
"testing"
"text/template"

"github.com/falcosecurity/falcosidekick/types"

"github.com/stretchr/testify/require"
)

func TestNewRocketchatPayload(t *testing.T) {
expectedOutput := slackPayload{
Text: "Rule: Test rule Priority: Debug",
Username: "Falcosidekick",
IconURL: DefaultIconURL,
Attachments: []slackAttachment{
{
Fallback: "This is a test from falcosidekick",
Color: PaleCyan,
Text: "This is a test from falcosidekick",
Footer: "",
Fields: []slackAttachmentField{
{
Title: "proc.name",
Value: "falcosidekick",
Short: true,
},
{
Title: "rule",
Value: "Test rule",
Short: true,
},
{
Title: "priority",
Value: "Debug",
Short: true,
},
{
Title: "time",
Value: "2001-01-01 01:10:00 +0000 UTC",
Short: false,
},
},
},
},
}

var f types.FalcoPayload
require.Nil(t, json.Unmarshal([]byte(falcoTestInput), &f))
config := &types.Configuration{
Rocketchat: types.RocketchatOutputConfig{
Username: "Falcosidekick",
Icon: DefaultIconURL,
},
}

var err error
config.Rocketchat.MessageFormatTemplate, err = template.New("").Parse("Rule: {{ .Rule }} Priority: {{ .Priority }}")
require.Nil(t, err)

output := newRocketchatPayload(f, config)
require.Equal(t, output, expectedOutput)
}
4 changes: 2 additions & 2 deletions types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type Configuration struct {
Customfields map[string]string
Slack SlackOutputConfig
Mattermost MattermostOutputConfig
Rocketchat rocketchatOutputConfig
Rocketchat RocketchatOutputConfig
Teams teamsOutputConfig
Datadog datadogOutputConfig
Discord discordOutputConfig
Expand Down Expand Up @@ -57,7 +57,7 @@ type SlackOutputConfig struct {
MessageFormatTemplate *template.Template
}

type rocketchatOutputConfig struct {
type RocketchatOutputConfig struct {
WebhookURL string
Footer string
Icon string
Expand Down