feat(sense): implement Control API v1 [T-011]
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
package config
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestValidateRejectsNonLoopbackByDefault(t *testing.T) {
|
||||
t.Parallel()
|
||||
@@ -93,3 +96,43 @@ func TestValidateDatabaseDriver(t *testing.T) {
|
||||
t.Fatal("unknown database driver must be rejected")
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateControlAPIRequiresPostgresAndExternalSecurityFiles(t *testing.T) {
|
||||
cfg := Config{
|
||||
HTTPAddress: "127.0.0.1:8080", DatabaseDriver: "sqlite", DatabaseDSN: "file:test.db",
|
||||
MediaMTXURL: "http://127.0.0.1:9997", ReconcileInterval: 1, ProbeInterval: 1,
|
||||
ControlAPIEnabled: true, ControlAuthMode: "static-sha256",
|
||||
ControlAuthFile: filepath.Join(t.TempDir(), "sense-auth.json"),
|
||||
ControlCursorKeyFile: filepath.Join(t.TempDir(), "sense-cursor.key"),
|
||||
}
|
||||
if err := cfg.Validate(); err == nil {
|
||||
t.Fatal("Control API was accepted on SQLite")
|
||||
}
|
||||
cfg.DatabaseDriver = "postgres"
|
||||
cfg.DatabaseDSN = "postgres://sense-runtime@127.0.0.1/yovision?sslmode=disable"
|
||||
if err := cfg.Validate(); err != nil {
|
||||
t.Fatalf("valid Control API configuration failed: %v", err)
|
||||
}
|
||||
cfg.ControlAuthFile = "relative-auth.json"
|
||||
if err := cfg.Validate(); err == nil {
|
||||
t.Fatal("repository-relative authentication file was accepted")
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateControlAPINonLoopbackNeedsSeparateRiskAcceptance(t *testing.T) {
|
||||
cfg := Config{
|
||||
HTTPAddress: "0.0.0.0:8080", AllowNonLoopback: true,
|
||||
DatabaseDriver: "postgres", DatabaseDSN: "postgres://sense-runtime@127.0.0.1/yovision?sslmode=disable",
|
||||
MediaMTXURL: "http://127.0.0.1:9997", ReconcileInterval: 1, ProbeInterval: 1,
|
||||
ControlAPIEnabled: true, ControlAuthMode: "static-sha256",
|
||||
ControlAuthFile: filepath.Join(t.TempDir(), "sense-auth.json"),
|
||||
ControlCursorKeyFile: filepath.Join(t.TempDir(), "sense-cursor.key"),
|
||||
}
|
||||
if err := cfg.Validate(); err == nil {
|
||||
t.Fatal("non-loopback plaintext Control API was accepted without explicit risk acceptance")
|
||||
}
|
||||
cfg.ControlAllowInsecureHTTP = true
|
||||
if err := cfg.Validate(); err != nil {
|
||||
t.Fatalf("explicit non-loopback Control API risk acceptance failed: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user