fleet/ee/server/webhooks/mapper_test.go
Juan Fernandez aecc2fed75
Feature 9834: Add published date to vulnerability object (#10434)
This only applies to Premium users, we want to show the vulnerabilities' published date anywhere vulnerabilities are shown including API endpoints and third party integrations.
2023-03-28 16:11:31 -04:00

39 lines
994 B
Go

package webhooks
import (
"net/url"
"testing"
"time"
"github.com/fleetdm/fleet/v4/server/fleet"
"github.com/fleetdm/fleet/v4/server/ptr"
"github.com/stretchr/testify/require"
)
func TestGetPayload(t *testing.T) {
serverURL, err := url.Parse("http://mywebsite.com")
require.NoError(t, err)
now := time.Now().UTC().Truncate(time.Second)
vuln := fleet.SoftwareVulnerability{
CVE: "cve-1",
SoftwareID: 1,
}
meta := fleet.CVEMeta{
CVE: "cve-1",
CVSSScore: ptr.Float64(1),
EPSSProbability: ptr.Float64(0.5),
CISAKnownExploit: ptr.Bool(true),
Published: ptr.Time(now),
}
sut := Mapper{}
result := sut.GetPayload(serverURL, nil, vuln.CVE, meta)
require.Equal(t, *meta.CISAKnownExploit, *result.CISAKnownExploit)
require.Equal(t, *meta.EPSSProbability, *result.EPSSProbability)
require.Equal(t, *meta.CVSSScore, *result.CVSSScore)
require.NotNil(t, result.CVEPublished)
require.Equal(t, *meta.Published, *result.CVEPublished)
}