mirror of
https://github.com/mjl-/mox.git
synced 2025-06-28 01:48:15 +03:00
imapserver: fix fuzz tests
The acc.Close() at the end of the fuzzing would find inconsistencies. For example, message files on disk that aren't in the database file. I don't understand what is happening there, the database file on disk does have those messages, and it seems the database file is getting replaced. When running the same code not as a fuzzing test but as a regular Go test doesn't show the problem. So it seems to be some interaction with fuzzing. The problem is "solved" (feels more like side-stepped), by starting each fuzz test with a clean database. We still open & close the account in each fuzz test, and it doesn't find consistency problems.
This commit is contained in:
parent
e7b562e3f2
commit
3fe765dce9
@ -60,38 +60,11 @@ func FuzzServer(f *testing.F) {
|
|||||||
f.Add(tag + cmd)
|
f.Add(tag + cmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
log := mlog.New("imapserver", nil)
|
|
||||||
mox.ConfigStaticPath = filepath.FromSlash("../testdata/imapserverfuzz/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, password0)
|
|
||||||
if err != nil {
|
|
||||||
f.Fatalf("set password: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
comm := store.RegisterComm(acc)
|
|
||||||
defer comm.Unregister()
|
|
||||||
|
|
||||||
var cid int64 = 1
|
var cid int64 = 1
|
||||||
|
|
||||||
var fl *os.File
|
var fl *os.File
|
||||||
if false {
|
if false {
|
||||||
|
var err error
|
||||||
fl, err = os.OpenFile("fuzz.log", os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0600)
|
fl, err = os.OpenFile("fuzz.log", os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0600)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
f.Fatalf("fuzz log")
|
f.Fatalf("fuzz log")
|
||||||
@ -105,6 +78,34 @@ func FuzzServer(f *testing.F) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
f.Fuzz(func(t *testing.T, s string) {
|
f.Fuzz(func(t *testing.T, s string) {
|
||||||
|
log := mlog.New("imapserver", nil)
|
||||||
|
mox.ConfigStaticPath = filepath.FromSlash("../testdata/imapserverfuzz/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 {
|
||||||
|
t.Fatalf("store init: %v", err)
|
||||||
|
}
|
||||||
|
defer store.Switchboard()()
|
||||||
|
|
||||||
|
acc, err := store.OpenAccount(log, "mjl", false)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("open account: %v", err)
|
||||||
|
}
|
||||||
|
defer func() {
|
||||||
|
acc.Close()
|
||||||
|
acc.WaitClosed()
|
||||||
|
}()
|
||||||
|
err = acc.SetPassword(log, password0)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("set password: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
comm := store.RegisterComm(acc)
|
||||||
|
defer comm.Unregister()
|
||||||
|
|
||||||
run := func(cmds []string) {
|
run := func(cmds []string) {
|
||||||
limitersInit() // Reset rate limiters.
|
limitersInit() // Reset rate limiters.
|
||||||
serverConn, clientConn := net.Pipe()
|
serverConn, clientConn := net.Pipe()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user