Files
traefik-llmgateway/readme_anonymous_example_test.go

41 lines
1.2 KiB
Go

package traefikllmgateway
import (
"net/http"
"net/http/httptest"
"testing"
)
// The values mirror the README "Anonymous access" example.
func TestReadmeAnonymousExample_DeniesTargets(t *testing.T) {
cfg := &Config{
Providers: map[string]*ProviderConfig{"openai": {Type: "openai", APIKey: "k"}},
Groups: map[string]*GroupConfig{
"public": {
Providers: []string{"openai"},
Models: []string{"gpt-5-mini"},
MCPServers: []string{"-none-"},
Agents: []string{"-none-"},
PassthroughPaths: []string{"-none-"},
Limits: &LimitsConfig{RequestsPerDay: 5000},
MemberLimits: &LimitsConfig{RequestsPerMinute: 30},
},
},
Users: &UsersConfig{AnonymousGroup: "public"},
}
a, err := newAuthStore(cfg)
if err != nil {
t.Fatal(err)
}
_, grp, ok := a.identify(httptest.NewRequest(http.MethodPost, "/v1/chat/completions", nil))
if !ok {
t.Fatal("anonymous request not identified")
}
if grp.allowsMCP("docs") || grp.allowsAgent("planner") || grp.allowsPassthroughPath("v1/files") {
t.Fatal("README anonymous example allows an MCP server, agent or passthrough path")
}
if !grp.allowsProvider("openai") {
t.Fatal("README anonymous example denies its own provider")
}
}