Help us shape the future of Go! Take the 2026 Go Developer Survey

fakeserver

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 26, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

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

View Source
const MaxPage = 50

MaxPage is the most messages a list's page holds (PROTOCOL.md §11.11).

View Source
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 TakeAs

func TakeAs(w http.ResponseWriter, r *http.Request, edit func(*protocol.Receipt))

TakeAs is Take, with the receipt changed by edit before it is written.

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 New

func New(t testing.TB, now func() time.Time) *Server

New starts a server on the clock now, stopped when the test ends.

func (*Server) ACL

func (s *Server) ACL(a protocol.Address) *protocol.ACL

ACL returns a box's sender ACL, nil if it has none.

func (*Server) Account

func (s *Server) Account(a protocol.Address) string

Account is the account a box is in, or "".

func (*Server) AdoptKey

func (s *Server) AdoptKey(account string) string

AdoptKey mints an adopt key into account, good for one box.

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) Count

func (s *Server) Count(a protocol.Address) int

Count returns how many messages a box holds.

func (*Server) Forget

func (s *Server) Forget(a protocol.Address)

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

func (s *Server) Inject(to protocol.Address, id string, from protocol.Address, ciphertext []byte)

Inject stores a message in a box under id, as only the operator can: no check at all.

func (*Server) Prekey

func (s *Server) Prekey(a protocol.Address) (statement, signature []byte)

Prekey returns a box's current prekey statement and its signature, as served.

func (*Server) PutACL

func (s *Server) PutACL(a protocol.Address, acl *protocol.ACL)

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.

func (*Server) Requests

func (s *Server) Requests() []Request

Requests returns every call the server has been sent, oldest first.

func (*Server) SetMiddle

func (s *Server) SetMiddle(m func(w http.ResponseWriter, r *http.Request, next http.Handler))

SetMiddle puts m between the clients and the server, or removes it if m is nil. It sees every request, and calls next to let the server answer.

func (*Server) SetPage

func (s *Server) SetPage(n int)

SetPage sets the most messages a list's page holds, MaxPage until a test sets another.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL