Documentation
¶
Overview ¶
Package davtest is an in-process CardDAV and CalDAV server for tests, as imapxtest is for IMAP (docs/design/pim.md): memory collections, ETags, sync tokens over a change log, conditional writes, and hooks to change objects as another client would and to make requests fail.
It serves one user. The principal is PrincipalPath; address books live under ContactsHome and calendars under CalendarsHome, and /.well-known/carddav and caldav redirect to /dav/.
Index ¶
- Constants
- type Options
- type Request
- type Server
- func (s *Server) AddressBook(name, display string) string
- func (s *Server) Calendar(name, display, color string, comps ...string) string
- func (s *Server) Delete(path string)
- func (s *Server) FailWith(f func(*http.Request) int)
- func (s *Server) HideFromSync(path string)
- func (s *Server) InvalidateTokens()
- func (s *Server) Object(path string) (data []byte, etag string, ok bool)
- func (s *Server) Paths(coll string) []string
- func (s *Server) Phantom(path string)
- func (s *Server) Put(path string, data []byte) string
- func (s *Server) RemoveCollection(coll string)
- func (s *Server) Rename(coll, display string)
- func (s *Server) Requests() []Request
- func (s *Server) ResetRequests()
- func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (s *Server) SetReadOnly(coll string, ro bool)
Constants ¶
const ( User = "user" Password = "secret" PrincipalPath = "/dav/principals/user/" ContactsHome = "/dav/user/contacts/" CalendarsHome = "/dav/user/calendars/" // InboxPath is the scheduling inbox, named with ScheduleDefault. InboxPath = "/dav/user/inbox/" )
The server's fixed names.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Options ¶
type Options struct {
// Bearer, when set, is a token accepted as "Authorization: Bearer …"
// besides User and Password.
Bearer string
// NoSync makes collections neither list nor answer sync-collection.
NoSync bool
// NoWellKnown answers /.well-known/ with 404.
NoWellKnown bool
// Truncate cuts sync-collection answers after this many changes and
// marks them 507, as servers with a result limit do; 0 never cuts.
Truncate int
// CDATA writes object data in CDATA sections with literal line
// endings, which XML parsers turn from CRLF into LF.
CDATA bool
// NoETagOnPut leaves the ETag header out of PUT responses.
NoETagOnPut bool
// ScheduleDefault is the decoded path of the user's default calendar,
// named by the scheduling inbox (RFC 6638 §9.2); "" names no inbox.
ScheduleDefault string
// RelocateCreates stores a new object at a name of the server's
// choosing, from its UID, and answers 201 with a Location and no ETag,
// as Google's CalDAV does.
RelocateCreates bool
// NoInitialSync answers a sync-collection without a token with 400,
// as Google's CardDAV does, while still listing the report.
NoInitialSync bool
// KeepSequence refuses with 409, as Google's CalDAV does, a calendar
// object whose highest SEQUENCE is lower than the stored one's.
KeepSequence bool
}
Options tune the server.
type Request ¶
type Request struct {
Method string
Path string // escaped, as sent
Depth string
Report string // REPORTs: sync-collection, addressbook-multiget or calendar-multiget
Token string // sync-collection: the token sent
Hrefs int // multiget: how many hrefs
Header http.Header
}
Request is one request the server received.
type Server ¶
type Server struct {
// URL is the server's https:// origin.
URL string
// Client trusts the server's certificate.
Client *http.Client
// contains filtered or unexported fields
}
Server is a running DAV server.
func (*Server) AddressBook ¶
AddressBook adds an address book named name (a path segment) and returns its path.
func (*Server) Calendar ¶
Calendar adds a calendar with the components (VEVENT, VTODO; VEVENT when none) and returns its path. color is #rrggbb, or "".
func (*Server) FailWith ¶
FailWith makes each request for which f returns a status other than 0 fail with that status; nil stops failing. f runs without the server's lock and must not block.
func (*Server) HideFromSync ¶
HideFromSync makes a sync-collection call the object at path deleted, from no token as well, whenever it reports a change to path, while a PROPFIND, a multiget and a GET still serve it: Google does so for a single occurrence whose series is gone.
func (*Server) InvalidateTokens ¶
func (s *Server) InvalidateTokens()
InvalidateTokens makes every sync token handed out so far invalid, as a server that pruned its change log.
func (*Server) Phantom ¶
Phantom makes a PROPFIND of path's collection list path with an ETag, while a sync-collection, a multiget and a GET do not have it: Google lists events its sync reports as deleted and does not serve.
func (*Server) Put ¶
Put stores data at path, a decoded path inside a collection, as another client would, and returns the new ETag.
func (*Server) RemoveCollection ¶
RemoveCollection deletes a collection and its objects.
func (*Server) ResetRequests ¶
func (s *Server) ResetRequests()
ResetRequests forgets the requests received so far.
func (*Server) ServeHTTP ¶
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP implements http.Handler.
func (*Server) SetReadOnly ¶
SetReadOnly makes a collection refuse (or accept again) PUT and DELETE.