87765bfa63
gates / gates (push) Successful in 3m21s
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0159rPz1ZhFKsS53msqPYxtS
46 lines
1.6 KiB
Go
46 lines
1.6 KiB
Go
package notify
|
|
|
|
import (
|
|
"encoding/json"
|
|
"io"
|
|
"log"
|
|
"net/http"
|
|
"os"
|
|
"testing"
|
|
)
|
|
|
|
type captureRT struct{ bodies []map[string]any }
|
|
|
|
func (c *captureRT) RoundTrip(r *http.Request) (*http.Response, error) {
|
|
b, _ := io.ReadAll(r.Body)
|
|
var m map[string]any
|
|
_ = json.Unmarshal(b, &m)
|
|
c.bodies = append(c.bodies, m)
|
|
return &http.Response{StatusCode: 200, Body: io.NopCloser(nil), Header: http.Header{}}, nil
|
|
}
|
|
|
|
// `09` §3 decision 174: a household mail carries Reply-To = the operator's address (it is sent from monitoring@, and the
|
|
// kernel notice says "reply to this e-mail"); a mail to the operator carries none.
|
|
// COMPANION RED-PROOF (observed): drop the reply_to line in sendEmail → "household mail has no reply_to".
|
|
func TestReplyTo_HouseholdMailRepliesReachTheOperator(t *testing.T) {
|
|
d := NewDispatcher(nil, "k", "monitoring@felhom.eu", "admin@felhom.eu", true, log.New(os.Stderr, "", 0))
|
|
c := &captureRT{}
|
|
d.httpClient = &http.Client{Transport: c}
|
|
if err := d.sendEmail("household@example.com", "s", "b", nil); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := d.sendEmail("admin@felhom.eu", "s", "b", nil); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got := c.bodies[0]["reply_to"]; got != "admin@felhom.eu" {
|
|
t.Fatalf("household mail has no reply_to to the operator: %v", c.bodies[0])
|
|
}
|
|
if _, ok := c.bodies[1]["reply_to"]; ok {
|
|
t.Fatalf("a mail to the operator must carry no reply_to: %v", c.bodies[1])
|
|
}
|
|
none := NewDispatcher(nil, "k", "monitoring@felhom.eu", "", true, log.New(os.Stderr, "", 0))
|
|
if none.replyToFor("x@y") != "" {
|
|
t.Fatal("no operator address → no reply_to")
|
|
}
|
|
}
|