Documentation
¶
Overview ¶
Package imaptest runs go-imap's in-memory IMAP server over TLS for integration tests.
Index ¶
- Constants
- type Server
- func (s *Server) AllowToken(token string)
- func (s *Server) Append(t testing.TB, folder, eml string, flags ...imap.Flag) uint32
- func (s *Server) ChangePassword(p string)
- func (s *Server) CreateSpecial(t testing.TB, name string, attrs ...imap.MailboxAttr)
- func (s *Server) DelayNewMail(delay bool)
- func (s *Server) ExpireSessions()
- func (s *Server) Fingerprint() string
- func (s *Server) KillConnections()
- func (s *Server) OnIdle(f func())
- func (s *Server) RefuseCreate(refuse bool)
- func (s *Server) Rotate(t testing.TB)
- func (s *Server) TokenLogins() []string
Constants ¶
const ( Username = "me@example.test" Password = "app-pass-wxyz-1234" // #nosec G101 -- exists only on the in-memory test server )
The one account on the test server.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Server ¶
type Server struct {
Host string
Port int
TLS *tls.Config // client config that trusts the server's certificate
User *imapmemserver.User // create folders and inspect state directly
// contains filtered or unexported fields
}
Server is a running in-memory IMAP server with one user and an INBOX.
func Start ¶
Start serves until the test ends. caps is what the server advertises; nil means plain IMAP4rev1 (which still includes IDLE, but neither MOVE nor UIDPLUS).
func StartSTARTTLS ¶ added in v0.3.0
StartSTARTTLS is Start for a server that greets in the clear and offers STARTTLS, as Proton Mail Bridge does on its IMAP port; it refuses a login before TLS.
func (*Server) AllowToken ¶ added in v0.3.0
AllowToken makes AUTHENTICATE XOAUTH2 accept token for the one account, as a provider accepts an access token it issued, until ExpireSessions.
func (*Server) ChangePassword ¶ added in v0.3.0
ChangePassword makes LOGIN accept only p as the account's password from now on, as Proton Mail Bridge does when the account is signed in to it again; sessions already open stay. XOAUTH2 is not affected.
func (*Server) CreateSpecial ¶ added in v0.3.0
CreateSpecial makes a folder that LIST reports with the given SPECIAL-USE attributes (RFC 6154), always, as Gmail does. The in-memory server cannot store them, so once any folder is made this way LIST shows only INBOX and folders made with CreateSpecial.
func (*Server) DelayNewMail ¶ added in v0.3.0
DelayNewMail makes the server behave as Dovecot does: a session that has a folder selected sees mail delivered after the SELECT only once a later command has completed (NOOP being the one meant for it). Until then the new UID does not exist for it: UID FETCH answers nothing, UID STORE, COPY and MOVE ignore it and still answer OK (RFC 9051 §6.4.9 allows this of a UID that does not exist), and UID SEARCH leaves it out. The in-memory server otherwise shows every message at once.
func (*Server) ExpireSessions ¶ added in v0.3.0
func (s *Server) ExpireSessions()
ExpireSessions does what Gmail and Outlook do when an access token expires, about an hour after it was issued: every token accepted so far stops working, and every open session is closed with "* BYE".
func (*Server) Fingerprint ¶ added in v0.3.0
Fingerprint is the SHA-256 fingerprint of the certificate the server presents now, as mail.Cert.Fingerprint has it.
func (*Server) KillConnections ¶
func (s *Server) KillConnections()
KillConnections cuts every open connection, as a network drop would.
func (*Server) OnIdle ¶ added in v0.3.0
func (s *Server) OnIdle(f func())
OnIdle has f run each time a session begins IDLE, before anything is announced to it, so mail a test delivers from f lands between the client's last command and its IDLE. nil removes it.
func (*Server) RefuseCreate ¶
RefuseCreate makes the server answer CREATE with NO, as a server that does not let a client make folders would, until it is called with false.
func (*Server) Rotate ¶ added in v0.3.0
Rotate makes the server present a new self-signed certificate from the next connection on, as a server whose certificate was replaced would. TLS keeps trusting only the old one.
func (*Server) TokenLogins ¶ added in v0.3.0
TokenLogins are the access tokens of the XOAUTH2 logins the server accepted, in order.