Merge remote-tracking branch 'origin/main' into alias-publish-precert-1293
2 files changed,
+48
−0
internal/console/sesevents.go+17 −0internal/console/sesevents_test.go+31 −0
diff --git a/internal/console/sesevents.go b/internal/console/sesevents.go| index 0f086fa46..b81294d64 100644 |
| --- a/internal/console/sesevents.go |
| +++ b/internal/console/sesevents.go |
| @@ -125,6 +125,11 @@ import ( |
| // unauthenticated endpoint is memory exhaustion anyone can trigger. |
| const sesEventMaxBody = 256 << 10 |
| +// sesTopicValidated opens the plain-text message SES publishes to a topic |
| +// when an event destination is created on it: "Successfully validated SNS |
| +// topic for Amazon SES event publishing." |
| +const sesTopicValidated = "Successfully validated SNS topic for Amazon SES" |
| + |
| // sesCertMaxBody bounds the signing certificate this door fetches (and the |
| // SubscribeURL response body it discards). AWS's SNS certificates are a few |
| // KB, even bundled with an intermediate; anything vastly larger than that |
| @@ -394,6 +399,18 @@ func (s *Server) handleSESEvents(w http.ResponseWriter, r *http.Request) { |
| } |
| w.WriteHeader(http.StatusOK) |
| case "Notification": |
| + if strings.HasPrefix(strings.TrimSpace(env.Message), sesTopicValidated) { |
| + // SES's plain-text test message, sent each time an event |
| + // destination is created on this topic — every console start |
| + // re-creates its own (EnsureDomain; SES answers "already exists" |
| + // and sends it anyway). Not an event: nothing to count. Its |
| + // arrival is worth one line, as it proves SES -> SNS -> this |
| + // console works. Signed by SNS like everything else here, so |
| + // the line is bounded by AWS, not by strangers. |
| + log.Printf("console: ses events: SES test message received (message %s); the topic reaches this console", env.MessageID) |
| + w.WriteHeader(http.StatusOK) |
| + return |
| + } |
| ev, err := mail.ParseEvent([]byte(env.Message)) |
| if err != nil { |
| // Logged and dropped, not retried: an unparseable or |
diff --git a/internal/console/sesevents_test.go b/internal/console/sesevents_test.go| index 3e9394a5a..db8657956 100644 |
| --- a/internal/console/sesevents_test.go |
| +++ b/internal/console/sesevents_test.go |
| @@ -321,6 +321,37 @@ func TestSESEventsAnswers200ForUnknownTypes(t *testing.T) { |
| } |
| } |
| +// SES publishes a plain-text test message to the topic each time an event |
| +// destination is created, and the console re-creates its own on every start |
| +// (the console mailer's EnsureDomain; SES answers "already exists" and sends |
| +// the message anyway). It is not an SES event and must not read as a fault: |
| +// it used to log "parse notification: ... invalid character 'S'" on every |
| +// start. It is a 200, counts nothing, and logs one line saying the topic |
| +// reaches this console. |
| +func TestSESEventsTakesTheTopicValidationMessageQuietly(t *testing.T) { |
| + fx := newConsoleFixture(t) |
| + fx.srv.cfg.MailDeployment.SNSTopicARN = "arn:aws:sns:eu-west-1:1:carlos-mail" |
| + fx.srv.snsVerify = func(_ snsEnvelope) error { return nil } |
| + var buf bytes.Buffer |
| + log.SetOutput(&buf) |
| + t.Cleanup(func() { log.SetOutput(os.Stderr) }) |
| + |
| + resp := sesPost(t, fx, `{"Type":"Notification","MessageId":"m-1","TopicArn":"arn:aws:sns:eu-west-1:1:carlos-mail",`+ |
| + `"Message":"Successfully validated SNS topic for Amazon SES event publishing.",`+ |
| + `"SigningCertURL":"https://sns.eu-west-1.amazonaws.com/x.pem","Signature":"x"}`) |
| + defer resp.Body.Close() |
| + if resp.StatusCode != http.StatusOK { |
| + t.Fatalf("status = %d, want 200 — a non-2xx makes SNS retry", resp.StatusCode) |
| + } |
| + got := buf.String() |
| + if strings.Contains(got, "parse notification") { |
| + t.Errorf("the validation message logged as a parse failure:\n%s", got) |
| + } |
| + if strings.Count(got, "SES test message") != 1 { |
| + t.Errorf("want one line naming the SES test message:\n%s", got) |
| + } |
| +} |
| + |
| // TestSESEventsAnswers200ForUnknownTypes above sends a recognised SNS |
| // envelope Type ("Notification") whose INNER SES eventType is the unknown |
| // part — it never reaches the dispatch switch's default case at all. This |