Files
tenant-registry/internal/mail/plain_test.go
T
Sharang ParnerkarandClaude Opus 5.5 2f6fa5f3e8
ci / shared (pull_request) Successful in 11s
ci / test (pull_request) Failing after 38s
ci / image (pull_request) Skipped
feat(onprem): APP_ENV=onprem for a customer's own node
The registry on a customer's node must never reach a Breakpilot host and
must not run the cloud's commercial machinery.

- APP_ENV=onprem: no ERP (nothing queued, webhook off), no trial (new
  workspaces start active, the ladder never escalates by time), and the
  trial-offer, trial-terms, catalog/trial request and admin trial routes
  answer 404 not_available.
- PRODUCTS, PRODUCT_LAUNCH_URLS, PRODUCT_PROVISION_URLS: one store
  decorator applies the product list and URLs to every catalog read
  (catalog, activation, provisioning, entitlement checks). On-prem has no
  seeded URLs, so provisioning goes only to the local products. Checked at
  start ({id} in provision URLs, absolute http(s)).
- On-prem start fails when the values leave something to a cloud or dev
  default (auth off, no authz rules, ephemeral licence key, portal, invite,
  sender, LLM gateway) or set an ERP or contract documents.
- SMTP_TLS=starttls|tls|none: a plain relay inside the customer's network;
  no AUTH without encryption.
- Migration 0032: the Werkpilot text no longer names our LLM host.

Cloud behaviour is unchanged without the new variables (tested).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-19 17:35:53 +01:00

102 lines
2.7 KiB
Go

package mail
import (
"bufio"
"context"
"net"
"strconv"
"strings"
"testing"
)
// plainRelay is a minimal SMTP server without STARTTLS (an internal relay on
// port 25). It records the commands it saw.
func plainRelay(t *testing.T) (host string, port int, cmds chan string) {
t.Helper()
ln, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() { _ = ln.Close() })
cmds = make(chan string, 64)
go func() {
conn, err := ln.Accept()
if err != nil {
return
}
defer conn.Close()
r := bufio.NewReader(conn)
say := func(s string) { _, _ = conn.Write([]byte(s + "\r\n")) }
say("220 relay.onprem.test ESMTP")
data := false
for {
line, err := r.ReadString('\n')
if err != nil {
return
}
line = strings.TrimRight(line, "\r\n")
if data {
if line == "." {
data = false
say("250 queued")
}
continue
}
verb := strings.ToUpper(strings.SplitN(line, " ", 2)[0])
cmds <- verb
switch verb {
case "EHLO", "HELO":
say("250-relay.onprem.test")
say("250 8BITMIME")
case "MAIL", "RCPT":
say("250 ok")
case "DATA":
data = true
say("354 go ahead")
case "QUIT":
say("221 bye")
return
default:
say("502 not implemented")
}
}
}()
h, p, _ := net.SplitHostPort(ln.Addr().String())
port, _ = strconv.Atoi(p)
return h, port, cmds
}
func TestSMTP_plainRelay(t *testing.T) {
host, port, cmds := plainRelay(t)
s := &SMTP{Cfg: Config{Host: host, Port: port, From: "breakpilot@onprem.test", TLS: "none"}}
if err := s.Send(context.Background(), Message{To: "anna@onprem.test", Subject: "Test", Text: "hi", HTML: "<p>hi</p>"}); err != nil {
t.Fatal(err)
}
close(cmds)
var seen []string
for c := range cmds {
seen = append(seen, c)
}
if got := strings.Join(seen, " "); got != "EHLO MAIL RCPT DATA QUIT" {
t.Errorf("commands = %s", got)
}
}
func TestSMTP_starttlsStillRequiredByDefault(t *testing.T) {
host, port, _ := plainRelay(t)
s := &SMTP{Cfg: Config{Host: host, Port: port, From: "breakpilot@onprem.test"}}
err := s.Send(context.Background(), Message{To: "anna@onprem.test", Subject: "Test", Text: "hi"})
if err == nil || !strings.Contains(err.Error(), "STARTTLS") {
t.Errorf("err = %v, want the STARTTLS refusal", err)
}
}
func TestSMTP_noAuthInPlainText(t *testing.T) {
host, port, _ := plainRelay(t)
s := &SMTP{Cfg: Config{Host: host, Port: port, From: "breakpilot@onprem.test", TLS: "none", User: "u", Password: "p"}}
err := s.Send(context.Background(), Message{To: "anna@onprem.test", Subject: "Test", Text: "hi"})
if err == nil || !strings.Contains(err.Error(), "unencrypted") {
t.Errorf("err = %v, want the plain-text AUTH refusal", err)
}
}