feat(bell): add alert acknowledgement vertical slice
Harness governance / validate (pull_request) Has been cancelled
Harness governance / validate (pull_request) Has been cancelled
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
@@ -18,6 +19,49 @@ func TestConfigurationRequiresDatabaseAndExternalKey(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAlertsAreDisabledByDefaultAndConsoleRequiresLoopbackContext(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"))
|
||||
value, err := loadConfiguration()
|
||||
if err != nil || value.alertsEnabled || value.alertConsoleEnabled {
|
||||
t.Fatalf("default alert configuration: %+v %v", value, err)
|
||||
}
|
||||
t.Setenv("BELL_ALERTS_ENABLED", "true")
|
||||
if _, err := loadConfiguration(); err == nil {
|
||||
t.Fatal("alerts without an external rule file were accepted")
|
||||
}
|
||||
t.Setenv("BELL_ALERT_RULES_FILE", filepath.Join(t.TempDir(), "rules.json"))
|
||||
t.Setenv("BELL_ALERT_CONSOLE_ENABLED", "true")
|
||||
if _, err := loadConfiguration(); err == nil {
|
||||
t.Fatal("console without external context was accepted")
|
||||
}
|
||||
t.Setenv("BELL_ALERT_CONSOLE_TOKEN_FILE", filepath.Join(t.TempDir(), "token"))
|
||||
t.Setenv("BELL_ALERT_CONSOLE_TENANT_ID", "1")
|
||||
t.Setenv("BELL_ALERT_CONSOLE_SITE_ID", "2")
|
||||
t.Setenv("BELL_ALERT_CONSOLE_ACTOR_REF", "operator:local")
|
||||
t.Setenv("BELL_HTTP_ADDR", "127.0.0.1:8081")
|
||||
value, err = loadConfiguration()
|
||||
if err != nil || !value.alertsEnabled || !value.alertConsoleEnabled {
|
||||
t.Fatalf("valid alert console configuration: %+v %v", value, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadConsoleToken(t *testing.T) {
|
||||
path := filepath.Join(t.TempDir(), "token")
|
||||
if err := os.WriteFile(path, []byte("12345678901234567890123456789012\n"), 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if value, err := loadConsoleToken(path); err != nil || len(value) != 32 {
|
||||
t.Fatalf("valid token: %q %v", value, err)
|
||||
}
|
||||
if err := os.WriteFile(path, []byte("short"), 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := loadConsoleToken(path); err == nil {
|
||||
t.Fatal("short token 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"))
|
||||
|
||||
Reference in New Issue
Block a user