Add Authenticator test in AUTH handler.
This commit is contained in:
parent
7b9d6461a0
commit
b29fcf9fb6
2 changed files with 45 additions and 0 deletions
|
@ -298,6 +298,11 @@ func (session *session) handleQUIT(cmd command) {
|
||||||
|
|
||||||
func (session *session) handleAUTH(cmd command) {
|
func (session *session) handleAUTH(cmd command) {
|
||||||
|
|
||||||
|
if session.server.Authenticator == nil {
|
||||||
|
session.reply(502, "AUTH not supported.")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if session.peer.HeloName == "" {
|
if session.peer.HeloName == "" {
|
||||||
session.reply(502, "Please introduce yourself first.")
|
session.reply(502, "Please introduce yourself first.")
|
||||||
return
|
return
|
||||||
|
|
|
@ -278,6 +278,46 @@ func TestAuthRejection(t *testing.T) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAuthNotSupported(t *testing.T) {
|
||||||
|
|
||||||
|
ln, err := net.Listen("tcp", "127.0.0.1:0")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Listen failed: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
defer ln.Close()
|
||||||
|
|
||||||
|
cert, err := tls.X509KeyPair(localhostCert, localhostKey)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Cert load failed: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
server := &smtpd.Server{
|
||||||
|
TLSConfig: &tls.Config{
|
||||||
|
Certificates: []tls.Certificate{cert},
|
||||||
|
},
|
||||||
|
ForceTLS: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
server.Serve(ln)
|
||||||
|
}()
|
||||||
|
|
||||||
|
c, err := smtp.Dial(ln.Addr().String())
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Dial failed: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := c.StartTLS(&tls.Config{InsecureSkipVerify: true}); err != nil {
|
||||||
|
t.Fatalf("STARTTLS failed: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := c.Auth(smtp.PlainAuth("foo", "foo", "bar", "127.0.0.1")); err == nil {
|
||||||
|
t.Fatal("Auth worked despite no authenticator")
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
func TestConnectionCheck(t *testing.T) {
|
func TestConnectionCheck(t *testing.T) {
|
||||||
|
|
||||||
ln, err := net.Listen("tcp", "127.0.0.1:0")
|
ln, err := net.Listen("tcp", "127.0.0.1:0")
|
||||||
|
|
Loading…
Add table
Reference in a new issue