console: share the fake lookup's success block; pin post-lookup delivery failures
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
1 file changed,
+18
−22
internal/console/keymail_test.go+18 −22
diff --git a/internal/console/keymail_test.go b/internal/console/keymail_test.go| index 45b6d3538..4cd409e62 100644 |
| --- a/internal/console/keymail_test.go |
| +++ b/internal/console/keymail_test.go |
| @@ -77,6 +77,9 @@ type fakeKeymail struct { |
| // it hold the answer for that long (or until the caller gives up). |
| lookupStatus map[string]int |
| lookupStall map[string]time.Duration |
| + // deliverStatus, when set, makes /api/federation/deliver answer that |
| + // status (an ordinary post-lookup failure) before looking at the envelope. |
| + deliverStatus int |
| } |
| // sentBodies is every message body the fake has accepted — how a test proves |
| @@ -232,29 +235,18 @@ func (f *fakeKeymail) handleLookup(w http.ResponseWriter, r *http.Request) { |
| } |
| f.mu.Lock() |
| defer f.mu.Unlock() |
| - if status == http.StatusOK { |
| - // A forced 200 resolves whatever the host (a Keymail-served custom |
| - // domain), so skip the keymail.dev-only routing below. |
| - bits := f.powBits |
| - if _, known := f.senders[r.URL.Query().Get("from")]; known { |
| - bits = 0 |
| + // A forced 200 resolves whatever the host (a Keymail-served custom |
| + // domain), so it skips the keymail.dev-only routing. |
| + if status != http.StatusOK { |
| + local, host, ok := strings.Cut(addr, "@") |
| + if !ok || host != "keymail.dev" { |
| + jsonErr(w, http.StatusBadRequest, "could not determine target mailbox") |
| + return |
| + } |
| + if f.noMailbox[local] { |
| + jsonErr(w, http.StatusNotFound, "no such mailbox") |
| + return |
| } |
| - w.Header().Set("Content-Type", "application/json") |
| - json.NewEncoder(w).Encode(map[string]any{ |
| - "addr": addr, "sign_pub": "", |
| - "box_pub": base64.StdEncoding.EncodeToString(f.boxPriv.PublicKey().Bytes()), |
| - "pow_bits": bits, |
| - }) |
| - return |
| - } |
| - local, host, ok := strings.Cut(addr, "@") |
| - if !ok || host != "keymail.dev" { |
| - jsonErr(w, http.StatusBadRequest, "could not determine target mailbox") |
| - return |
| - } |
| - if f.noMailbox[local] { |
| - jsonErr(w, http.StatusNotFound, "no such mailbox") |
| - return |
| } |
| bits := f.powBits |
| if _, known := f.senders[r.URL.Query().Get("from")]; known { |
| @@ -363,6 +355,10 @@ func (f *fakeKeymail) handleDeliver(w http.ResponseWriter, r *http.Request) { |
| return |
| } |
| e := req.Envelope |
| + if f.deliverStatus != 0 { |
| + jsonErr(w, f.deliverStatus, http.StatusText(f.deliverStatus)) |
| + return |
| + } |
| if f.blocked[e.From] { |
| jsonErr(w, http.StatusForbidden, "blocked") |
| return |