Skip to content
This repository was archived by the owner on Sep 11, 2026. It is now read-only.

Commit 1169f42

Browse files
committed
add check for product uid in OCSF validation helpers
1 parent 8e6def2 commit 1169f42

2 files changed

Lines changed: 33 additions & 10 deletions

File tree

sdk/component/utils/testing/oscf_vulnerability_finding_verification.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ func AssertVulnerabilityFindingIsValid(t *testing.T, finding *ocsf.Vulnerability
2323

2424
assert.NotEmpty(t, findingInfo.GetUid(), "FindingInfo.Uid is required")
2525
assert.NotEmpty(t, findingInfo.GetTitle(), "FindingInfo.Title is required")
26+
assert.NotEmpty(t, findingInfo.GetProductUid(), "Product Uid is required")
2627

2728
dataSourcesJson := findingInfo.GetDataSources()
2829
require.Len(t, dataSourcesJson, 1, "Exactly one 'DataSource' JSON string is required")
@@ -136,6 +137,7 @@ func AssertFindingListsMatch(t *testing.T, expectedFindings, actualFindings []*o
136137

137138
assert.Equal(t, expectedDS.GetTargetType(), actualDS.GetTargetType(), "DataSource TargetType should match")
138139
assert.Equal(t, expectedDS.GetUri().GetPath(), actualDS.GetUri().GetPath(), "DataSource Uri Path should match")
140+
assert.Equal(t, expected.GetFindingInfo().GetProductUid(), actual.GetFindingInfo().GetProductUid(), "Product Uids don't match")
139141

140142
// Compare location data
141143
expectedLoc := expectedDS.GetFileFindingLocationData()

sdk/component/utils/testing/oscf_vulnerability_finding_verification_test.go

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,46 @@ import (
1010

1111
// TestCompareVulnerabilityFindings now sets up data and calls the assertion helper.
1212
func TestCompareVulnerabilityFindings(t *testing.T) {
13-
//repoDataSource := `{"targetType": 1, "uri": {"path": "file://user.go"}, "fileFindingLocationData": {"startLine": 50, "endLine": 55}, "sourceCodeMetadata": {"repositoryUrl": "https://github.com/my-org/my-repo", "reference": "refs/heads/main"}}`
1413
containerDataSource := `{"targetType": 2, "uri": {"path": "pkg:docker/my-app@sha256:f1..."}, "fileFindingLocationData": {"startLine": 1, "endLine": 1}, "ociPackageMetadata": {"packageUrl": "my-registry/my-app", "tag": "1.2.3"}}`
15-
//websiteDataSource := `{"targetType": 3, "uri": {"path": "https://example.com/login"}, "fileFindingLocationData": {"startLine": 25, "endLine": 30}, "websiteMetadata": {"url": "https://example.com/login"}}`
1614

1715
expectedFindings := []*ocsf.VulnerabilityFinding{
1816
{
19-
FindingInfo: &ocsf.FindingInfo{Uid: "G102", Title: "Outdated Container", DataSources: []string{containerDataSource}},
17+
FindingInfo: &ocsf.FindingInfo{
18+
Uid: "G102",
19+
Title: "Outdated Container",
20+
ProductUid: utils.Ptr("gosec"),
21+
DataSources: []string{containerDataSource},
22+
},
2023
Vulnerabilities: []*ocsf.Vulnerability{{
21-
// Cve: &ocsf.Cve{Uid: "2023-1234"},
22-
AffectedCode: []*ocsf.AffectedCode{{File: &ocsf.File{Name: "pkg:docker/my-app@sha256:f1..."}, StartLine: utils.Ptr(int32(1))}},
24+
AffectedCode: []*ocsf.AffectedCode{
25+
{
26+
File: &ocsf.File{
27+
Name: "pkg:docker/my-app@sha256:f1...",
28+
},
29+
StartLine: utils.Ptr(int32(1)),
30+
},
31+
},
2332
}},
2433
},
2534
}
2635

2736
actualFindings := []*ocsf.VulnerabilityFinding{
2837
{ // Matches G102 perfectly
29-
FindingInfo: &ocsf.FindingInfo{Uid: "G102", Title: "Outdated Container", DataSources: []string{containerDataSource}},
38+
FindingInfo: &ocsf.FindingInfo{
39+
Uid: "G102",
40+
Title: "Outdated Container",
41+
ProductUid: utils.Ptr("gosec"),
42+
DataSources: []string{containerDataSource},
43+
},
3044
Vulnerabilities: []*ocsf.Vulnerability{{
31-
// Cve: &ocsf.Cve{Uid: "2023-1234"},
32-
AffectedCode: []*ocsf.AffectedCode{{File: &ocsf.File{Name: "pkg:docker/my-app@sha256:f1..."}, StartLine: utils.Ptr(int32(1))}},
45+
AffectedCode: []*ocsf.AffectedCode{
46+
{
47+
File: &ocsf.File{
48+
Name: "pkg:docker/my-app@sha256:f1...",
49+
},
50+
StartLine: utils.Ptr(int32(1)),
51+
},
52+
},
3353
}},
3454
},
3555
}
@@ -42,8 +62,9 @@ func TestVulnerabilityFindingValidation(t *testing.T) {
4262
// A valid finding that should pass all assertions
4363
validFinding := &ocsf.VulnerabilityFinding{
4464
FindingInfo: &ocsf.FindingInfo{
45-
Uid: "G112",
46-
Title: "Uncontrolled Resource Consumption",
65+
Uid: "G112",
66+
Title: "Uncontrolled Resource Consumption",
67+
ProductUid: utils.Ptr("gosec"),
4768
// --- CORRECTED: JSON string is now a single object, not an array ---
4869
DataSources: []string{`{
4970
"targetType": 1,

0 commit comments

Comments
 (0)