-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(linter): add a check for affected field
Signed-off-by: Holly Gong <[email protected]>
- Loading branch information
Showing
6 changed files
with
1,678 additions
and
4 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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package checks | ||
|
||
import ( | ||
"github.com/tidwall/gjson" | ||
) | ||
|
||
var CheckAffectedFieldValid = &CheckDef{ | ||
Code: "A0001", | ||
Name: "affected-field-valid", | ||
Description: "affected field validates", | ||
Check: AffectedFieldValid, | ||
} | ||
|
||
// AffectedFieldValid checks if the 'affected' field exists in the JSON and is not an empty array. | ||
func AffectedFieldValid(json *gjson.Result, config *Config) (findings []CheckError) { | ||
affectedEntries := json.Get("affected") | ||
if !affectedEntries.Exists() || affectedEntries.String() == "[]" { | ||
findings = append(findings, CheckError{Message: "Invalid Affected: affected filed cannot be null or empty"}) | ||
} | ||
return findings | ||
} |
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,51 @@ | ||
package checks | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/tidwall/gjson" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
"github.com/google/go-cmp/cmp/cmpopts" | ||
) | ||
|
||
func TestAffectedField(t *testing.T) { | ||
type args struct { | ||
json *gjson.Result | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
wantFindings []CheckError | ||
}{ | ||
{ | ||
name: "A compliant file", | ||
args: args{ | ||
json: LoadTestData("../../test_data/CVE-2023-41045.json"), | ||
}, | ||
wantFindings: nil, | ||
}, | ||
{ | ||
name: "A file with an empty affected field", | ||
args: args{ | ||
json: LoadTestData("../../test_data/SUSE-FU-2022:0444-1.json"), | ||
}, | ||
wantFindings: []CheckError{{Message: "Invalid Affected: affected filed cannot be null or empty"}}, | ||
}, | ||
{ | ||
name: "A file without affected field", | ||
args: args{ | ||
json: LoadTestData("../../test_data/RHSA-2022:0216.json"), | ||
}, | ||
wantFindings: []CheckError{{Message: "Invalid Affected: affected filed cannot be null or empty"}}, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
gotFindings := AffectedFieldValid(tt.args.json, &Config{Verbose: true}) | ||
if diff := cmp.Diff(tt.wantFindings, gotFindings, cmpopts.EquateErrors()); diff != "" { | ||
t.Errorf("AffectedFieldValid() mismatch (-want +got):\n%s", diff) | ||
} | ||
}) | ||
} | ||
} |
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,128 @@ | ||
{ | ||
"id": "RHSA-2022:0216", | ||
"summary": "Red Hat Security Advisory: Red Hat JBoss Enterprise Application Platform 7.4 security update", | ||
"modified": "2024-09-01T17:42:35Z", | ||
"published": "2024-09-01T17:42:35Z", | ||
"related": [ | ||
"CVE-2021-44832", | ||
"CVE-2021-45046", | ||
"CVE-2021-45105" | ||
], | ||
"references": [ | ||
{ | ||
"type": "ADVISORY", | ||
"url": "https://access.redhat.com/errata/RHSA-2022:0216" | ||
}, | ||
{ | ||
"type": "ARTICLE", | ||
"url": "https://access.redhat.com/security/updates/classification/#low" | ||
}, | ||
{ | ||
"type": "ARTICLE", | ||
"url": "https://access.redhat.com/jbossnetwork/restricted/listSoftware.html?downloadType=securityPatches&product=appplatform&version=7.4" | ||
}, | ||
{ | ||
"type": "ARTICLE", | ||
"url": "https://access.redhat.com/security/vulnerabilities/RHSB-2021-009" | ||
}, | ||
{ | ||
"type": "ARTICLE", | ||
"url": "https://access.redhat.com/solutions/6577421" | ||
}, | ||
{ | ||
"type": "ARTICLE", | ||
"url": "https://access.redhat.com/documentation/en-us/red_hat_jboss_enterprise_application_platform/7.4/" | ||
}, | ||
{ | ||
"type": "ARTICLE", | ||
"url": "https://access.redhat.com/documentation/en-us/red_hat_jboss_enterprise_application_platform/7.4/html-single/installation_guide/" | ||
}, | ||
{ | ||
"type": "REPORT", | ||
"url": "https://bugzilla.redhat.com/show_bug.cgi?id=2032580" | ||
}, | ||
{ | ||
"type": "REPORT", | ||
"url": "https://bugzilla.redhat.com/show_bug.cgi?id=2034067" | ||
}, | ||
{ | ||
"type": "REPORT", | ||
"url": "https://bugzilla.redhat.com/show_bug.cgi?id=2035951" | ||
}, | ||
{ | ||
"type": "ADVISORY", | ||
"url": "https://access.redhat.com/security/data/csaf/v2/advisories/2022/rhsa-2022_0216.json" | ||
}, | ||
{ | ||
"type": "REPORT", | ||
"url": "https://access.redhat.com/security/cve/CVE-2021-44832" | ||
}, | ||
{ | ||
"type": "ADVISORY", | ||
"url": "https://www.cve.org/CVERecord?id=CVE-2021-44832" | ||
}, | ||
{ | ||
"type": "ADVISORY", | ||
"url": "https://nvd.nist.gov/vuln/detail/CVE-2021-44832" | ||
}, | ||
{ | ||
"type": "ARTICLE", | ||
"url": "https://issues.apache.org/jira/browse/LOG4J2-3293" | ||
}, | ||
{ | ||
"type": "REPORT", | ||
"url": "https://access.redhat.com/security/cve/CVE-2021-45046" | ||
}, | ||
{ | ||
"type": "ADVISORY", | ||
"url": "https://www.cve.org/CVERecord?id=CVE-2021-45046" | ||
}, | ||
{ | ||
"type": "ADVISORY", | ||
"url": "https://nvd.nist.gov/vuln/detail/CVE-2021-45046" | ||
}, | ||
{ | ||
"type": "ARTICLE", | ||
"url": "https://access.redhat.com/security/cve/CVE-2021-44228" | ||
}, | ||
{ | ||
"type": "ARTICLE", | ||
"url": "https://logging.apache.org/log4j/2.x/security.html" | ||
}, | ||
{ | ||
"type": "ARTICLE", | ||
"url": "https://www.openwall.com/lists/oss-security/2021/12/14/4" | ||
}, | ||
{ | ||
"type": "ARTICLE", | ||
"url": "https://www.cisa.gov/known-exploited-vulnerabilities-catalog" | ||
}, | ||
{ | ||
"type": "REPORT", | ||
"url": "https://access.redhat.com/security/cve/CVE-2021-45105" | ||
}, | ||
{ | ||
"type": "ADVISORY", | ||
"url": "https://www.cve.org/CVERecord?id=CVE-2021-45105" | ||
}, | ||
{ | ||
"type": "ADVISORY", | ||
"url": "https://nvd.nist.gov/vuln/detail/CVE-2021-45105" | ||
}, | ||
{ | ||
"type": "ARTICLE", | ||
"url": "https://issues.apache.org/jira/browse/LOG4J2-3230" | ||
}, | ||
{ | ||
"type": "ARTICLE", | ||
"url": "https://www.openwall.com/lists/oss-security/2021/12/19/1" | ||
} | ||
], | ||
"schema_version": "1.6.0", | ||
"severity": [ | ||
{ | ||
"type": "CVSS_V3", | ||
"score": "CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:H" | ||
} | ||
] | ||
} |
Oops, something went wrong.