mirror of
https://gitea.com/gitea/gitea-mcp.git
synced 2026-08-03 15:49:23 +02:00
0dc9868e2e
Review follow-ups on the SDK migration. An "arguments": null is what clients send for parameterless tools like get_me, and what mcp-go accepted by returning a nil map. The new adapter rejected it with InvalidParams, which broke those calls outright. The /mcp endpoint took unlimited request bodies and never expired idle sessions, so a peer that goes away without DELETE kept its session for the process lifetime. Both are reachable before any token check, so neither can stay unbounded; the body cap sits above the SDK default to leave room for the base64 content create_or_update_file accepts. Required() smuggled a bool through the property schema map and deleted it again, colliding with the JSON Schema keyword of the same name. It now sets a field on Property, so an object property can carry its own required list. The tool contract fixture cost a manual regeneration step and four hand-maintained counts on every tool change, and a snapshot freezes defects rather than reporting them. Property assertions cover the same surface and reject a duplicate tool name, a readOnlyHint that disagrees with the register call, and a default that contradicts its own type or enum. Co-Authored-By: Claude (Opus 5) <noreply@anthropic.com>
104 lines
2.1 KiB
Go
104 lines
2.1 KiB
Go
package operation
|
|
|
|
import "testing"
|
|
|
|
func TestParseAuthToken(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
header string
|
|
wantToken string
|
|
wantOK bool
|
|
}{
|
|
{
|
|
name: "valid Bearer token",
|
|
header: "Bearer validtoken",
|
|
wantToken: "validtoken",
|
|
wantOK: true,
|
|
},
|
|
{
|
|
name: "lowercase bearer",
|
|
header: "bearer lowercase",
|
|
wantToken: "lowercase",
|
|
wantOK: true,
|
|
},
|
|
{
|
|
name: "uppercase BEARER",
|
|
header: "BEARER uppercase",
|
|
wantToken: "uppercase",
|
|
wantOK: true,
|
|
},
|
|
{
|
|
name: "token with spaces trimmed",
|
|
header: "Bearer spacedToken ",
|
|
wantToken: "spacedToken",
|
|
wantOK: true,
|
|
},
|
|
{
|
|
name: "bearer with no token",
|
|
header: "Bearer ",
|
|
wantToken: "",
|
|
wantOK: false,
|
|
},
|
|
{
|
|
name: "bearer with only spaces",
|
|
header: "Bearer ",
|
|
wantToken: "",
|
|
wantOK: false,
|
|
},
|
|
{
|
|
name: "missing space after Bearer",
|
|
header: "Bearertoken",
|
|
wantToken: "",
|
|
wantOK: false,
|
|
},
|
|
{
|
|
name: "Gitea token format",
|
|
header: "token giteaapitoken",
|
|
wantToken: "giteaapitoken",
|
|
wantOK: true,
|
|
},
|
|
{
|
|
name: "Gitea Token format capitalized",
|
|
header: "Token giteaapitoken",
|
|
wantToken: "giteaapitoken",
|
|
wantOK: true,
|
|
},
|
|
{
|
|
name: "token with no value",
|
|
header: "token ",
|
|
wantToken: "",
|
|
wantOK: false,
|
|
},
|
|
{
|
|
name: "different auth type",
|
|
header: "Basic dXNlcjpwYXNz",
|
|
wantToken: "",
|
|
wantOK: false,
|
|
},
|
|
{
|
|
name: "empty header",
|
|
header: "",
|
|
wantToken: "",
|
|
wantOK: false,
|
|
},
|
|
{
|
|
name: "bearer token with internal spaces",
|
|
header: "Bearer token with spaces",
|
|
wantToken: "token with spaces",
|
|
wantOK: true,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
gotToken, gotOK := parseAuthToken(tt.header)
|
|
if gotToken != tt.wantToken {
|
|
t.Errorf("parseAuthToken() token = %q, want %q", gotToken, tt.wantToken)
|
|
}
|
|
if gotOK != tt.wantOK {
|
|
t.Errorf("parseAuthToken() ok = %v, want %v", gotOK, tt.wantOK)
|
|
}
|
|
})
|
|
}
|
|
}
|