mirror of
https://github.com/mjl-/mox.git
synced 2025-07-12 12:24:38 +03:00
if the first smtp or imap command is invalid, shut down the connection instead of trying to read more
this is quite common on the internet. the other side may be trying some other protocol, e.g. http, or some common vulnerability. we don't want to spam our own logs with multiple invalid lines. if the first command is valid, but later are not, we'll keep trying to process them. so this only affects protocol sessions that are very likely not smtp/imap. also remove a few more sleeps during tests, making imapserver and smtpserver tests a bit faster.
This commit is contained in:
@ -26,6 +26,7 @@ func init() {
|
||||
|
||||
// Don't slow down tests.
|
||||
badClientDelay = 0
|
||||
authFailDelay = 0
|
||||
}
|
||||
|
||||
func tocrlf(s string) string {
|
||||
@ -397,8 +398,6 @@ func TestLogin(t *testing.T) {
|
||||
func TestState(t *testing.T) {
|
||||
tc := start(t)
|
||||
|
||||
tc.transactf("bad", "boguscommand")
|
||||
|
||||
notAuthenticated := []string{"starttls", "authenticate", "login"}
|
||||
authenticatedOrSelected := []string{"enable", "select", "examine", "create", "delete", "rename", "subscribe", "unsubscribe", "list", "namespace", "status", "append", "idle", "lsub"}
|
||||
selected := []string{"close", "unselect", "expunge", "search", "fetch", "store", "copy", "move", "uid expunge"}
|
||||
@ -421,6 +420,21 @@ func TestState(t *testing.T) {
|
||||
for _, cmd := range append(append([]string{}, notAuthenticated...), selected...) {
|
||||
tc.transactf("no", "%s", cmd)
|
||||
}
|
||||
|
||||
tc.transactf("bad", "boguscommand")
|
||||
}
|
||||
|
||||
func TestNonIMAP(t *testing.T) {
|
||||
tc := start(t)
|
||||
defer tc.close()
|
||||
|
||||
// imap greeting has already been read, we sidestep the imapclient.
|
||||
_, err := fmt.Fprintf(tc.conn, "bogus\r\n")
|
||||
tc.check(err, "write bogus command")
|
||||
tc.readprefixline("* BYE ")
|
||||
if _, err := tc.conn.Read(make([]byte, 1)); err == nil {
|
||||
t.Fatalf("connection not closed after initial bad command")
|
||||
}
|
||||
}
|
||||
|
||||
func TestLiterals(t *testing.T) {
|
||||
|
Reference in New Issue
Block a user