1package imapserver
2
3import (
4 "crypto/tls"
5 "encoding/base64"
6 "testing"
7)
8
9func TestStarttls(t *testing.T) {
10 tc := start(t)
11 tc.client.Starttls(&tls.Config{InsecureSkipVerify: true})
12 tc.transactf("bad", "starttls") // TLS already active.
13 tc.client.Login("mjl@mox.example", password0)
14 tc.close()
15
16 tc = startArgs(t, true, true, false, true, "mjl")
17 tc.transactf("bad", "starttls") // TLS already active.
18 tc.close()
19
20 tc = startArgs(t, true, false, false, true, "mjl")
21 tc.transactf("no", `login "mjl@mox.example" "%s"`, password0)
22 tc.xcode("PRIVACYREQUIRED")
23 tc.transactf("no", "authenticate PLAIN %s", base64.StdEncoding.EncodeToString([]byte("\u0000mjl@mox.example\u0000"+password0)))
24 tc.xcode("PRIVACYREQUIRED")
25 tc.client.Starttls(&tls.Config{InsecureSkipVerify: true})
26 tc.client.Login("mjl@mox.example", password0)
27 tc.close()
28}
29