Files
gitea-mcp/internal/config/config_test.go
Mathias Bergqvist 923689afa5 feat: replace static API token with per-request Gitea PAT pass-through
Callers now supply their own Gitea PAT as a Bearer token; the server validates
it against GET /api/v1/user and threads it through context to all downstream
Gitea API calls. GITEA_API_TOKEN env var and the GiteaAPIToken config field are
removed.
2026-05-07 21:04:47 +02:00

44 lines
1.3 KiB
Go

package config_test
import (
"testing"
"gitea.d-ma.be/mathias/gitea-mcp/internal/config"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestLoadDefaults(t *testing.T) {
t.Setenv("GITEA_BASE_URL", "")
t.Setenv("GITEA_MCP_ALLOWED_OWNERS", "")
t.Setenv("GITEA_MCP_ORIGIN_ALLOWLIST", "")
t.Setenv("GITEA_MCP_PORT", "")
cfg, err := config.Load()
require.NoError(t, err)
assert.Equal(t, "8080", cfg.Port)
assert.Equal(t, []string{"mathias"}, cfg.AllowedOwners)
}
func TestLoadFromEnv(t *testing.T) {
t.Setenv("GITEA_BASE_URL", "https://gitea.d-ma.be")
t.Setenv("GITEA_MCP_ALLOWED_OWNERS", "mathias,acme")
t.Setenv("GITEA_MCP_ORIGIN_ALLOWLIST", "https://claude.ai,https://api.anthropic.com")
t.Setenv("GITEA_MCP_PORT", "9000")
cfg, err := config.Load()
require.NoError(t, err)
assert.Equal(t, "https://gitea.d-ma.be", cfg.GiteaBaseURL)
assert.Equal(t, []string{"mathias", "acme"}, cfg.AllowedOwners)
assert.Equal(t, []string{"https://claude.ai", "https://api.anthropic.com"}, cfg.OriginAllowlist)
assert.Equal(t, "9000", cfg.Port)
}
func TestLoadCSVTrimsWhitespaceAndDropsEmpty(t *testing.T) {
t.Setenv("GITEA_MCP_ALLOWED_OWNERS", " mathias , , acme ")
cfg, err := config.Load()
require.NoError(t, err)
assert.Equal(t, []string{"mathias", "acme"}, cfg.AllowedOwners)
}