54 lines
2.0 KiB
Go
54 lines
2.0 KiB
Go
package main
|
|
|
|
import (
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestConfigurationRequiresDatabaseAndExternalKey(t *testing.T) {
|
|
t.Setenv("BELL_DB_DSN", "")
|
|
t.Setenv("BELL_AUDIT_KEYS_FILE", "")
|
|
if _, err := loadConfiguration(); err == nil {
|
|
t.Fatal("missing Bell database was accepted")
|
|
}
|
|
t.Setenv("BELL_DB_DSN", "postgres://bell@127.0.0.1/yovision")
|
|
t.Setenv("BELL_AUDIT_KEYS_FILE", "relative.json")
|
|
if _, err := loadConfiguration(); err == nil {
|
|
t.Fatal("relative Bell key file was accepted")
|
|
}
|
|
}
|
|
|
|
func TestConfigurationRequiresTLSOutsideLoopback(t *testing.T) {
|
|
t.Setenv("BELL_DB_DSN", "postgres://bell@127.0.0.1/yovision")
|
|
t.Setenv("BELL_AUDIT_KEYS_FILE", filepath.Join(t.TempDir(), "keys.json"))
|
|
t.Setenv("BELL_HTTP_ADDR", "0.0.0.0:8081")
|
|
if _, err := loadConfiguration(); err == nil {
|
|
t.Fatal("remote plaintext Bell bind was accepted")
|
|
}
|
|
t.Setenv("BELL_TLS_CERT_FILE", filepath.Join(t.TempDir(), "server.crt"))
|
|
t.Setenv("BELL_TLS_KEY_FILE", filepath.Join(t.TempDir(), "server.key"))
|
|
if _, err := loadConfiguration(); err != nil {
|
|
t.Fatalf("remote TLS Bell bind rejected: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestEventIngressIsDisabledByDefaultAndRequiresExternalPolicy(t *testing.T) {
|
|
t.Setenv("BELL_DB_DSN", "postgres://bell@127.0.0.1/yovision")
|
|
t.Setenv("BELL_AUDIT_KEYS_FILE", filepath.Join(t.TempDir(), "audit.json"))
|
|
t.Setenv("BELL_EVENT_INGRESS_ENABLED", "")
|
|
value, err := loadConfiguration()
|
|
if err != nil || value.eventIngressEnabled {
|
|
t.Fatalf("default event ingress configuration: %+v %v", value, err)
|
|
}
|
|
t.Setenv("BELL_EVENT_INGRESS_ENABLED", "true")
|
|
if _, err := loadConfiguration(); err == nil {
|
|
t.Fatal("event ingress without keys and evidence policy was accepted")
|
|
}
|
|
t.Setenv("BELL_EVENT_INGRESS_KEYS_FILE", filepath.Join(t.TempDir(), "event-keys.json"))
|
|
t.Setenv("BELL_EVIDENCE_FORBIDDEN_NAMES_FILE", filepath.Join(t.TempDir(), "names.txt"))
|
|
value, err = loadConfiguration()
|
|
if err != nil || !value.eventIngressEnabled {
|
|
t.Fatalf("valid event ingress configuration rejected: %+v %v", value, err)
|
|
}
|
|
}
|