81 lines
3.2 KiB
Go
81 lines
3.2 KiB
Go
package main
|
|
|
|
// mesh-mail send (novox/hq ADR 0436 §7, issue 1195): refuses to start naming what is missing, never
|
|
// attempting to reach a bus when it cannot even read its own account or the accounts setting.
|
|
|
|
import (
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
// 1195/AC1: given `mesh-mail send` with MESH_MAIL_SECRETS holding broker-send.secret in the controller's
|
|
// form, when it starts, then it reads the account and the accounts file, and refuses to start naming what
|
|
// is missing when either is absent.
|
|
func TestSendRefusesToStartNamingWhatIsMissing(t *testing.T) {
|
|
validAccount := `{"url": "nats://127.0.0.1:4222", "node": "g14", "module": "mesh-mail", ` +
|
|
`"user": "g14.mesh-mail.send", "password": "pw"}`
|
|
|
|
t.Run("no secrets directory", func(t *testing.T) {
|
|
dir := t.TempDir()
|
|
env := Env{Accounts: filepath.Join(dir, "accounts.json")}
|
|
writeFile(t, env.Accounts, stageOne)
|
|
if code := send(env); code == 0 {
|
|
t.Fatal("send started with no secrets directory at all")
|
|
}
|
|
})
|
|
|
|
t.Run("no accounts file", func(t *testing.T) {
|
|
dir := t.TempDir()
|
|
env := Env{Accounts: filepath.Join(dir, "accounts.json"), Secrets: dir}
|
|
writeFile(t, filepath.Join(dir, "broker-send.secret"), validAccount)
|
|
if code := send(env); code == 0 {
|
|
t.Fatal("send started with no accounts setting")
|
|
}
|
|
})
|
|
|
|
t.Run("accounts file is not the module's", func(t *testing.T) {
|
|
dir := t.TempDir()
|
|
env := Env{Accounts: filepath.Join(dir, "accounts.json"), Secrets: dir}
|
|
writeFile(t, env.Accounts, `not json`)
|
|
writeFile(t, filepath.Join(dir, "broker-send.secret"), validAccount)
|
|
if code := send(env); code == 0 {
|
|
t.Fatal("send started with an accounts setting it cannot read")
|
|
}
|
|
})
|
|
|
|
t.Run("no own account delivered yet", func(t *testing.T) {
|
|
dir := t.TempDir()
|
|
env := Env{Accounts: filepath.Join(dir, "accounts.json"), Secrets: dir}
|
|
writeFile(t, env.Accounts, stageOne)
|
|
// broker-send.secret is not written at all.
|
|
if code := send(env); code == 0 {
|
|
t.Fatal("send started with no own account delivered")
|
|
}
|
|
})
|
|
|
|
t.Run("own account missing a field", func(t *testing.T) {
|
|
dir := t.TempDir()
|
|
env := Env{Accounts: filepath.Join(dir, "accounts.json"), Secrets: dir}
|
|
writeFile(t, env.Accounts, stageOne)
|
|
writeFile(t, filepath.Join(dir, "broker-send.secret"), `{"url": "nats://127.0.0.1:4222", "node": "g14", "module": "mesh-mail"}`)
|
|
code := send(env)
|
|
if code == 0 {
|
|
t.Fatal("send started with an own account missing its user and password")
|
|
}
|
|
})
|
|
}
|
|
|
|
// The account file's path is exactly what secret.Path gives for the member "broker-<process id>", inside
|
|
// the directory MESH_MAIL_SECRETS already names — no secret of its own needs declaring in the manifest for
|
|
// it (novox/hq ADR 0436 §2: the controller delivers it automatically for every process with a bus).
|
|
func TestSendProcessIDNamesItsOwnAccountFile(t *testing.T) {
|
|
if SendProcessID != "send" {
|
|
t.Fatalf("SendProcessID: %q; module.json's resource id is \"send\"", SendProcessID)
|
|
}
|
|
// mesh-controller's own StreamBusName: "mail-sends" capitalised, its hyphen an underscore (review round
|
|
// 1, finding 7 — confirmed against cmd/mesh-controller/process_live_test.go's own fixture).
|
|
if MailSendsStream != "MAIL_SENDS" {
|
|
t.Fatalf("MailSendsStream: %q, want MAIL_SENDS", MailSendsStream)
|
|
}
|
|
}
|