Skip to content

Commit d1feae1

Browse files
Updated OpenAI Analyzer (#4203)
* Updated OpenAI Analyzer * fixed test
1 parent ce3f2ae commit d1feae1

File tree

6 files changed

+516
-50
lines changed

6 files changed

+516
-50
lines changed

pkg/analyzer/analyzers/openai/openai.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ func (a Analyzer) Analyze(_ context.Context, credInfo map[string]string) (*analy
3838

3939
func secretInfoToAnalyzerResult(info *AnalyzerJSON) *analyzers.AnalyzerResult {
4040
result := analyzers.AnalyzerResult{
41+
AnalyzerType: analyzers.AnalyzerTypeOpenAI,
4142
Metadata: map[string]any{
4243
"user": info.me.Name,
4344
"email": info.me.Email,

pkg/analyzer/analyzers/openai/openai_test.go

Lines changed: 8 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package openai
22

33
import (
4+
_ "embed"
45
"encoding/json"
56
"testing"
67
"time"
@@ -11,6 +12,9 @@ import (
1112
"github.com/trufflesecurity/trufflehog/v3/pkg/context"
1213
)
1314

15+
//go:embed result_output.json
16+
var expectedOutput []byte
17+
1418
func TestAnalyzer_Analyze(t *testing.T) {
1519
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
1620
defer cancel()
@@ -22,59 +26,13 @@ func TestAnalyzer_Analyze(t *testing.T) {
2226
tests := []struct {
2327
name string
2428
key string
25-
want string // JSON string
29+
want []byte
2630
wantErr bool
2731
}{
2832
{
29-
name: "valid OpenAI key",
30-
key: testSecrets.MustGetField("OPENAI_VERIFIED"),
31-
want: `{
32-
"AnalyzerType": 0,
33-
"Bindings": [
34-
{
35-
"Resource": {
36-
"Name": "Truffle Security Co",
37-
"FullyQualifiedName": "org-n56tuYdSewh06PEGJZC0xWHf",
38-
"Type": "organization",
39-
"Metadata": {
40-
"description": "Personal org for [email protected]",
41-
"user": "truffle-security-co"
42-
},
43-
"Parent": null
44-
},
45-
"Permission": {
46-
"Value": "full_access",
47-
"AccessLevel": "",
48-
"Parent": null
49-
}
50-
},
51-
{
52-
"Resource": {
53-
"Name": "Personal",
54-
"FullyQualifiedName": "org-S2T2qOGM1KofMLUxb9rt7eV0",
55-
"Type": "organization",
56-
"Metadata": {
57-
"description": "Personal org for [email protected]",
58-
"user": "user-ohfap0ky8lkatw97iskuhghv"
59-
},
60-
"Parent": null
61-
},
62-
"Permission": {
63-
"Value": "full_access",
64-
"AccessLevel": "",
65-
"Parent": null
66-
}
67-
}
68-
],
69-
"UnboundedResources": null,
70-
"Metadata": {
71-
"email": "[email protected]",
72-
"is_admin": "true",
73-
"is_restricted": "false",
74-
"mfa": "true",
75-
"user": "Dustin Decker"
76-
}
77-
}`,
33+
name: "valid OpenAI key",
34+
key: testSecrets.MustGetField("OPENAI_VERIFIED"),
35+
want: expectedOutput,
7836
wantErr: false,
7937
},
8038
}

pkg/analyzer/analyzers/openai/permissions.go

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/analyzer/analyzers/openai/permissions.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,7 @@ permissions:
99
- fine_tuning:write
1010
- files:read
1111
- files:write
12+
- evals:read
13+
- evals:write
14+
- responses:read
15+
- responses:write

0 commit comments

Comments
 (0)