-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtransaction_helo_test.go
74 lines (69 loc) · 1.78 KB
/
transaction_helo_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package msmtpd
import (
"net/smtp"
"testing"
"github.com/vodolaz095/msmtpd/internal"
)
func TestHELOCheck(t *testing.T) {
addr, closer := RunTestServerWithoutTLS(t, &Server{
HeloCheckers: []HelloChecker{
func(transaction *Transaction) error {
name := transaction.HeloName
if name != "foobar.local" {
t.Error("Wrong HELO name")
}
return ErrorSMTP{Code: 552, Message: "Denied"}
},
},
})
defer closer()
c, err := smtp.Dial(addr)
if err != nil {
t.Errorf("Dial failed: %v", err)
}
if err = c.Hello("foobar.local"); err == nil {
t.Error("Unexpected HELO success")
}
err = c.Close()
if err != nil {
t.Errorf("%s : while closing transaction", err)
}
}
func TestHELO(t *testing.T) {
addr, closer := RunTestServerWithoutTLS(t, &Server{})
defer closer()
c, err := smtp.Dial(addr)
if err != nil {
t.Errorf("Dial failed: %v", err)
}
if err = internal.DoCommand(c.Text, 502, "MAIL FROM:<test@example.org>"); err != nil {
t.Errorf("MAIL before HELO didn't fail: %v", err)
}
if err = internal.DoCommand(c.Text, 250, "HELO localhost"); err != nil {
t.Errorf("HELO failed: %v", err)
}
if err = internal.DoCommand(c.Text, 250, "MAIL FROM:<test@example.org>"); err != nil {
t.Errorf("MAIL after HELO failed: %v", err)
}
if err = internal.DoCommand(c.Text, 250, "HELO localhost"); err != nil {
t.Errorf("double HELO failed: %v", err)
}
if err = c.Quit(); err != nil {
t.Errorf("Quit failed: %v", err)
}
}
func TestInvalidHelo(t *testing.T) {
addr, closer := RunTestServerWithoutTLS(t, &Server{})
defer closer()
c, err := smtp.Dial(addr)
if err != nil {
t.Errorf("Dial failed: %v", err)
}
if err = c.Hello(""); err == nil {
t.Error("Unexpected HELO success")
}
err = c.Close()
if err != nil {
t.Errorf("%s : while closing transaction", err)
}
}