danielmiessler.fabric/internal/cli/setup_server_test.go
Kayvan Sylvan f37c71f9f7 fix: secure storage paths and authenticate REST and Ollama servers
- Reject unsafe cross-platform storage names and traversal attempts.
- Confine symlink targets within configured filesystem storage directories.
- Require API keys for every non-loopback server binding.
- Authenticate Ollama routes and securely forward configured credentials.
- Validate chat pattern, context, and session names early.
- Sanitize client errors to hide internal filesystem details.
- Default REST server binding to loopback port 8080.
- Add regression coverage for traversal, symlinks, and authentication.
2026-09-02 15:59:59 -07:00

38 lines
1.2 KiB
Go

package cli
import (
"testing"
"github.com/danielmiessler/fabric/internal/core"
"github.com/danielmiessler/fabric/internal/plugins/ai"
)
// The --serveOllama path must pass the address, version, and API key
// flags through to ServeOllama unchanged.
func TestHandleSetupAndServerCommands_ServeOllamaWiring(t *testing.T) {
var gotAddress, gotVersion, gotKey string
prev := serveOllama
serveOllama = func(_ *core.PluginRegistry, address, version, apiKey string) error {
gotAddress, gotVersion, gotKey = address, version, apiKey
return nil
}
defer func() { serveOllama = prev }()
registry := &core.PluginRegistry{
VendorManager: ai.NewVendorsManager(),
VendorsAll: ai.NewVendorsManager(),
}
flags := &Flags{ServeOllama: true, ServeAddress: "127.0.0.1:9999", ServeAPIKey: "secret"}
handled, err := handleSetupAndServerCommands(flags, registry, "v-test")
if err != nil {
t.Fatalf("handleSetupAndServerCommands() error = %v", err)
}
if !handled {
t.Fatal("handleSetupAndServerCommands() handled = false, want true")
}
if gotAddress != "127.0.0.1:9999" || gotVersion != "v-test" || gotKey != "secret" {
t.Fatalf("ServeOllama got (%q, %q, %q), want (127.0.0.1:9999, v-test, secret)",
gotAddress, gotVersion, gotKey)
}
}