Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
mcpproxy-go/web/web_test.go at main · smart-mcp-proxy/mcpproxy-go · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
See all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
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 }}
smart-mcp-proxy
mcpproxy-go
Repository navigation
Code
Issues
22
(22)
Pull requests
21
(21)
Discussions
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
main
Breadcrumbs
mcpproxy-go
/
web
/
web_test.go
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
126 lines (111 loc) · 4.49 KB
main
Breadcrumbs
mcpproxy-go
/
web
/
web_test.go
Copy path
Top
File metadata and controls
Code
Blame
126 lines (111 loc) · 4.49 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
package
web
import
(
"net/http/httptest"
"strings"
"sync/atomic"
"testing"
"go.uber.org/zap"
)
// serveWeb issues a GET against the handler (paths arrive with the /ui prefix
// already stripped, exactly as in production).
func
serveWeb
(
t
*
testing.
T
,
onIndexServe
func
(),
path
string
)
*
httptest.
ResponseRecorder
{
t
.
Helper
()
h
:=
NewHandlerWithIndexCallback
(
zap
.
NewNop
().
Sugar
(),
onIndexServe
)
rec
:=
httptest
.
NewRecorder
()
req
:=
httptest
.
NewRequest
(
"GET"
,
path
,
nil
)
h
.
ServeHTTP
(
rec
,
req
)
return
rec
}
// TestIndexServeCallback_CountsIndexNotAssets asserts FR-006: serving the UI
// entrypoint (index document) fires the callback; asset requests do not, even
// when a missing asset falls back to the index document body.
func
TestIndexServeCallback_CountsIndexNotAssets
(
t
*
testing.
T
) {
var
count
atomic.
Int64
cb
:=
func
() {
count
.
Add
(
1
) }
// Root → index document: counts.
rec
:=
serveWeb
(
t
,
cb
,
"/"
)
if
rec
.
Code
!=
200
{
t
.
Fatalf
(
"expected 200 for /, got %d"
,
rec
.
Code
)
}
if
got
:=
count
.
Load
();
got
!=
1
{
t
.
Fatalf
(
"expected 1 index serve after /, got %d"
,
got
)
}
// Explicit index.html: counts.
serveWeb
(
t
,
cb
,
"/index.html"
)
if
got
:=
count
.
Load
();
got
!=
2
{
t
.
Fatalf
(
"expected 2 index serves after /index.html, got %d"
,
got
)
}
// SPA client-side route (no extension) → index fallback: counts. A user
// deep-linking into the UI opened it.
serveWeb
(
t
,
cb
,
"/servers"
)
if
got
:=
count
.
Load
();
got
!=
3
{
t
.
Fatalf
(
"expected 3 index serves after SPA route, got %d"
,
got
)
}
// Asset requests must never count — neither present assets nor missing
// ones that fall back to the index body (stale hashed bundles after an
// upgrade, favicons, source maps).
for
_
,
p
:=
range
[]
string
{
"/assets/app-abc123.js"
,
"/assets/style.css"
,
"/favicon.ico"
,
"/logo.png"
} {
serveWeb
(
t
,
cb
,
p
)
}
if
got
:=
count
.
Load
();
got
!=
3
{
t
.
Fatalf
(
"expected asset requests uncounted (still 3), got %d"
,
got
)
}
}
// TestIndexServeCallback_NilCallbackSafe asserts the handler works without a
// callback (and via the legacy constructor).
func
TestIndexServeCallback_NilCallbackSafe
(
t
*
testing.
T
) {
rec
:=
serveWeb
(
t
,
nil
,
"/"
)
if
rec
.
Code
!=
200
{
t
.
Fatalf
(
"expected 200 with nil callback, got %d"
,
rec
.
Code
)
}
h
:=
NewHandler
(
zap
.
NewNop
().
Sugar
())
rec2
:=
httptest
.
NewRecorder
()
h
.
ServeHTTP
(
rec2
,
httptest
.
NewRequest
(
"GET"
,
"/"
,
nil
))
if
rec2
.
Code
!=
200
{
t
.
Fatalf
(
"expected 200 via NewHandler, got %d"
,
rec2
.
Code
)
}
}
// TestServerEditionHint_OnlyIndexes verifies that the non-secret edition hint
// is injected into every served SPA document (including deep links), while
// asset responses and the index-open telemetry callback retain their existing
// behavior.
func
TestServerEditionHint_OnlyIndexes
(
t
*
testing.
T
) {
var
count
atomic.
Int64
h
:=
NewHandlerWithOptions
(
zap
.
NewNop
().
Sugar
(),
HandlerOptions
{
ServerEditionEnabled
:
true
,
OnIndexServe
:
func
() {
count
.
Add
(
1
) },
})
for
_
,
requestPath
:=
range
[]
string
{
"/"
,
"/servers"
} {
rec
:=
httptest
.
NewRecorder
()
h
.
ServeHTTP
(
rec
,
httptest
.
NewRequest
(
"GET"
,
requestPath
,
nil
))
if
rec
.
Code
!=
200
{
t
.
Fatalf
(
"expected 200 for %s, got %d"
,
requestPath
,
rec
.
Code
)
}
if
got
:=
rec
.
Body
.
String
();
!
strings
.
Contains
(
got
,
`name="mcpproxy-server-edition" content="true"`
) {
t
.
Fatalf
(
"expected server-edition marker in %s response, got %q"
,
requestPath
,
got
)
}
if
got
:=
rec
.
Body
.
String
();
strings
.
Count
(
got
,
"mcpproxy-server-edition"
)
!=
1
||
!
strings
.
Contains
(
got
,
"mcpproxy-server-edition
\"
content=
\"
true
\"
>
\n
</head>"
) {
t
.
Fatalf
(
"expected exactly one marker inside a complete head in %s response, got %q"
,
requestPath
,
got
)
}
}
if
got
:=
count
.
Load
();
got
!=
2
{
t
.
Fatalf
(
"expected 2 index serves, got %d"
,
got
)
}
asset
:=
httptest
.
NewRecorder
()
h
.
ServeHTTP
(
asset
,
httptest
.
NewRequest
(
"GET"
,
"/assets/app-abc123.js"
,
nil
))
if
got
:=
asset
.
Body
.
String
();
strings
.
Contains
(
got
,
"mcpproxy-server-edition"
) {
t
.
Fatal
(
"asset fallback must not be rewritten with the server-edition marker"
)
}
if
got
:=
count
.
Load
();
got
!=
2
{
t
.
Fatalf
(
"expected asset request not to count as an index serve, got %d"
,
got
)
}
}
func
TestServerEditionHint_FalseDoesNotLeakConfiguration
(
t
*
testing.
T
) {
h
:=
NewHandlerWithOptions
(
zap
.
NewNop
().
Sugar
(),
HandlerOptions
{
ServerEditionEnabled
:
false
})
rec
:=
httptest
.
NewRecorder
()
h
.
ServeHTTP
(
rec
,
httptest
.
NewRequest
(
"GET"
,
"/"
,
nil
))
body
:=
rec
.
Body
.
String
()
if
!
strings
.
Contains
(
body
,
`name="mcpproxy-server-edition" content="false"`
) {
t
.
Fatalf
(
"expected explicit personal-edition marker, got %q"
,
body
)
}
}
You can’t perform that action at this time.