case "RSET":
conn.doRSET()
case "VRFY":
- conn.doVRFY()
+ conn.writeReply(252, "I'll do my best")
case "EXPN":
conn.writeReply(550, "access denied")
case "NOOP":
conn.reply(ReplyOK)
}
-func (conn *connection) doVRFY() {
-}
-
func (conn *connection) doRSET() {
conn.state = stateInitial
conn.resetBuffers()
return conn
}
+type requestResponse struct {
+ request string
+ responseCode int
+ handler func(testing.TB, *textproto.Conn)
+}
+
+func runTableTest(t testing.TB, conn *textproto.Conn, seq []requestResponse) {
+ for i, rr := range seq {
+ t.Logf("%s case %d", _fl(1), i)
+ ok(t, conn.PrintfLine(rr.request))
+ if rr.handler != nil {
+ rr.handler(t, conn)
+ } else {
+ readCodeLine(t, conn, rr.responseCode)
+ }
+ }
+}
+
// RFC 5321 ยง D.1
func TestScenarioTypical(t *testing.T) {
s := testServer{
ok(t, conn.PrintfLine("QUIT"))
readCodeLine(t, conn, 221)
}
+
+func TestVerifyAddress(t *testing.T) {
+ s := testServer{
+ blockList: []string{"banned@test.mail"},
+ }
+ l := runServer(t, &s)
+ defer l.Close()
+
+ conn := createClient(t, l.Addr())
+ readCodeLine(t, conn, 220)
+
+ runTableTest(t, conn, []requestResponse{
+ {"EHLO test", 0, func(t testing.TB, conn *textproto.Conn) { conn.ReadResponse(250) }},
+ {"VRFY banned@test.mail", 252, nil},
+ {"VRFY allowed@test.mail", 252, nil},
+ {"MAIL FROM:<sender@example.com>", 250, nil},
+ {"RCPT TO:<banned@test.mail>", 550, nil},
+ {"QUIT", 221, nil},
+ })
+}