fix: say the true thing when Gmail, AI or mail is not set up
Two bugs with one shape: the interface confidently told you something that was not so. Connecting Gmail without a registered OAuth client said "Det er der allerede." Thirteen different situations answered a plain `conflict`, and the frontend renders that as "that already exists" — which for four of them is not vague but wrong. An unconfigured Gmail is not a Gmail that is already connected; a second factor that is off is not one that is on; the Inbox is not a project that already exists somewhere else. Those four have their own codes now, and their own sentences. The mail-to-task address came out as todo+…@localhost. VERDANDE_SMTP_FROM defaults to verdande@localhost and the domain was taken from it unconditionally, so an instance with no mail server handed out an address that looks real, can never receive anything, and gives no hint which of the two it is. The default no longer wins over the public hostname, and the response now carries whether a mail server exists at all — because even with the right domain, nothing routes to it until one does. errors.go has always claimed the code list is kept in one place "so the frontend's mapping can be checked against it". Nothing checked it, and the mapping was missing bad_request. Now a test reads both files and fails on a code with no message. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
committed by
Kristian Wind
co-authored by
Claude Opus 5
parent
7e28d8bb92
commit
78ec9b08a1
@@ -880,3 +880,52 @@ func TestMCPWithKeyIgnoresTheSessionCookie(t *testing.T) {
|
||||
resp.StatusCode)
|
||||
}
|
||||
}
|
||||
|
||||
// --- mail to task ------------------------------------------------------------------
|
||||
|
||||
// The address used to come out as todo+…@localhost on any instance without a
|
||||
// mail server, because VERDANDE_SMTP_FROM defaults to verdande@localhost and the
|
||||
// domain was taken from it unconditionally. That address looks real, cannot
|
||||
// receive anything, and gives no hint which of the two it is.
|
||||
func TestMailAddressDoesNotClaimToBeLocalhost(t *testing.T) {
|
||||
ts := newTestServerWith(t, func(c *config.Config) {
|
||||
c.BaseURL = "https://todo.example.dk"
|
||||
// Left at the default, as an instance with no mail server has it.
|
||||
c.SMTP.From = "verdande@localhost"
|
||||
})
|
||||
ts.bootstrap(t)
|
||||
|
||||
_, body := ts.do(t, "GET", "/api/v1/mail-address", nil)
|
||||
address, _ := body["address"].(string)
|
||||
|
||||
if strings.HasSuffix(address, "@localhost") {
|
||||
t.Errorf("address = %q — that can never receive mail", address)
|
||||
}
|
||||
if !strings.HasSuffix(address, "@todo.example.dk") {
|
||||
t.Errorf("address = %q, want the public hostname", address)
|
||||
}
|
||||
if body["configured"] != false {
|
||||
t.Error("no SMTP host is set, so configured should be false")
|
||||
}
|
||||
}
|
||||
|
||||
// A real sender address still wins: the mail server's own domain is the one that
|
||||
// can actually route this, and the web address may be a tunnel hostname.
|
||||
func TestMailAddressPrefersTheConfiguredSender(t *testing.T) {
|
||||
ts := newTestServerWith(t, func(c *config.Config) {
|
||||
c.BaseURL = "https://tunnel-abc123.example.net"
|
||||
c.SMTP.Host = "mail.firma.dk"
|
||||
c.SMTP.From = "verdande@firma.dk"
|
||||
})
|
||||
ts.bootstrap(t)
|
||||
|
||||
_, body := ts.do(t, "GET", "/api/v1/mail-address", nil)
|
||||
address, _ := body["address"].(string)
|
||||
|
||||
if !strings.HasSuffix(address, "@firma.dk") {
|
||||
t.Errorf("address = %q, want the sender's domain", address)
|
||||
}
|
||||
if body["configured"] != true {
|
||||
t.Error("an SMTP host is set, so configured should be true")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user