Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
github-mcp-server/pkg/github/secret_scanning_test.go at main · anthropics/github-mcp-server · GitHub
Skip to content
Navigation Menu
Sign in
Products
Platform
GitHub
Repository hosting, code review, and collaboration
Copilot
AI coding agent for tasks, projects and automated work
Build & Ship
Actions
CI/CD and automation
Code Quality
Quality analysis, fixes, and enforcement
Codespaces
Cloud development environments
Secure
Code Security
Vulnerability detection and remediation
Secret Protection
Secret scanning and leak prevention
All Features
Developers
Learn
Documentation
Training
Certifications
Build
Build with Copilot
Customize Copilot
Integrations
Explore
Trending repos
GitHub Sponsors
Events
Changelog
Changelog
Your source for the latest features, improvements, and fixes across GitHub products, all in one place.
Businesses
By Stage
Enterprises
Team
Startups
Nonprofits
By Industry
Healthcare
Financial services
Manufacturing
Government
See all industries
Evaluate GitHub
Why GitHub
Customer Stories
Business insights
Trust Center
Add-ons
GitHub Advanced Security
Enterprise-grade code security
Copilot for business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Resources
Learn & Connect
Documentation
Resource center
Blog
Events & webinars
Community Forum
Customer Stories
Integrations
Support
Customer support
Training
GitHub Status
Company
About
Partners
Changelog
GitHub Universe
GitHub Universe
The event for developers, by developers — talks, workshops, and what’s next for GitHub.
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
anthropics
github-mcp-server
Repository navigation
Code
Pull requests
1
(1)
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
main
Breadcrumbs
github-mcp-server
/
pkg
/
github
/
secret_scanning_test.go
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
243 lines (218 loc) · 7.51 KB
main
Breadcrumbs
github-mcp-server
/
pkg
/
github
/
secret_scanning_test.go
Copy path
Top
File metadata and controls
Code
Blame
243 lines (218 loc) · 7.51 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
package
github
import
(
"context"
"encoding/json"
"net/http"
"testing"
"github.com/github/github-mcp-server/pkg/translations"
"github.com/google/go-github/v69/github"
"github.com/migueleliasweb/go-github-mock/src/mock"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func
Test_GetSecretScanningAlert
(
t
*
testing.
T
) {
mockClient
:=
github
.
NewClient
(
nil
)
tool
,
_
:=
GetSecretScanningAlert
(
stubGetClientFn
(
mockClient
),
translations
.
NullTranslationHelper
)
assert
.
Equal
(
t
,
"get_secret_scanning_alert"
,
tool
.
Name
)
assert
.
NotEmpty
(
t
,
tool
.
Description
)
assert
.
Contains
(
t
,
tool
.
InputSchema
.
Properties
,
"owner"
)
assert
.
Contains
(
t
,
tool
.
InputSchema
.
Properties
,
"repo"
)
assert
.
Contains
(
t
,
tool
.
InputSchema
.
Properties
,
"alertNumber"
)
assert
.
ElementsMatch
(
t
,
tool
.
InputSchema
.
Required
, []
string
{
"owner"
,
"repo"
,
"alertNumber"
})
// Setup mock alert for success case
mockAlert
:=
&
github.
SecretScanningAlert
{
Number
:
github
.
Ptr
(
42
),
State
:
github
.
Ptr
(
"open"
),
HTMLURL
:
github
.
Ptr
(
"https://github.com/owner/private-repo/security/secret-scanning/42"
),
}
tests
:=
[]
struct
{
name
string
mockedClient
*
http.
Client
requestArgs
map
[
string
]
interface
{}
expectError
bool
expectedAlert
*
github.
SecretScanningAlert
expectedErrMsg
string
}{
{
name
:
"successful alert fetch"
,
mockedClient
:
mock
.
NewMockedHTTPClient
(
mock
.
WithRequestMatch
(
mock
.
GetReposSecretScanningAlertsByOwnerByRepoByAlertNumber
,
mockAlert
,
),
),
requestArgs
:
map
[
string
]
interface
{}{
"owner"
:
"owner"
,
"repo"
:
"repo"
,
"alertNumber"
:
float64
(
42
),
},
expectError
:
false
,
expectedAlert
:
mockAlert
,
},
{
name
:
"alert fetch fails"
,
mockedClient
:
mock
.
NewMockedHTTPClient
(
mock
.
WithRequestMatchHandler
(
mock
.
GetReposSecretScanningAlertsByOwnerByRepoByAlertNumber
,
http
.
HandlerFunc
(
func
(
w
http.
ResponseWriter
,
_
*
http.
Request
) {
w
.
WriteHeader
(
http
.
StatusNotFound
)
_
,
_
=
w
.
Write
([]
byte
(
`{"message": "Not Found"}`
))
}),
),
),
requestArgs
:
map
[
string
]
interface
{}{
"owner"
:
"owner"
,
"repo"
:
"repo"
,
"alertNumber"
:
float64
(
9999
),
},
expectError
:
true
,
expectedErrMsg
:
"failed to get alert"
,
},
}
for
_
,
tc
:=
range
tests
{
t
.
Run
(
tc
.
name
,
func
(
t
*
testing.
T
) {
// Setup client with mock
client
:=
github
.
NewClient
(
tc
.
mockedClient
)
_
,
handler
:=
GetSecretScanningAlert
(
stubGetClientFn
(
client
),
translations
.
NullTranslationHelper
)
// Create call request
request
:=
createMCPRequest
(
tc
.
requestArgs
)
// Call handler
result
,
err
:=
handler
(
context
.
Background
(),
request
)
// Verify results
if
tc
.
expectError
{
require
.
Error
(
t
,
err
)
assert
.
Contains
(
t
,
err
.
Error
(),
tc
.
expectedErrMsg
)
return
}
require
.
NoError
(
t
,
err
)
// Parse the result and get the text content if no error
textContent
:=
getTextResult
(
t
,
result
)
// Unmarshal and verify the result
var
returnedAlert
github.
Alert
err
=
json
.
Unmarshal
([]
byte
(
textContent
.
Text
),
&
returnedAlert
)
assert
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
*
tc
.
expectedAlert
.
Number
,
*
returnedAlert
.
Number
)
assert
.
Equal
(
t
,
*
tc
.
expectedAlert
.
State
,
*
returnedAlert
.
State
)
assert
.
Equal
(
t
,
*
tc
.
expectedAlert
.
HTMLURL
,
*
returnedAlert
.
HTMLURL
)
})
}
}
func
Test_ListSecretScanningAlerts
(
t
*
testing.
T
) {
// Verify tool definition once
mockClient
:=
github
.
NewClient
(
nil
)
tool
,
_
:=
ListSecretScanningAlerts
(
stubGetClientFn
(
mockClient
),
translations
.
NullTranslationHelper
)
assert
.
Equal
(
t
,
"list_secret_scanning_alerts"
,
tool
.
Name
)
assert
.
NotEmpty
(
t
,
tool
.
Description
)
assert
.
Contains
(
t
,
tool
.
InputSchema
.
Properties
,
"owner"
)
assert
.
Contains
(
t
,
tool
.
InputSchema
.
Properties
,
"repo"
)
assert
.
Contains
(
t
,
tool
.
InputSchema
.
Properties
,
"state"
)
assert
.
Contains
(
t
,
tool
.
InputSchema
.
Properties
,
"secret_type"
)
assert
.
Contains
(
t
,
tool
.
InputSchema
.
Properties
,
"resolution"
)
assert
.
ElementsMatch
(
t
,
tool
.
InputSchema
.
Required
, []
string
{
"owner"
,
"repo"
})
// Setup mock alerts for success case
resolvedAlert
:=
github.
SecretScanningAlert
{
Number
:
github
.
Ptr
(
2
),
HTMLURL
:
github
.
Ptr
(
"https://github.com/owner/private-repo/security/secret-scanning/2"
),
State
:
github
.
Ptr
(
"resolved"
),
Resolution
:
github
.
Ptr
(
"false_positive"
),
SecretType
:
github
.
Ptr
(
"adafruit_io_key"
),
}
openAlert
:=
github.
SecretScanningAlert
{
Number
:
github
.
Ptr
(
2
),
HTMLURL
:
github
.
Ptr
(
"https://github.com/owner/private-repo/security/secret-scanning/3"
),
State
:
github
.
Ptr
(
"open"
),
Resolution
:
github
.
Ptr
(
"false_positive"
),
SecretType
:
github
.
Ptr
(
"adafruit_io_key"
),
}
tests
:=
[]
struct
{
name
string
mockedClient
*
http.
Client
requestArgs
map
[
string
]
interface
{}
expectError
bool
expectedAlerts
[]
*
github.
SecretScanningAlert
expectedErrMsg
string
}{
{
name
:
"successful resolved alerts listing"
,
mockedClient
:
mock
.
NewMockedHTTPClient
(
mock
.
WithRequestMatchHandler
(
mock
.
GetReposSecretScanningAlertsByOwnerByRepo
,
expectQueryParams
(
t
,
map
[
string
]
string
{
"state"
:
"resolved"
,
}).
andThen
(
mockResponse
(
t
,
http
.
StatusOK
, []
*
github.
SecretScanningAlert
{
&
resolvedAlert
}),
),
),
),
requestArgs
:
map
[
string
]
interface
{}{
"owner"
:
"owner"
,
"repo"
:
"repo"
,
"state"
:
"resolved"
,
},
expectError
:
false
,
expectedAlerts
: []
*
github.
SecretScanningAlert
{
&
resolvedAlert
},
},
{
name
:
"successful alerts listing"
,
mockedClient
:
mock
.
NewMockedHTTPClient
(
mock
.
WithRequestMatchHandler
(
mock
.
GetReposSecretScanningAlertsByOwnerByRepo
,
expectQueryParams
(
t
,
map
[
string
]
string
{}).
andThen
(
mockResponse
(
t
,
http
.
StatusOK
, []
*
github.
SecretScanningAlert
{
&
resolvedAlert
,
&
openAlert
}),
),
),
),
requestArgs
:
map
[
string
]
interface
{}{
"owner"
:
"owner"
,
"repo"
:
"repo"
,
},
expectError
:
false
,
expectedAlerts
: []
*
github.
SecretScanningAlert
{
&
resolvedAlert
,
&
openAlert
},
},
{
name
:
"alerts listing fails"
,
mockedClient
:
mock
.
NewMockedHTTPClient
(
mock
.
WithRequestMatchHandler
(
mock
.
GetReposSecretScanningAlertsByOwnerByRepo
,
http
.
HandlerFunc
(
func
(
w
http.
ResponseWriter
,
_
*
http.
Request
) {
w
.
WriteHeader
(
http
.
StatusUnauthorized
)
_
,
_
=
w
.
Write
([]
byte
(
`{"message": "Unauthorized access"}`
))
}),
),
),
requestArgs
:
map
[
string
]
interface
{}{
"owner"
:
"owner"
,
"repo"
:
"repo"
,
},
expectError
:
true
,
expectedErrMsg
:
"failed to list alerts"
,
},
}
for
_
,
tc
:=
range
tests
{
t
.
Run
(
tc
.
name
,
func
(
t
*
testing.
T
) {
client
:=
github
.
NewClient
(
tc
.
mockedClient
)
_
,
handler
:=
ListSecretScanningAlerts
(
stubGetClientFn
(
client
),
translations
.
NullTranslationHelper
)
request
:=
createMCPRequest
(
tc
.
requestArgs
)
result
,
err
:=
handler
(
context
.
Background
(),
request
)
if
tc
.
expectError
{
require
.
Error
(
t
,
err
)
assert
.
Contains
(
t
,
err
.
Error
(),
tc
.
expectedErrMsg
)
return
}
require
.
NoError
(
t
,
err
)
textContent
:=
getTextResult
(
t
,
result
)
// Unmarshal and verify the result
var
returnedAlerts
[]
*
github.
SecretScanningAlert
err
=
json
.
Unmarshal
([]
byte
(
textContent
.
Text
),
&
returnedAlerts
)
assert
.
NoError
(
t
,
err
)
assert
.
Len
(
t
,
returnedAlerts
,
len
(
tc
.
expectedAlerts
))
for
i
,
alert
:=
range
returnedAlerts
{
assert
.
Equal
(
t
,
*
tc
.
expectedAlerts
[
i
].
Number
,
*
alert
.
Number
)
assert
.
Equal
(
t
,
*
tc
.
expectedAlerts
[
i
].
HTMLURL
,
*
alert
.
HTMLURL
)
assert
.
Equal
(
t
,
*
tc
.
expectedAlerts
[
i
].
State
,
*
alert
.
State
)
assert
.
Equal
(
t
,
*
tc
.
expectedAlerts
[
i
].
Resolution
,
*
alert
.
Resolution
)
assert
.
Equal
(
t
,
*
tc
.
expectedAlerts
[
i
].
SecretType
,
*
alert
.
SecretType
)
}
})
}
}
You can’t perform that action at this time.