diff options
| author | Shulhan <ms@kilabit.info> | 2019-01-15 19:37:13 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2019-01-15 19:37:13 +0700 |
| commit | cff4954bfc68c4d8d3215d814df14c2f6dfc9920 (patch) | |
| tree | 9be14256763f2a9cfd2dae9a3d103aa18c3f083b | |
| parent | 1e8fc58b394bae4fe1c034d35c6bf667c45364e1 (diff) | |
| download | pakakeh.go-cff4954bfc68c4d8d3215d814df14c2f6dfc9920.tar.xz | |
lib/smtp: test client authentication with two handshake
| -rw-r--r-- | lib/smtp/client_test.go | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/lib/smtp/client_test.go b/lib/smtp/client_test.go index 7fc5395b..1c04bfce 100644 --- a/lib/smtp/client_test.go +++ b/lib/smtp/client_test.go @@ -5,6 +5,7 @@ package smtp import ( + "encoding/base64" "net" "testing" "time" @@ -120,7 +121,43 @@ func TestAuth(t *testing.T) { test.Assert(t, "Response", c.exp, got, true) } +} + +func TestAuth2(t *testing.T) { + cl, err := NewClient(testAddress) + if err != nil { + t.Fatal(err) + } + + _, err = cl.Connect(true) + if err != nil { + t.Fatal(err) + } + + cmd := "AUTH PLAIN\r\n" + res, err := cl.SendCommand([]byte(cmd)) + if err != nil { + t.Fatal(err) + } + + exp := &Response{ + Code: StatusAuthReady, + } + test.Assert(t, "Response", exp, res, true) + + cred := []byte("\x00" + testUsername + "\x00" + testPassword) + cmd = base64.StdEncoding.EncodeToString(cred) + res, err = cl.SendCommand([]byte(cmd)) + if err != nil { + t.Fatal(err) + } + + exp = &Response{ + Code: StatusAuthenticated, + Message: "2.7.0 Authentication successful", + } + test.Assert(t, "Response", exp, res, true) } func TestExpand(t *testing.T) { |
