Remove Version field from LogMessage (#1640)

Co-authored-by: Azeem Shaikh <azeems@google.com>
This commit is contained in:
Azeem Shaikh 2022-02-15 10:26:06 -08:00 committed by GitHub
parent 35511342c8
commit 2b206dc365
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 139 additions and 266 deletions

View File

@ -110,8 +110,6 @@ type LogMessage struct {
Offset uint // Offset in the file of Path (line for source/text files).
EndOffset uint // End of offset in the file, e.g. if the command spans multiple lines.
Snippet string // Snippet of code
// UPGRADEv3: to remove.
Version int // `3` to indicate the detail was logged using new structure.
}
// CreateProportionalScore creates a proportional score.

View File

@ -85,7 +85,6 @@ func CITests(c *checker.CheckRequest) checker.CheckResult {
if !foundCI {
c.Dlogger.Debug(&checker.LogMessage{
Text: fmt.Sprintf("merged PR without CI test: %d", pr.Number),
Version: 3,
})
}
}
@ -115,7 +114,6 @@ func prHasSuccessStatus(pr *clients.PullRequest, c *checker.CheckRequest) (bool,
Type: checker.FileTypeURL,
Text: fmt.Sprintf("CI test found: pr: %d, context: %s", pr.Number,
status.Context),
Version: 3,
})
return true, nil
}
@ -143,7 +141,6 @@ func prHasSuccessfulCheck(pr *clients.PullRequest, c *checker.CheckRequest) (boo
Type: checker.FileTypeURL,
Text: fmt.Sprintf("CI test found: pr: %d, context: %s", pr.Number,
cr.App.Slug),
Version: 3,
})
return true, nil
}

View File

@ -75,7 +75,6 @@ func Contributors(c *checker.CheckRequest) checker.CheckResult {
c.Dlogger.Info(&checker.LogMessage{
Text: fmt.Sprintf("contributors work for: %v", strings.Join(names, ",")),
Version: 3,
})
reason := fmt.Sprintf("%d different companies found", len(companies))

View File

@ -335,7 +335,6 @@ func checkJobForUntrustedCodeCheckout(job *actionlint.Job, path string,
Type: checker.FileTypeSource,
Offset: line,
Text: fmt.Sprintf("untrusted code checkout '%v'", ref.Value.Value),
Version: 3,
// TODO: set Snippet.
})
// Detected untrusted checkout.
@ -449,7 +448,6 @@ func checkSecretInScript(script string, pos *actionlint.Pos, path string,
Type: checker.FileTypeSource,
Offset: line,
Text: fmt.Sprintf("secret accessible to pull requests '%v'", variable),
Version: 3,
// TODO: set Snippet.
})
pdata.workflowPattern[secretsViaPullRequests] = true
@ -481,7 +479,6 @@ func checkVariablesInScript(script string, pos *actionlint.Pos, path string,
Type: checker.FileTypeSource,
Offset: line,
Text: fmt.Sprintf("script injection with untrusted input '%v'", variable),
Version: 3,
// TODO: set Snippet.
})
pdata.workflowPattern[scriptInjection] = true

View File

@ -38,7 +38,6 @@ func BinaryArtifacts(name string, dl checker.DetailLogger,
Path: f.Path, Type: checker.FileTypeBinary,
Offset: f.Offset,
Text: "binary detected",
Version: 3,
})
// We remove one point for each binary.
score--

View File

@ -54,7 +54,6 @@ func CodeReview(name string, dl checker.DetailLogger,
if rs == "" {
dl.Warn(&checker.LogMessage{
Text: fmt.Sprintf("no reviews found for commit: %s", commit.SHA),
Version: 3,
})
continue
}
@ -127,7 +126,6 @@ func isReviewedOnGitHub(c *checker.DefaultBranchCommit, dl checker.DetailLogger)
dl.Debug(&checker.LogMessage{
Text: fmt.Sprintf("commit %s was reviewed through %s #%d approved merge request",
c.SHA, reviewPlatformGitHub, mr.Number),
Version: 3,
})
return true
}
@ -141,7 +139,6 @@ func isReviewedOnGitHub(c *checker.DefaultBranchCommit, dl checker.DetailLogger)
dl.Debug(&checker.LogMessage{
Text: fmt.Sprintf("commit %s was reviewed through %s #%d merge request",
c.SHA, reviewPlatformGitHub, mr.Number),
Version: 3,
})
return true
}
@ -153,7 +150,6 @@ func isReviewedOnProw(c *checker.DefaultBranchCommit, dl checker.DetailLogger) b
if isBot(c.Committer.Login) {
dl.Debug(&checker.LogMessage{
Text: fmt.Sprintf("skip commit %s from bot account: %s", c.SHA, c.Committer.Login),
Version: 3,
})
return true
}
@ -164,7 +160,6 @@ func isReviewedOnProw(c *checker.DefaultBranchCommit, dl checker.DetailLogger) b
dl.Debug(&checker.LogMessage{
Text: fmt.Sprintf("commit %s review was through %s #%d approved merge request",
c.SHA, reviewPlatformProw, c.MergeRequest.Number),
Version: 3,
})
return true
}
@ -177,7 +172,6 @@ func isReviewedOnGerrit(c *checker.DefaultBranchCommit, dl checker.DetailLogger)
if isBot(c.Committer.Login) {
dl.Debug(&checker.LogMessage{
Text: fmt.Sprintf("skip commit %s from bot account: %s", c.SHA, c.Committer.Login),
Version: 3,
})
return true
}
@ -187,7 +181,6 @@ func isReviewedOnGerrit(c *checker.DefaultBranchCommit, dl checker.DetailLogger)
strings.Contains(m, "\nReviewed-by: ") {
dl.Debug(&checker.LogMessage{
Text: fmt.Sprintf("commit %s was approved through %s", c.SHA, reviewPlatformGerrit),
Version: 3,
})
return true
}

View File

@ -34,12 +34,10 @@ func DependencyUpdateTool(name string, dl checker.DetailLogger,
dl.Warn(&checker.LogMessage{
Text: `dependabot config file not detected in source location.
We recommend setting this configuration in code so it can be easily verified by others.`,
Version: 3,
})
dl.Warn(&checker.LogMessage{
Text: `renovatebot config file not detected in source location.
We recommend setting this configuration in code so it can be easily verified by others.`,
Version: 3,
})
return checker.CreateMinScoreResult(name, "no update tool detected")
}
@ -63,7 +61,6 @@ func DependencyUpdateTool(name string, dl checker.DetailLogger,
Type: r.Tools[0].ConfigFiles[0].Type,
Offset: r.Tools[0].ConfigFiles[0].Offset,
Text: fmt.Sprintf("%s detected", r.Tools[0].Name),
Version: 3,
})
// High score result.

View File

@ -36,7 +36,6 @@ func SecurityPolicy(name string, dl checker.DetailLogger, r *checker.SecurityPol
Path: f.Path,
Type: f.Type,
Offset: f.Offset,
Version: 3,
}
if msg.Type == checker.FileTypeURL {
msg.Text = "security policy detected in org repo"

View File

@ -44,7 +44,6 @@ func Vulnerabilities(name string, dl checker.DetailLogger,
if len(IDs) > 0 {
dl.Warn(&checker.LogMessage{
Text: fmt.Sprintf("HEAD is vulnerable to %s", strings.Join(IDs, ", ")),
Version: 3,
})
return checker.CreateResultWithScore(name,
fmt.Sprintf("%v existing vulnerabilities detected", len(IDs)), score)

View File

@ -113,7 +113,6 @@ func LicenseCheck(c *checker.CheckRequest) checker.CheckResult {
Path: name,
Type: checker.FileTypeSource,
Offset: 1,
Version: 3,
})
*pdata = true
return false, nil

View File

@ -71,7 +71,6 @@ func Packaging(c *checker.CheckRequest) checker.CheckResult {
Type: checker.FileTypeSource,
Offset: checker.OffsetDefault,
Text: fmt.Sprintf("GitHub publishing workflow used in run %s", runs[0].URL),
Version: 3,
})
return checker.CreateMaxScoreResult(CheckPackaging,
"publishing workflow detected")
@ -81,13 +80,11 @@ func Packaging(c *checker.CheckRequest) checker.CheckResult {
Type: checker.FileTypeSource,
Offset: checker.OffsetDefault,
Text: "GitHub publishing workflow not used in runs",
Version: 3,
})
}
c.Dlogger.Warn(&checker.LogMessage{
Text: "no GitHub publishing workflow detected",
Version: 3,
})
return checker.CreateInconclusiveResult(CheckPackaging,
@ -215,7 +212,6 @@ func isPackagingWorkflow(workflow *actionlint.Workflow, fp string, dl checker.De
Type: checker.FileTypeSource,
Offset: fileparser.GetLineNumber(job.Pos),
Text: matcher.LogText,
Version: 3,
})
return true
}
@ -226,7 +222,6 @@ func isPackagingWorkflow(workflow *actionlint.Workflow, fp string, dl checker.De
Type: checker.FileTypeSource,
Offset: checker.OffsetDefault,
Text: "not a publishing workflow",
Version: 3,
})
return false
}

View File

@ -102,7 +102,6 @@ func validatePermission(permissionKey permission, permissionValue *actionlint.Pe
Type: checker.FileTypeSource,
Offset: lineNumber,
Text: fmt.Sprintf("%s '%v' permission set to '%v'", permLevel, permissionKey, val),
Version: 3,
// TODO: set Snippet.
})
recordPermissionWrite(pPermissions, permissionKey)
@ -114,7 +113,6 @@ func validatePermission(permissionKey permission, permissionValue *actionlint.Pe
Type: checker.FileTypeSource,
Offset: lineNumber,
Text: fmt.Sprintf("%s '%v' permission set to '%v'", permLevel, permissionKey, val),
Version: 3,
// TODO: set Snippet.
})
}
@ -126,7 +124,6 @@ func validatePermission(permissionKey permission, permissionValue *actionlint.Pe
Type: checker.FileTypeSource,
Offset: lineNumber,
Text: fmt.Sprintf("%s '%v' permission set to '%v'", permLevel, permissionKey, val),
Version: 3,
// TODO: set Snippet.
})
return nil
@ -178,7 +175,6 @@ func validatePermissions(permissions *actionlint.Permissions, permLevel, path st
Type: checker.FileTypeSource,
Offset: checker.OffsetDefault,
Text: fmt.Sprintf("%s permissions set to 'none'", permLevel),
Version: 3,
})
}
if allIsSet {
@ -190,7 +186,6 @@ func validatePermissions(permissions *actionlint.Permissions, permLevel, path st
Type: checker.FileTypeSource,
Offset: lineNumber,
Text: fmt.Sprintf("%s permissions set to '%v'", permLevel, val),
Version: 3,
// TODO: set Snippet.
})
recordAllPermissionsWrite(pdata, permLevel, path)
@ -202,7 +197,6 @@ func validatePermissions(permissions *actionlint.Permissions, permLevel, path st
Type: checker.FileTypeSource,
Offset: lineNumber,
Text: fmt.Sprintf("%s permissions set to '%v'", permLevel, val),
Version: 3,
// TODO: set Snippet.
})
} else /* scopeIsSet == true */ if err := validateMapPermissions(permissions.Scopes,
@ -221,7 +215,6 @@ func validateTopLevelPermissions(workflow *actionlint.Workflow, path string,
Type: checker.FileTypeSource,
Offset: checker.OffsetDefault,
Text: fmt.Sprintf("no %s permission defined", topLevelPermission),
Version: 3,
})
recordAllPermissionsWrite(pdata, topLevelPermission, path)
return nil
@ -244,7 +237,6 @@ func validatejobLevelPermissions(workflow *actionlint.Workflow, path string,
Type: checker.FileTypeSource,
Offset: fileparser.GetLineNumber(job.Pos),
Text: fmt.Sprintf("no %s permission defined", jobLevelPermission),
Version: 3,
})
recordAllPermissionsWrite(pdata, jobLevelPermission, path)
continue
@ -485,7 +477,6 @@ func isSARIFUploadAction(workflow *actionlint.Workflow, fp string, dl checker.De
Type: checker.FileTypeSource,
Offset: fileparser.GetLineNumber(uses.Pos),
Text: "codeql SARIF upload workflow detected",
Version: 3,
// TODO: set Snippet.
})
return true
@ -497,7 +488,6 @@ func isSARIFUploadAction(workflow *actionlint.Workflow, fp string, dl checker.De
Type: checker.FileTypeSource,
Offset: checker.OffsetDefault,
Text: "not a codeql upload SARIF workflow",
Version: 3,
})
return false
}
@ -519,7 +509,6 @@ func isCodeQlAnalysisWorkflow(workflow *actionlint.Workflow, fp string, dl check
Type: checker.FileTypeSource,
Offset: fileparser.GetLineNumber(uses.Pos),
Text: "codeql workflow detected",
Version: 3,
// TODO: set Snippet.
})
return true
@ -531,7 +520,6 @@ func isCodeQlAnalysisWorkflow(workflow *actionlint.Workflow, fp string, dl check
Type: checker.FileTypeSource,
Offset: checker.OffsetDefault,
Text: "not a codeql workflow",
Version: 3,
})
return false
}

View File

@ -165,7 +165,6 @@ func createReturnValuesForGitHubActionsWorkflowPinned(r worklowPinningResult, in
Type: checker.FileTypeSource,
Offset: checker.OffsetDefault,
Text: fmt.Sprintf("%s %s", "GitHub-owned", infoMsg),
Version: 3,
})
}
@ -175,7 +174,6 @@ func createReturnValuesForGitHubActionsWorkflowPinned(r worklowPinningResult, in
Type: checker.FileTypeSource,
Offset: checker.OffsetDefault,
Text: fmt.Sprintf("%s %s", "Third-party", infoMsg),
Version: 3,
})
}
@ -440,7 +438,6 @@ func validateDockerfileIsPinned(pathfn string, content []byte,
EndOffset: uint(child.EndLine),
Text: "docker image not pinned by hash",
Snippet: child.Original,
Version: 3,
})
// FROM name.
@ -456,7 +453,6 @@ func validateDockerfileIsPinned(pathfn string, content []byte,
EndOffset: uint(child.EndLine),
Text: "docker image not pinned by hash",
Snippet: child.Original,
Version: 3,
})
}
@ -666,7 +662,6 @@ func validateGitHubActionWorkflow(pathfn string, content []byte,
EndOffset: uint(execAction.Uses.Pos.Line), // `Uses` always span a single line.
Snippet: execAction.Uses.Value,
Text: fmt.Sprintf("%s action not pinned by hash", owner),
Version: 3,
})
}

View File

@ -144,7 +144,6 @@ func sastToolInCheckRuns(c *checker.CheckRequest) (int, error) {
Path: cr.URL,
Type: checker.FileTypeURL,
Text: "tool detected",
Version: 3,
})
totalTested++
break
@ -154,7 +153,6 @@ func sastToolInCheckRuns(c *checker.CheckRequest) (int, error) {
if totalMerged == 0 {
c.Dlogger.Warn(&checker.LogMessage{
Text: "no pull requests merged into dev branch",
Version: 3,
})
return checker.InconclusiveResultScore, nil
}
@ -162,12 +160,10 @@ func sastToolInCheckRuns(c *checker.CheckRequest) (int, error) {
if totalTested == totalMerged {
c.Dlogger.Info(&checker.LogMessage{
Text: fmt.Sprintf("all commits (%v) are checked with a SAST tool", totalMerged),
Version: 3,
})
} else {
c.Dlogger.Warn(&checker.LogMessage{
Text: fmt.Sprintf("%v commits out of %v are checked with a SAST tool", totalTested, totalMerged),
Version: 3,
})
}
@ -192,7 +188,6 @@ func codeQLInCheckDefinitions(c *checker.CheckRequest) (int, error) {
Type: checker.FileTypeSource,
Offset: checker.OffsetDefault,
Text: "CodeQL detected",
Version: 3,
})
}
@ -201,14 +196,12 @@ func codeQLInCheckDefinitions(c *checker.CheckRequest) (int, error) {
if resp.Hits > 0 {
c.Dlogger.Info(&checker.LogMessage{
Text: "SAST tool detected: CodeQL",
Version: 3,
})
return checker.MaxResultScore, nil
}
c.Dlogger.Warn(&checker.LogMessage{
Text: "CodeQL tool not detected",
Version: 3,
})
return checker.MinResultScore, nil
}

View File

@ -331,7 +331,6 @@ func isFetchPipeExecute(startLine, endLine uint, node syntax.Node, cmd, pathfn s
EndOffset: endLine,
Snippet: cmd,
Text: "insecure (not pinned by hash) download detected",
Version: 3,
})
return true
}
@ -380,7 +379,6 @@ func isExecuteFiles(startLine, endLine uint, node syntax.Node, cmd, pathfn strin
EndOffset: endLine,
Snippet: cmd,
Text: "insecure (not pinned by hash) download-then-run",
Version: 3,
})
ok = true
}
@ -598,7 +596,6 @@ func isUnpinnedPakageManagerDownload(startLine, endLine uint, node syntax.Node,
EndOffset: endLine,
Snippet: cmd,
Text: "go installation not pinned by hash",
Version: 3,
})
return true
}
@ -612,7 +609,6 @@ func isUnpinnedPakageManagerDownload(startLine, endLine uint, node syntax.Node,
EndOffset: endLine,
Snippet: cmd,
Text: "pip installation not pinned by hash",
Version: 3,
})
return true
}
@ -626,7 +622,6 @@ func isUnpinnedPakageManagerDownload(startLine, endLine uint, node syntax.Node,
EndOffset: endLine,
Snippet: cmd,
Text: "npm installation not pinned by hash",
Version: 3,
})
return true
}
@ -719,7 +714,6 @@ func isFetchProcSubsExecute(startLine, endLine uint, node syntax.Node, cmd, path
EndOffset: endLine,
Snippet: cmd,
Text: "insecure (not pinned by hash) download-then-run",
Version: 3,
})
return true
}

View File

@ -54,7 +54,6 @@ func SignedReleases(c *checker.CheckRequest) checker.CheckResult {
}
c.Dlogger.Debug(&checker.LogMessage{
Text: fmt.Sprintf("GitHub release found: %s", r.TagName),
Version: 3,
})
totalReleases++
signed := false
@ -65,7 +64,6 @@ func SignedReleases(c *checker.CheckRequest) checker.CheckResult {
Path: asset.URL,
Type: checker.FileTypeURL,
Text: fmt.Sprintf("signed release artifact: %s", asset.Name),
Version: 3,
})
signed = true
break
@ -81,7 +79,6 @@ func SignedReleases(c *checker.CheckRequest) checker.CheckResult {
Path: r.URL,
Type: checker.FileTypeURL,
Text: fmt.Sprintf("release artifact %s not signed", r.TagName),
Version: 3,
})
}
if totalReleases >= releaseLookBack {
@ -92,7 +89,6 @@ func SignedReleases(c *checker.CheckRequest) checker.CheckResult {
if totalReleases == 0 {
c.Dlogger.Warn(&checker.LogMessage{
Text: "no GitHub releases found",
Version: 3,
})
// Generic summary.
return checker.CreateInconclusiveResult(CheckSignedReleases, "no releases found")

View File

@ -113,8 +113,6 @@ func TestJSONOutput(t *testing.T) {
Type: checker.FileTypeSource,
Offset: 5,
Snippet: "if (bad) {BUG();}",
// UPGRADEv3: to remove.
Version: 3,
},
},
},
@ -151,8 +149,6 @@ func TestJSONOutput(t *testing.T) {
Path: "bin/binary.elf",
Type: checker.FileTypeBinary,
Offset: 0,
// UPGRADEv3: to remove.
Version: 3,
},
},
},
@ -189,8 +185,6 @@ func TestJSONOutput(t *testing.T) {
Path: "bin/binary.elf",
Type: checker.FileTypeBinary,
Offset: 0,
// UPGRADEv3: to remove.
Version: 3,
},
},
},
@ -208,8 +202,6 @@ func TestJSONOutput(t *testing.T) {
Type: checker.FileTypeText,
Offset: 3,
Snippet: "some text",
// UPGRADEv3: to remove.
Version: 3,
},
},
},
@ -227,8 +219,6 @@ func TestJSONOutput(t *testing.T) {
Type: checker.FileTypeSource,
Offset: 3,
Snippet: "if (bad) {BUG();}",
// UPGRADEv3: to remove.
Version: 3,
},
},
{
@ -239,8 +229,6 @@ func TestJSONOutput(t *testing.T) {
Type: checker.FileTypeSource,
Offset: 3,
Snippet: "if (bad) {BUG2();}",
// UPGRADEv3: to remove.
Version: 3,
},
},
{
@ -251,8 +239,6 @@ func TestJSONOutput(t *testing.T) {
Type: checker.FileTypeSource,
Offset: 3,
Snippet: "if (bad) {BUG5();}",
// UPGRADEv3: to remove.
Version: 3,
},
},
},
@ -289,8 +275,6 @@ func TestJSONOutput(t *testing.T) {
Path: "bin/binary.elf",
Type: checker.FileTypeBinary,
Offset: 0,
// UPGRADEv3: to remove.
Version: 3,
},
},
},
@ -308,8 +292,6 @@ func TestJSONOutput(t *testing.T) {
Type: checker.FileTypeText,
Offset: 3,
Snippet: "some text",
// UPGRADEv3: to remove.
Version: 3,
},
},
},
@ -327,8 +309,6 @@ func TestJSONOutput(t *testing.T) {
Type: checker.FileTypeSource,
Offset: 3,
Snippet: "if (bad) {BUG();}",
// UPGRADEv3: to remove.
Version: 3,
},
},
{
@ -339,8 +319,6 @@ func TestJSONOutput(t *testing.T) {
Type: checker.FileTypeSource,
Offset: 3,
Snippet: "if (bad) {BUG2();}",
// UPGRADEv3: to remove.
Version: 3,
},
},
{
@ -351,8 +329,6 @@ func TestJSONOutput(t *testing.T) {
Type: checker.FileTypeSource,
Offset: 3,
Snippet: "if (bad) {BUG5();}",
// UPGRADEv3: to remove.
Version: 3,
},
},
},
@ -390,8 +366,6 @@ func TestJSONOutput(t *testing.T) {
Type: checker.FileTypeSource,
Offset: 5,
Snippet: "if (bad) {BUG();}",
// UPGRADEv3: to remove.
Version: 3,
},
},
},
@ -427,8 +401,6 @@ func TestJSONOutput(t *testing.T) {
Text: "warn message",
Path: "https://domain.com/something",
Type: checker.FileTypeURL,
// UPGRADEv3: to remove.
Version: 3,
},
},
},

View File

@ -28,12 +28,10 @@ func textToMarkdown(s string) string {
// DetailToString turns a detail information into a string.
func DetailToString(d *checker.CheckDetail, logLevel log.Level) string {
// TODO(#1393): remove switch statement.
switch d.Msg.Version {
case 3:
if d.Type == checker.DetailDebug && logLevel != log.DebugLevel {
return ""
}
switch {
case d.Msg.Path != "" && d.Msg.Offset != 0 && d.Msg.EndOffset != 0 && d.Msg.Offset < d.Msg.EndOffset:
return fmt.Sprintf("%s: %s: %s:%d-%d", typeToString(d.Type), d.Msg.Text, d.Msg.Path, d.Msg.Offset, d.Msg.EndOffset)
@ -44,12 +42,6 @@ func DetailToString(d *checker.CheckDetail, logLevel log.Level) string {
default:
return fmt.Sprintf("%s: %s", typeToString(d.Type), d.Msg.Text)
}
default:
if d.Type == checker.DetailDebug && logLevel != log.DebugLevel {
return ""
}
return fmt.Sprintf("%s: %s", typeToString(d.Type), d.Msg.Text)
}
}
func detailsToString(details []checker.CheckDetail, logLevel log.Level) (string, bool) {

View File

@ -112,8 +112,6 @@ func TestJSONOutput(t *testing.T) {
Type: checker.FileTypeSource,
Offset: 5,
Snippet: "if (bad) {BUG();}",
// UPGRADEv3: to remove.
Version: 3,
},
},
},
@ -150,8 +148,6 @@ func TestJSONOutput(t *testing.T) {
Path: "bin/binary.elf",
Type: checker.FileTypeBinary,
Offset: 0,
// UPGRADEv3: to remove.
Version: 3,
},
},
},
@ -188,8 +184,6 @@ func TestJSONOutput(t *testing.T) {
Path: "bin/binary.elf",
Type: checker.FileTypeBinary,
Offset: 0,
// UPGRADEv3: to remove.
Version: 3,
},
},
},
@ -207,8 +201,6 @@ func TestJSONOutput(t *testing.T) {
Type: checker.FileTypeText,
Offset: 3,
Snippet: "some text",
// UPGRADEv3: to remove.
Version: 3,
},
},
},
@ -226,8 +218,6 @@ func TestJSONOutput(t *testing.T) {
Type: checker.FileTypeSource,
Offset: 3,
Snippet: "if (bad) {BUG();}",
// UPGRADEv3: to remove.
Version: 3,
},
},
{
@ -238,8 +228,6 @@ func TestJSONOutput(t *testing.T) {
Type: checker.FileTypeSource,
Offset: 3,
Snippet: "if (bad) {BUG2();}",
// UPGRADEv3: to remove.
Version: 3,
},
},
{
@ -250,8 +238,6 @@ func TestJSONOutput(t *testing.T) {
Type: checker.FileTypeSource,
Offset: 3,
Snippet: "if (bad) {BUG5();}",
// UPGRADEv3: to remove.
Version: 3,
},
},
},
@ -288,8 +274,6 @@ func TestJSONOutput(t *testing.T) {
Path: "bin/binary.elf",
Type: checker.FileTypeBinary,
Offset: 0,
// UPGRADEv3: to remove.
Version: 3,
},
},
},
@ -307,8 +291,6 @@ func TestJSONOutput(t *testing.T) {
Type: checker.FileTypeText,
Offset: 3,
Snippet: "some text",
// UPGRADEv3: to remove.
Version: 3,
},
},
},
@ -326,8 +308,6 @@ func TestJSONOutput(t *testing.T) {
Type: checker.FileTypeSource,
Offset: 3,
Snippet: "if (bad) {BUG();}",
// UPGRADEv3: to remove.
Version: 3,
},
},
{
@ -338,8 +318,6 @@ func TestJSONOutput(t *testing.T) {
Type: checker.FileTypeSource,
Offset: 3,
Snippet: "if (bad) {BUG2();}",
// UPGRADEv3: to remove.
Version: 3,
},
},
{
@ -350,8 +328,6 @@ func TestJSONOutput(t *testing.T) {
Type: checker.FileTypeSource,
Offset: 3,
Snippet: "if (bad) {BUG5();}",
// UPGRADEv3: to remove.
Version: 3,
},
},
},
@ -389,8 +365,6 @@ func TestJSONOutput(t *testing.T) {
Type: checker.FileTypeSource,
Offset: 5,
Snippet: "if (bad) {BUG();}",
// UPGRADEv3: to remove.
Version: 3,
},
},
},
@ -426,8 +400,6 @@ func TestJSONOutput(t *testing.T) {
Text: "warn message",
Path: "https://domain.com/something",
Type: checker.FileTypeURL,
// UPGRADEv3: to remove.
Version: 3,
},
},
},

View File

@ -21,6 +21,8 @@ import (
"testing"
"time"
"github.com/google/go-cmp/cmp"
"github.com/ossf/scorecard/v4/checker"
"github.com/ossf/scorecard/v4/log"
spol "github.com/ossf/scorecard/v4/policy"
@ -767,8 +769,8 @@ func TestSARIFOutput(t *testing.T) {
},
},
}
for _, tt := range tests {
tt := tt // Re-initializing variable so it is not changed while executing the closure below
for i := range tests {
tt := &tests[i] // Re-initializing variable so it is not changed while executing the closure below
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
var content []byte
@ -796,7 +798,7 @@ func TestSARIFOutput(t *testing.T) {
r := bytes.Compare(expected.Bytes(), result.Bytes())
if r != 0 {
t.Fatalf("%s: invalid result: %d", tt.name, r)
t.Fatalf("%s: invalid result: %d, %s", tt.name, r, cmp.Diff(expected.Bytes(), result.Bytes()))
}
})
}

View File

@ -47,7 +47,7 @@
"ruleId": "CheckNameID",
"ruleIndex": 0,
"message": {
"text": "score is 6: six score reason:\nWarn: warn message\nClick Remediation section below to solve this issue"
"text": "score is 6: six score reason:\nWarn: warn message: https://domain.com/something\nClick Remediation section below to solve this issue"
},
"locations": [
{

View File

@ -46,7 +46,6 @@ func (l *TestDetailLogger) Info(msg *checker.LogMessage) {
Type: checker.DetailInfo,
Msg: *msg,
}
cd.Msg.Version = 3
l.messages = append(l.messages, cd)
}
@ -56,7 +55,6 @@ func (l *TestDetailLogger) Warn(msg *checker.LogMessage) {
Type: checker.DetailWarn,
Msg: *msg,
}
cd.Msg.Version = 3
l.messages = append(l.messages, cd)
}
@ -66,7 +64,6 @@ func (l *TestDetailLogger) Debug(msg *checker.LogMessage) {
Type: checker.DetailDebug,
Msg: *msg,
}
cd.Msg.Version = 3
l.messages = append(l.messages, cd)
}