@@ -26,8 +26,8 @@ func Test_GetSecretScanningAlert(t *testing.T) {
26
26
27
27
// Setup mock alert for success case
28
28
mockAlert := & github.SecretScanningAlert {
29
- Number : github .Ptr (42 ),
30
- State : github .Ptr ("open" ),
29
+ Number : github .Ptr (42 ),
30
+ State : github .Ptr ("open" ),
31
31
HTMLURL : github .Ptr ("https://github.com/owner/private-repo/security/secret-scanning/42" ),
32
32
}
33
33
@@ -124,22 +124,22 @@ func Test_ListSecretScanningAlerts(t *testing.T) {
124
124
assert .Contains (t , tool .InputSchema .Properties , "state" )
125
125
assert .Contains (t , tool .InputSchema .Properties , "secret_type" )
126
126
assert .Contains (t , tool .InputSchema .Properties , "resolution" )
127
- assert .Contains (t , tool .InputSchema .Properties , "sort" )
128
- assert .Contains (t , tool .InputSchema .Properties , "direction" )
129
127
assert .ElementsMatch (t , tool .InputSchema .Required , []string {"owner" , "repo" })
130
128
131
129
// Setup mock alerts for success case
132
- mockAlerts := []* github.SecretScanningAlert {
133
- {
134
- Number : github .Ptr (42 ),
135
- State : github .Ptr ("open" ),
136
- HTMLURL : github .Ptr ("https://github.com/owner/repo/security/code-scanning/42" ),
137
- },
138
- {
139
- Number : github .Ptr (43 ),
140
- State : github .Ptr ("fixed" ),
141
- HTMLURL : github .Ptr ("https://github.com/owner/repo/security/code-scanning/43" ),
142
- },
130
+ resolvedAlert := github.SecretScanningAlert {
131
+ Number : github .Ptr (2 ),
132
+ HTMLURL : github .Ptr ("https://github.com/owner/private-repo/security/secret-scanning/2" ),
133
+ State : github .Ptr ("resolved" ),
134
+ Resolution : github .Ptr ("false_positive" ),
135
+ SecretType : github .Ptr ("adafruit_io_key" ),
136
+ }
137
+ openAlert := github.SecretScanningAlert {
138
+ Number : github .Ptr (2 ),
139
+ HTMLURL : github .Ptr ("https://github.com/owner/private-repo/security/secret-scanning/3" ),
140
+ State : github .Ptr ("open" ),
141
+ Resolution : github .Ptr ("false_positive" ),
142
+ SecretType : github .Ptr ("adafruit_io_key" ),
143
143
}
144
144
145
145
tests := []struct {
@@ -151,28 +151,41 @@ func Test_ListSecretScanningAlerts(t *testing.T) {
151
151
expectedErrMsg string
152
152
}{
153
153
{
154
- name : "successful alerts listing" ,
154
+ name : "successful resolved alerts listing" ,
155
155
mockedClient : mock .NewMockedHTTPClient (
156
156
mock .WithRequestMatchHandler (
157
- mock .GetReposSecretScanningAlertsByOwnerByRepoByAlertNumber ,
157
+ mock .GetReposSecretScanningAlertsByOwnerByRepo ,
158
158
expectQueryParams (t , map [string ]string {
159
- "ref" : "main" ,
160
- "state" : "open" ,
161
- "severity" : "high" ,
159
+ "state" : "resolved" ,
162
160
}).andThen (
163
- mockResponse (t , http .StatusOK , mockAlerts ),
161
+ mockResponse (t , http .StatusOK , [] * github. SecretScanningAlert { & resolvedAlert } ),
164
162
),
165
163
),
166
164
),
167
165
requestArgs : map [string ]interface {}{
168
- "owner" : "owner" ,
169
- "repo" : "repo" ,
170
- "ref" : "main" ,
171
- "state" : "open" ,
172
- "severity" : "high" ,
166
+ "owner" : "owner" ,
167
+ "repo" : "repo" ,
168
+ "state" : "resolved" ,
173
169
},
174
170
expectError : false ,
175
- expectedAlerts : mockAlerts ,
171
+ expectedAlerts : []* github.SecretScanningAlert {& resolvedAlert },
172
+ },
173
+ {
174
+ name : "successful alerts listing" ,
175
+ mockedClient : mock .NewMockedHTTPClient (
176
+ mock .WithRequestMatchHandler (
177
+ mock .GetReposSecretScanningAlertsByOwnerByRepo ,
178
+ expectQueryParams (t , map [string ]string {}).andThen (
179
+ mockResponse (t , http .StatusOK , []* github.SecretScanningAlert {& resolvedAlert , & openAlert }),
180
+ ),
181
+ ),
182
+ ),
183
+ requestArgs : map [string ]interface {}{
184
+ "owner" : "owner" ,
185
+ "repo" : "repo" ,
186
+ },
187
+ expectError : false ,
188
+ expectedAlerts : []* github.SecretScanningAlert {& resolvedAlert , & openAlert },
176
189
},
177
190
{
178
191
name : "alerts listing fails" ,
@@ -196,17 +209,13 @@ func Test_ListSecretScanningAlerts(t *testing.T) {
196
209
197
210
for _ , tc := range tests {
198
211
t .Run (tc .name , func (t * testing.T ) {
199
- // Setup client with mock
200
212
client := github .NewClient (tc .mockedClient )
201
213
_ , handler := ListSecretScanningAlerts (stubGetClientFn (client ), translations .NullTranslationHelper )
202
214
203
- // Create call request
204
215
request := createMCPRequest (tc .requestArgs )
205
216
206
- // Call handler
207
217
result , err := handler (context .Background (), request )
208
218
209
- // Verify results
210
219
if tc .expectError {
211
220
require .Error (t , err )
212
221
assert .Contains (t , err .Error (), tc .expectedErrMsg )
@@ -215,18 +224,19 @@ func Test_ListSecretScanningAlerts(t *testing.T) {
215
224
216
225
require .NoError (t , err )
217
226
218
- // Parse the result and get the text content if no error
219
227
textContent := getTextResult (t , result )
220
228
221
229
// Unmarshal and verify the result
222
- var returnedAlerts []* github.Alert
230
+ var returnedAlerts []* github.SecretScanningAlert
223
231
err = json .Unmarshal ([]byte (textContent .Text ), & returnedAlerts )
224
232
assert .NoError (t , err )
225
233
assert .Len (t , returnedAlerts , len (tc .expectedAlerts ))
226
234
for i , alert := range returnedAlerts {
227
235
assert .Equal (t , * tc .expectedAlerts [i ].Number , * alert .Number )
228
- assert .Equal (t , * tc .expectedAlerts [i ].State , * alert .State )
229
236
assert .Equal (t , * tc .expectedAlerts [i ].HTMLURL , * alert .HTMLURL )
237
+ assert .Equal (t , * tc .expectedAlerts [i ].State , * alert .State )
238
+ assert .Equal (t , * tc .expectedAlerts [i ].Resolution , * alert .Resolution )
239
+ assert .Equal (t , * tc .expectedAlerts [i ].SecretType , * alert .SecretType )
230
240
}
231
241
})
232
242
}
0 commit comments