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

Add owner to github tokens #3558

Merged
merged 1 commit into from
Nov 4, 2024
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 pkg/analyzer/analyzers/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func secretInfoToAnalyzerResult(info *common.SecretInfo) *analyzers.AnalyzerResu
}
result := &analyzers.AnalyzerResult{
Metadata: map[string]any{
"owner": info.Metadata.User.Login,
"type": info.Metadata.Type,
"expiration": info.Metadata.Expiration,
},
Expand Down
24 changes: 9 additions & 15 deletions pkg/analyzer/analyzers/github/github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"
"time"

"github.com/google/go-cmp/cmp"
"github.com/trufflesecurity/trufflehog/v3/pkg/analyzer/analyzers"
"github.com/trufflesecurity/trufflehog/v3/pkg/common"
"github.com/trufflesecurity/trufflehog/v3/pkg/context"
Expand Down Expand Up @@ -229,6 +230,7 @@ func TestAnalyzer_Analyze(t *testing.T) {
],
"UnboundedResources": null,
"Metadata": {
"owner": "sirdetectsalot",
"expiration": "2025-08-05T00:00:00-07:00",
"type": "Fine-Grained GitHub Personal Access Token"
}
Expand Down Expand Up @@ -276,6 +278,7 @@ func TestAnalyzer_Analyze(t *testing.T) {
],
"UnboundedResources": null,
"Metadata": {
"owner": "truffle-sandbox",
"expiration": "0001-01-01T00:00:00Z",
"type": "Classic GitHub Personal Access Token"
}
Expand All @@ -293,7 +296,7 @@ func TestAnalyzer_Analyze(t *testing.T) {
}

// Marshal the actual result to JSON
gotJSON, err := json.Marshal(got)
gotJSON, err := json.MarshalIndent(got, "", " ")
if err != nil {
t.Fatalf("could not marshal got to JSON: %s", err)
}
Expand All @@ -304,25 +307,16 @@ func TestAnalyzer_Analyze(t *testing.T) {
t.Fatalf("could not unmarshal want JSON string: %s", err)
}

// Marshal the expected result to JSON (to normalize)
wantJSON, err := json.Marshal(wantObj)
// Marshal the expected result to JSON with indentation
wantJSON, err := json.MarshalIndent(wantObj, "", " ")
if err != nil {
t.Fatalf("could not marshal want to JSON: %s", err)
}

// Compare the JSON strings
// Compare the JSON strings and show diff if they don't match
if string(gotJSON) != string(wantJSON) {
// Pretty-print both JSON strings for easier comparison
var gotIndented, wantIndented []byte
gotIndented, err = json.MarshalIndent(got, "", " ")
if err != nil {
t.Fatalf("could not marshal got to indented JSON: %s", err)
}
wantIndented, err = json.MarshalIndent(wantObj, "", " ")
if err != nil {
t.Fatalf("could not marshal want to indented JSON: %s", err)
}
t.Errorf("Analyzer.Analyze() = %s, want %s", gotIndented, wantIndented)
diff := cmp.Diff(string(wantJSON), string(gotJSON))
t.Errorf("Analyzer.Analyze() mismatch (-want +got):\n%s", diff)
}
})
}
Expand Down
Loading