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

feat: add line content to 2ms results #249

Merged
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
1 change: 1 addition & 0 deletions engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ func (e *Engine) Detect(item plugins.ISourceItem, secretsChannel chan *secrets.S
EndLine: endLine,
EndColumn: value.EndColumn,
Value: value.Secret,
LineContent: value.Line,
}
if !isSecretIgnored(secret, &e.ignoredIds, &e.allowedValues) {
secretsChannel <- secret
Expand Down
10 changes: 5 additions & 5 deletions engine/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package engine

import (
"fmt"
"github.com/stretchr/testify/assert"
"sync"
"testing"

Expand Down Expand Up @@ -159,11 +160,10 @@ func TestSecrets(t *testing.T) {

s := <-secretsChan

if s == nil && secret.ShouldFind {
t.Errorf("secret \"%s\" not found", secret.Name)
}
if s != nil && !secret.ShouldFind {
t.Errorf("should not find")
if secret.ShouldFind {
assert.Equal(t, s.LineContent, secret.Content)
} else {
assert.Nil(t, s)
}
})
}
Expand Down
8 changes: 6 additions & 2 deletions lib/reporting/sarif.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package reporting
import (
"encoding/json"
"fmt"

"github.com/checkmarx/2ms/lib/config"
"github.com/checkmarx/2ms/lib/secrets"
"strings"
)

func writeSarif(report Report, cfg *config.Config) (string, error) {
Expand Down Expand Up @@ -92,6 +92,9 @@ func getLocation(secret *secrets.Secret) []Locations {
EndColumn: secret.EndColumn,
Snippet: Snippet{
Text: secret.Value,
Properties: Properties{
"lineContent": strings.TrimSpace(secret.LineContent),
},
},
},
},
Expand Down Expand Up @@ -134,7 +137,8 @@ type Region struct {
}

type Snippet struct {
Text string `json:"text"`
Text string `json:"text"`
Properties Properties `json:"properties,omitempty"`
}

type PhysicalLocation struct {
Expand Down
1 change: 1 addition & 0 deletions lib/secrets/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type Secret struct {
RuleID string `json:"ruleId"`
StartLine int `json:"startLine"`
EndLine int `json:"endLine"`
LineContent string `json:"lineContent"`
StartColumn int `json:"startColumn"`
EndColumn int `json:"endColumn"`
Value string `json:"value"`
Expand Down
Loading