Documentation
¶
Overview ¶
Package fakeserver is an in-memory dromas server for the client's tests: honest, and just enough of the API for a client to register, renew its prekey, send, list page by page, fetch and ack, each call carrying its box's pass. It is NOT the dromas.dev server, and checks little of what that server checks. Like every server it keeps and serves a revocation of any address, with a box here or none (PROTOCOL.md §11.15).
A test plays the hostile operator two ways: with SetMiddle, a function that sees every request and can rewrite it, answer it or forge the reply; and with the operator's own powers over storage (Inject, Count, Prekey). It logs every call it is sent, as the client sent it (Requests). Nothing the client is told to trust comes from here: every forgery a test makes is one a real operator could make (internal/forge has the common ones).
Index ¶
- Constants
- func Take(w http.ResponseWriter, r *http.Request)
- func TakeAs(w http.ResponseWriter, r *http.Request, edit func(*protocol.Receipt))
- func WriteCiphertext(w http.ResponseWriter, ct []byte)
- func WriteJSON(w http.ResponseWriter, status int, v any)
- func WriteList(w http.ResponseWriter, l protocol.MessageList)
- func WritePartial(w http.ResponseWriter, ct []byte, from int64)
- type Request
- type Server
- func (s *Server) ACL(a protocol.Address) *protocol.ACL
- func (s *Server) Account(a protocol.Address) string
- func (s *Server) AdoptKey(account string) string
- func (s *Server) Close()
- func (s *Server) Count(a protocol.Address) int
- func (s *Server) Forget(a protocol.Address)
- func (s *Server) Inject(to protocol.Address, id string, from protocol.Address, ciphertext []byte)
- func (s *Server) Prekey(a protocol.Address) (statement, signature []byte)
- func (s *Server) PutACL(a protocol.Address, acl *protocol.ACL)
- func (s *Server) Requests() []Request
- func (s *Server) SetMiddle(m func(w http.ResponseWriter, r *http.Request, next http.Handler))
- func (s *Server) SetPage(n int)
Constants ¶
const MaxPage = 50
MaxPage is the most messages a list's page holds (PROTOCOL.md §11.11).
const PollInterval = "60"
PollInterval is the Retry-After every list answer carries: the poll interval, in seconds.
Variables ¶
This section is empty.
Functions ¶
func Take ¶
func Take(w http.ResponseWriter, r *http.Request)
Take answers a post as a server that kept it would, and keeps nothing: a receipt for the ciphertext posted. It is for a test that plays an operator who swallows mail, which a client cannot tell from a delivery.
func WriteCiphertext ¶
func WriteCiphertext(w http.ResponseWriter, ct []byte)
WriteCiphertext writes a fetch's answer, as the server does: the ciphertext's bytes, with their length. A middleware forging one uses it.
func WriteJSON ¶
func WriteJSON(w http.ResponseWriter, status int, v any)
WriteJSON writes v as a JSON response, as the server does: a middleware forging an answer uses it.
func WriteList ¶
func WriteList(w http.ResponseWriter, l protocol.MessageList)
WriteList writes a list answer as the server does, with its Retry-After: PollInterval, unless the caller set one. A middleware forging one uses it.
func WritePartial ¶
func WritePartial(w http.ResponseWriter, ct []byte, from int64)
WritePartial writes a fetch's answer to a range that begins at byte from, below the ciphertext's length, as the server does: 206, the bytes from there to the end, their length, and a Content-Range that says which they are (protocol.ContentRange). A middleware forging one uses it.
Types ¶
type Request ¶
type Request struct {
Method, Path, Query string // the path and the raw query apart
Pass bool // it carried an Authorization header
}
Request is one call the server was sent, as the client sent it, before any middleware saw it.
type Server ¶
type Server struct {
URL string
// contains filtered or unexported fields
}
Server is a running fake server.
func (*Server) Close ¶
func (s *Server) Close()
Close stops the server for good, as one that is gone: whoever calls it gets no answer at all.
func (*Server) Forget ¶
Forget forgets box a, as a server does once its record's expiry has passed (PROTOCOL.md §13): what its identity revoked is kept, and nothing else.
func (*Server) Inject ¶
Inject stores a message in a box under id, as only the operator can: no check at all.
func (*Server) Prekey ¶
Prekey returns a box's current prekey statement and its signature, as served.
func (*Server) PutACL ¶
PutACL replaces a box's ACL as another writer of it does, another machine of the box or whoever holds its pass, with nothing deleted: a test's way to change what the box last sent.