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

storetest

package
v0.56.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package storetest is a fake app store for tests: the `/v1/` paths a filex reads (docs/APP-PLUGINS-API.md → The store contract), signing exactly as a store must - ed25519 over the lower-hex sha256 of the canonical payload - and every answer adjustable mid-test (a tampered signature, a 410, a key that changes, a store that cannot be reached).

It signs with appstore.Canonical, so it can only prove that filex agrees with ITSELF; the independent proof that the canonical form is what a store in another language writes is the test vector (appstore/testdata, produced by Node's crypto, docs/APP-PLUGINS-API.md).

Index

Constants

View Source
const DefaultFilexOrigin = "http://test.local"

DefaultFilexOrigin is the filex a link of New's store is made for unless FilexOrigin says otherwise.

View Source
const DefaultInstanceID = "0f1e2d3c-4b5a-4968-8776-655443322110"

DefaultInstanceID is the store instance a connection binds to.

Variables

This section is empty.

Functions

func SignWith

func SignWith(priv ed25519.PrivateKey, keyID string, payload map[string]any) appstore.Envelope

SignWith signs payload with priv: ed25519(lower-hex sha256(canonical)). The payload is carried INDENTED and in Go's map order, not canonical: a filex must canonicalise what it received before it verifies.

Types

type Completion

type Completion struct {
	Token      string `json:"-"`
	InstanceID string `json:"instance_id"`
	Result     string `json:"result"`
}

Completion is one `POST /v1/install/{token}/complete` the store received.

type IntentAsk added in v0.53.0

type IntentAsk struct {
	App        string `json:"app"`
	Version    string `json:"version"`
	LicenseKey string `json:"license_key"`
}

IntentAsk is one signed intent request the store received.

type IntentEntry

type IntentEntry struct {
	Payload map[string]any
	KeyID   string
	// Status: 0/200 answers the signed intent; 404 / 410 as such.
	Status int
	// Tamper changes the payload after signing it.
	Tamper bool
}

IntentEntry is how the store answers one token.

type Store

type Store struct {
	Srv *httptest.Server
	// FilexOrigin is the filex_origin IntentPayload writes.
	FilexOrigin string

	// License answers a license check: the payload to sign and the key to
	// sign it with ("" = the first license key). nil answers 404.
	License func(req appstore.LicenseRequest) (payload map[string]any, keyID string)

	// KeysHits counts the keys.json reads; IntentHits the install-link reads.
	KeysHits   int
	IntentHits int
	// contains filtered or unexported fields
}

Store is the fake.

func New

func New() *Store

New starts a fake store on a loopback address (plain http: filex admits it with loopback sources on).

func (*Store) AddConnectCode added in v0.53.0

func (s *Store) AddConnectCode(code string)

AddConnectCode makes code a connection code the store takes once.

func (*Store) AddKey

func (s *Store) AddKey(id, use, status string) ed25519.PublicKey

AddKey publishes a fresh key; its private half stays here.

func (*Store) Close

func (s *Store) Close()

Close stops the server.

func (*Store) Completions

func (s *Store) Completions() []Completion

Completions answers the completions received.

func (*Store) ConnectedKey added in v0.53.0

func (s *Store) ConnectedKey() ed25519.PublicKey

ConnectedKey is the public key a filex connected with (nil: none).

func (*Store) ConnectedOrigin added in v0.53.0

func (s *Store) ConnectedOrigin() string

ConnectedOrigin is the filex_origin the last connection named.

func (*Store) Disconnects added in v0.53.0

func (s *Store) Disconnects() int

Disconnects counts the signed DELETEs of the connection.

func (*Store) Fingerprints

func (s *Store) Fingerprints() []string

Fingerprints are what an administrator approves for the keys published now.

func (*Store) IndexDoc added in v0.53.0

func (s *Store) IndexDoc(apps ...map[string]any) map[string]any

IndexDoc is a well-formed schema-1 index of this store with apps (each {name, version, permissions?}), expiring in a day.

func (*Store) IndexReads added in v0.53.0

func (s *Store) IndexReads() int

IndexReads counts the index reads.

func (*Store) Intent

func (s *Store) Intent(token string) *IntentEntry

Intent answers the entry for token (to change it mid-test).

func (*Store) IntentAsks added in v0.53.0

func (s *Store) IntentAsks() []IntentAsk

IntentAsks are the signed intent requests the store took.

func (*Store) IntentPayload

func (s *Store) IntentPayload(tokenID, app, version, repo, ref string, expires time.Time) map[string]any

IntentPayload is a well-formed intent payload for this store.

func (*Store) IntentReads

func (s *Store) IntentReads() int

IntentReads: see KeyReads.

func (*Store) KeyReads

func (s *Store) KeyReads() int

KeyReads is how many times keys.json was read; IntentReads how many times an install link was. Read under the store's lock (the fields are written by the server's goroutines: read bare, -race reports it).

func (*Store) Keys

func (s *Store) Keys() []appstore.Key

Keys answers the published keys.

func (*Store) OnIntent added in v0.53.0

func (s *Store) OnIntent(fn func(ask IntentAsk) (token, tokenID string, status int))

OnIntent sets how the store answers a connected filex's intent request.

func (*Store) Origin

func (s *Store) Origin() string

Origin is the store's origin, as filex names it.

func (*Store) PutIntent

func (s *Store) PutIntent(token string, e *IntentEntry)

PutIntent publishes an install link.

func (*Store) PutMedia added in v0.53.0

func (s *Store) PutMedia(name string, b []byte)

PutMedia serves b at /v1/media/<name>.

func (*Store) Refused added in v0.53.0

func (s *Store) Refused() []string

Refused are the reasons the store refused signed requests with.

func (*Store) ReplaceKey

func (s *Store) ReplaceKey(id string)

ReplaceKey publishes new material under an existing id (what a store whose key was swapped looks like).

func (*Store) SetDown

func (s *Store) SetDown(down bool)

SetDown makes every request fail at the connection (unreachable).

func (*Store) SetIndex added in v0.53.0

func (s *Store) SetIndex(keyID string, doc map[string]any, tamper bool)

SetIndex publishes doc as the store's index, signed with key id (the bytes as served are what is signed). tamper changes the bytes after.

func (*Store) SetKeyStatus

func (s *Store) SetKeyStatus(id, status string)

SetKeyStatus moves a published key's status (rotation, retirement).

func (*Store) Sign

func (s *Store) Sign(keyID string, payload map[string]any) appstore.Envelope

Sign builds an envelope over payload with key id.

func (*Store) Verifies

func (s *Store) Verifies() []appstore.LicenseRequest

Verifies answers the license checks received.

Jump to

Keyboard shortcuts

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