mirror of
https://github.com/hanzoai/mail.git
synced 2026-09-23 23:53:02 +00:00
Fork of github.com/mjl-/mox at 5656ca6d1b
(upstream v0.0.15 plus 55 commits).
Rename the module path in go.mod and the import paths in 268 Go files. Also
update the five scripts that "go install" the module (genwebsite.sh,
docker-release.sh, apidiff.sh, test-upgrade.sh, Dockerfile.release), which
would otherwise build upstream rather than this fork.
Add NOTICE recording the upstream project, author, license, and fork point,
and stating which license covers which files: MIT for the mox source and our
changes, MPL-2.0 for publicsuffix/public_suffix_list.txt alone, and the
vendored dependencies' own licenses under licenses/. Embed NOTICE so
"mail licenses" prints the lineage from the running binary. LICENSE.MIT,
LICENSE.MPLv2.0 and the licenses/ tree are preserved verbatim; no code is
relicensed.
The mox command name, config keys, data directory layout and website content
are unchanged. LLM.md records the fork point, the rename, what was left alone,
and the steps to stand the server up.
Co-authored-by: Hanzo Dev <[email protected]>
127 lines
3.1 KiB
Go
127 lines
3.1 KiB
Go
package smtpserver
|
|
|
|
import (
|
|
"fmt"
|
|
"net"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/hanzoai/mail/dns"
|
|
"github.com/hanzoai/mail/mlog"
|
|
"github.com/hanzoai/mail/mox-"
|
|
"github.com/hanzoai/mail/queue"
|
|
"github.com/hanzoai/mail/store"
|
|
)
|
|
|
|
// Fuzz the server. For each fuzz string, we set up servers in various connection states, and write the string as command.
|
|
func FuzzServer(f *testing.F) {
|
|
f.Add("HELO remote")
|
|
f.Add("EHLO remote")
|
|
f.Add("AUTH PLAIN")
|
|
f.Add("MAIL FROM:<remote@remote>")
|
|
f.Add("RCPT TO:<[email protected]>")
|
|
f.Add("DATA")
|
|
f.Add(".")
|
|
f.Add("RSET")
|
|
f.Add("VRFY x")
|
|
f.Add("EXPN x")
|
|
f.Add("HELP")
|
|
f.Add("NOOP")
|
|
f.Add("QUIT")
|
|
|
|
log := mlog.New("smtpserver", nil)
|
|
mox.Context = ctxbg
|
|
mox.ConfigStaticPath = filepath.FromSlash("../testdata/smtpserverfuzz/mox.conf")
|
|
mox.MustLoadConfig(true, false)
|
|
store.Close() // May not be open, we ignore error.
|
|
dataDir := mox.ConfigDirPath(mox.Conf.Static.DataDir)
|
|
os.RemoveAll(dataDir)
|
|
err := store.Init(ctxbg)
|
|
if err != nil {
|
|
f.Fatalf("store init: %v", err)
|
|
}
|
|
defer store.Switchboard()()
|
|
|
|
acc, err := store.OpenAccount(log, "mjl", false)
|
|
if err != nil {
|
|
f.Fatalf("open account: %v", err)
|
|
}
|
|
defer func() {
|
|
acc.Close()
|
|
acc.WaitClosed()
|
|
}()
|
|
err = acc.SetPassword(log, "testtest")
|
|
if err != nil {
|
|
f.Fatalf("set password: %v", err)
|
|
}
|
|
|
|
err = queue.Init()
|
|
if err != nil {
|
|
f.Fatalf("queue init: %v", err)
|
|
}
|
|
defer queue.Shutdown()
|
|
|
|
comm := store.RegisterComm(acc)
|
|
defer comm.Unregister()
|
|
|
|
var cid int64 = 1
|
|
|
|
var fl *os.File
|
|
if false {
|
|
fl, err = os.Create("fuzz.log")
|
|
if err != nil {
|
|
f.Fatalf("fuzz log")
|
|
}
|
|
defer fl.Close()
|
|
}
|
|
flog := func(err error, msg string) {
|
|
if fl != nil && err != nil {
|
|
fmt.Fprintf(fl, "%s: %v\n", msg, err)
|
|
}
|
|
}
|
|
|
|
f.Fuzz(func(t *testing.T, s string) {
|
|
run := func(cmds []string) {
|
|
limitersInit() // Reset rate limiters.
|
|
serverConn, clientConn := net.Pipe()
|
|
defer serverConn.Close()
|
|
defer clientConn.Close()
|
|
|
|
go func() {
|
|
err := clientConn.SetDeadline(time.Now().Add(time.Second))
|
|
flog(err, "set client deadline")
|
|
_, err = clientConn.Read(make([]byte, 1024))
|
|
flog(err, "read ehlo")
|
|
for _, cmd := range cmds {
|
|
_, err = clientConn.Write([]byte(cmd + "\r\n"))
|
|
flog(err, "write command")
|
|
_, err = clientConn.Read(make([]byte, 1024))
|
|
flog(err, "read response")
|
|
}
|
|
_, err = clientConn.Write([]byte(s + "\r\n"))
|
|
flog(err, "write test command")
|
|
_, err = clientConn.Read(make([]byte, 1024))
|
|
flog(err, "read test response")
|
|
clientConn.Close()
|
|
serverConn.Close()
|
|
}()
|
|
|
|
resolver := dns.MockResolver{}
|
|
const submission = false
|
|
const viaHTTPS = false
|
|
err := serverConn.SetDeadline(time.Now().Add(time.Second))
|
|
flog(err, "set server deadline")
|
|
serve("test", cid, dns.Domain{ASCII: "mox.example"}, nil, serverConn, resolver, submission, false, viaHTTPS, false, 100<<10, false, false, false, nil, 0)
|
|
cid++
|
|
}
|
|
|
|
run([]string{})
|
|
run([]string{"EHLO remote"})
|
|
run([]string{"EHLO remote", "MAIL FROM:<[email protected]>"})
|
|
run([]string{"EHLO remote", "MAIL FROM:<[email protected]>", "RCPT TO:<[email protected]>"})
|
|
// todo: submission with login
|
|
})
|
|
}
|