Files
mathiasandClaude Opus 4.8 4c1f36f9eb
CD / Lint / Test / Vet (push) Successful in 7s
CD / Build & Import (push) Successful in 23s
CD / Deploy via GitOps (push) Has been skipped
chore(rename): module gitea.d-ma.be → git.d-ma.be/mathias/gitea-mcp (#39)
Gitea host renamed (infra ADR-0004); the mcp-chassis dep already migrated
(3329ff3), so the sequencing gate is clear. `go mod edit -module` + bulk import
rewrite across all .go files. gitea-mcp is a server binary (not an imported
library), so no downstream consumers break. build + task check green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-03 22:48:26 +02:00

46 lines
1.1 KiB
Go

package mcp_test
import (
"net/http"
"net/http/httptest"
"testing"
"git.d-ma.be/mathias/gitea-mcp/internal/mcp"
"github.com/stretchr/testify/assert"
)
func TestOriginAllowlist(t *testing.T) {
allow := []string{"https://claude.ai", "https://api.anthropic.com"}
called := false
h := mcp.OriginAllowlist(allow)(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
called = true
w.WriteHeader(http.StatusOK)
}))
cases := []struct {
name string
origin string
wantCode int
wantCalled bool
}{
{"allowed", "https://claude.ai", 200, true},
{"allowed-2", "https://api.anthropic.com", 200, true},
{"forbidden", "https://evil.example", 403, false},
{"empty allowed (server-side caller)", "", 200, true},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
called = false
req := httptest.NewRequest(http.MethodPost, "/", nil)
if tc.origin != "" {
req.Header.Set("Origin", tc.origin)
}
rr := httptest.NewRecorder()
h.ServeHTTP(rr, req)
assert.Equal(t, tc.wantCode, rr.Code)
assert.Equal(t, tc.wantCalled, called)
})
}
}