Files
archie/cmd/archied/main_test.go
T
sam 4be28e0e48 feat: optional NATS token authentication (archie-core-l1q)
Add token_env to [nats] config, resolved and validated at daemon startup
(fails early if configured but the named env var is unset). Container
workers get NATS_URL/NATS_TOKEN; archie-agent honors both while CLI-supplied
URL still takes precedence. Anonymous auth remains the default for
single-node deployments.

Unblocks archie-core-5zh (promote archie-agent to per-task process).
2026-07-24 07:51:06 +10:00

45 lines
1.2 KiB
Go

package main
import (
"strings"
"testing"
"github.com/samcharles93/archie-core/internal/config"
)
func TestConfiguredNATSToken(t *testing.T) {
t.Run("anonymous when token env is not configured", func(t *testing.T) {
token, err := configuredNATSToken(config.NATSConfig{}, func(string) string {
return ""
})
if err != nil || token != "" {
t.Fatalf("configuredNATSToken() = (%q, %v), want empty token and nil error", token, err)
}
})
t.Run("reads configured environment variable", func(t *testing.T) {
token, err := configuredNATSToken(
config.NATSConfig{TokenEnv: "ARCHIE_NATS_SECRET"},
func(name string) string {
if name == "ARCHIE_NATS_SECRET" {
return "test-nats-token"
}
return ""
},
)
if err != nil || token != "test-nats-token" {
t.Fatalf("configuredNATSToken() = (%q, %v)", token, err)
}
})
t.Run("rejects missing configured credential", func(t *testing.T) {
_, err := configuredNATSToken(
config.NATSConfig{TokenEnv: "ARCHIE_NATS_SECRET"},
func(string) string { return "" },
)
if err == nil || !strings.Contains(err.Error(), "ARCHIE_NATS_SECRET") {
t.Fatalf("configuredNATSToken() error = %v, want missing variable name", err)
}
})
}