@@ -23,8 +23,15 @@ func TestAsanaPersonalAccessToken_FromChunk(t *testing.T) {
23
23
if err != nil {
24
24
t .Fatalf ("could not get test secrets from GCP: %s" , err )
25
25
}
26
- secret := testSecrets .MustGetField ("ASANA_PAT" )
27
- inactiveSecret := testSecrets .MustGetField ("ASANA_PAT_INACTIVE" )
26
+ testNewSecrets , err := common .GetSecret (ctx , "trufflehog-testing" , "detectors6" )
27
+ if err != nil {
28
+ t .Fatalf ("could not get test secrets from GCP: %s" , err )
29
+ }
30
+
31
+ oldFormatSecret := testSecrets .MustGetField ("ASANA_PAT" )
32
+ newFormatSecret := testNewSecrets .MustGetField ("ASANA_PAT_NEW" )
33
+ inactiveOldFormatSecret := testSecrets .MustGetField ("ASANA_PAT_INACTIVE" )
34
+ inactiveNewFormatSecret := testNewSecrets .MustGetField ("ASANA_PAT_NEW_INACTIVE" )
28
35
29
36
type args struct {
30
37
ctx context.Context
@@ -43,7 +50,7 @@ func TestAsanaPersonalAccessToken_FromChunk(t *testing.T) {
43
50
s : Scanner {},
44
51
args : args {
45
52
ctx : context .Background (),
46
- data : []byte (fmt .Sprintf ("You can find a asana secret %s within" , secret )),
53
+ data : []byte (fmt .Sprintf ("You can find a asana secret %s within" , oldFormatSecret )),
47
54
verify : true ,
48
55
},
49
56
want : []detectors.Result {
@@ -71,6 +78,38 @@ func TestAsanaPersonalAccessToken_FromChunk(t *testing.T) {
71
78
wantErr : false ,
72
79
},
73
80
{
81
+ name : "found, verified - new format" ,
82
+ s : Scanner {},
83
+ args : args {
84
+ ctx : context .Background (),
85
+ data : []byte (fmt .Sprintf ("You can find a asana secret %s within" , newFormatSecret )),
86
+ verify : true ,
87
+ },
88
+ want : []detectors.Result {
89
+ {
90
+ DetectorType : detectorspb .DetectorType_AsanaPersonalAccessToken ,
91
+ Verified : true ,
92
+ },
93
+ },
94
+ wantErr : false ,
95
+ },
96
+ {
97
+ name : "found, unverified - new format" ,
98
+ s : Scanner {},
99
+ args : args {
100
+ ctx : context .Background (),
101
+ data : []byte (fmt .Sprintf ("You can find a asana secret %s but unverified" , inactiveNewFormatSecret )),
102
+ verify : true ,
103
+ },
104
+ want : []detectors.Result {
105
+ {
106
+ DetectorType : detectorspb .DetectorType_AsanaPersonalAccessToken ,
107
+ Verified : false ,
108
+ },
109
+ },
110
+ wantErr : false ,
111
+ },
112
+ {
74
113
name : "not found" ,
75
114
s : Scanner {},
76
115
args : args {
@@ -81,25 +120,25 @@ func TestAsanaPersonalAccessToken_FromChunk(t *testing.T) {
81
120
want : nil ,
82
121
wantErr : false ,
83
122
},
84
- }
85
- for _ , tt := range tests {
86
- t .Run (tt .name , func (t * testing.T ) {
87
- s := Scanner {}
88
- got , err := s .FromData (tt .args .ctx , tt .args .verify , tt .args .data )
89
- if (err != nil ) != tt .wantErr {
90
- t .Errorf ("AsanaPersonalAccessToken.FromData() error = %v, wantErr %v" , err , tt .wantErr )
91
- return
92
- }
93
- for i := range got {
94
- if len (got [i ].Raw ) == 0 {
95
- t .Fatalf ("no raw secret present: \n %+v" , got [i ])
123
+ for _ , tt := range tests {
124
+ t .Run (tt .name , func (t * testing.T ) {
125
+ s := Scanner {}
126
+ got , err := s .FromData (tt .args .ctx , tt .args .verify , tt .args .data )
127
+ if (err != nil ) != tt .wantErr {
128
+ t .Errorf ("AsanaPersonalAccessToken.FromData() error = %v, wantErr %v" , err , tt .wantErr )
129
+ return
96
130
}
97
- got [i ].Raw = nil
98
- }
99
- if diff := pretty .Compare (got , tt .want ); diff != "" {
100
- t .Errorf ("AsanaPersonalAccessToken.FromData() %s diff: (-got +want)\n %s" , tt .name , diff )
101
- }
102
- })
131
+ for i := range got {
132
+ if len (got [i ].Raw ) == 0 {
133
+ t .Fatalf ("no raw secret present: \n %+v" , got [i ])
134
+ }
135
+ got [i ].Raw = nil
136
+ }
137
+ if diff := pretty .Compare (got , tt .want ); diff != "" {
138
+ t .Errorf ("AsanaPersonalAccessToken.FromData() %s diff: (-got +want)\n %s" , tt .name , diff )
139
+ }
140
+ })
141
+ }
103
142
}
104
143
}
105
144
0 commit comments