34 lines
1.1 KiB
Go
34 lines
1.1 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)
|
|
}
|
|
}
|