Enables exposing the supervisor MCP via Tailscale Funnel for claude.ai custom-connector tests. Auth is opt-in: empty SUPERVISOR_MCP_TOKEN preserves the existing unauthenticated behavior for tailnet-internal callers and local dev. When the token is set, every request must carry "Authorization: Bearer <token>" or it is rejected with HTTP 401 and a JSON-RPC -32001 error. Comparison uses crypto/subtle.ConstantTimeCompare; the token value and the supplied header are never logged. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
47 lines
1.4 KiB
Go
47 lines
1.4 KiB
Go
package config_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/mathiasbq/supervisor/internal/config"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestLoadDefaults(t *testing.T) {
|
|
t.Setenv("SUPERVISOR_PORT", "")
|
|
t.Setenv("LITELLM_BASE_URL", "")
|
|
t.Setenv("LITELLM_API_KEY", "")
|
|
t.Setenv("SUPERVISOR_CONFIG_DIR", "")
|
|
t.Setenv("INGEST_BASE_URL", "")
|
|
t.Setenv("SUPERVISOR_SESSIONS_DIR", "")
|
|
t.Setenv("SUPERVISOR_BRAIN_DIR", "")
|
|
t.Setenv("SUPERVISOR_MCP_TOKEN", "")
|
|
|
|
cfg, err := config.Load()
|
|
require.NoError(t, err)
|
|
assert.Equal(t, "3200", cfg.Port)
|
|
assert.Equal(t, "http://iguana:4000", cfg.LiteLLMBaseURL)
|
|
assert.Equal(t, "./config/supervisor", cfg.ConfigDir)
|
|
assert.Equal(t, "http://localhost:3300", cfg.IngestBaseURL)
|
|
assert.Equal(t, "./brain/sessions", cfg.SessionsDir)
|
|
assert.Equal(t, "./brain", cfg.BrainDir)
|
|
assert.Equal(t, "", cfg.MCPAuthToken)
|
|
}
|
|
|
|
func TestLoadFromEnv(t *testing.T) {
|
|
t.Setenv("SUPERVISOR_PORT", "4000")
|
|
t.Setenv("LITELLM_BASE_URL", "http://localhost:4000")
|
|
t.Setenv("LITELLM_API_KEY", "test-key")
|
|
t.Setenv("SUPERVISOR_CONFIG_DIR", "/etc/supervisor")
|
|
t.Setenv("SUPERVISOR_MCP_TOKEN", "secret-token")
|
|
|
|
cfg, err := config.Load()
|
|
require.NoError(t, err)
|
|
assert.Equal(t, "4000", cfg.Port)
|
|
assert.Equal(t, "http://localhost:4000", cfg.LiteLLMBaseURL)
|
|
assert.Equal(t, "test-key", cfg.LiteLLMAPIKey)
|
|
assert.Equal(t, "/etc/supervisor", cfg.ConfigDir)
|
|
assert.Equal(t, "secret-token", cfg.MCPAuthToken)
|
|
}
|