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
- func SignWith(priv ed25519.PrivateKey, keyID string, payload map[string]any) appstore.Envelope
- type Completion
- type IntentAsk
- type IntentEntry
- type Store
- func (s *Store) AddConnectCode(code string)
- func (s *Store) AddKey(id, use, status string) ed25519.PublicKey
- func (s *Store) Close()
- func (s *Store) Completions() []Completion
- func (s *Store) ConnectedKey() ed25519.PublicKey
- func (s *Store) ConnectedOrigin() string
- func (s *Store) Disconnects() int
- func (s *Store) Fingerprints() []string
- func (s *Store) IndexDoc(apps ...map[string]any) map[string]any
- func (s *Store) IndexReads() int
- func (s *Store) Intent(token string) *IntentEntry
- func (s *Store) IntentAsks() []IntentAsk
- func (s *Store) IntentPayload(tokenID, app, version, repo, ref string, expires time.Time) map[string]any
- func (s *Store) IntentReads() int
- func (s *Store) KeyReads() int
- func (s *Store) Keys() []appstore.Key
- func (s *Store) OnIntent(fn func(ask IntentAsk) (token, tokenID string, status int))
- func (s *Store) Origin() string
- func (s *Store) PutIntent(token string, e *IntentEntry)
- func (s *Store) PutMedia(name string, b []byte)
- func (s *Store) Refused() []string
- func (s *Store) ReplaceKey(id string)
- func (s *Store) SetDown(down bool)
- func (s *Store) SetIndex(keyID string, doc map[string]any, tamper bool)
- func (s *Store) SetKeyStatus(id, status string)
- func (s *Store) Sign(keyID string, payload map[string]any) appstore.Envelope
- func (s *Store) Verifies() []appstore.LicenseRequest
Constants ¶
const DefaultFilexOrigin = "http://test.local"
DefaultFilexOrigin is the filex a link of New's store is made for unless FilexOrigin says otherwise.
const DefaultInstanceID = "0f1e2d3c-4b5a-4968-8776-655443322110"
DefaultInstanceID is the store instance a connection binds to.
Variables ¶
This section is empty.
Functions ¶
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
AddConnectCode makes code a connection code the store takes once.
func (*Store) Completions ¶
func (s *Store) Completions() []Completion
Completions answers the completions received.
func (*Store) ConnectedKey ¶ added in v0.53.0
ConnectedKey is the public key a filex connected with (nil: none).
func (*Store) ConnectedOrigin ¶ added in v0.53.0
ConnectedOrigin is the filex_origin the last connection named.
func (*Store) Disconnects ¶ added in v0.53.0
Disconnects counts the signed DELETEs of the connection.
func (*Store) Fingerprints ¶
Fingerprints are what an administrator approves for the keys published now.
func (*Store) IndexDoc ¶ added in v0.53.0
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
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
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) KeyReads ¶
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) OnIntent ¶ added in v0.53.0
OnIntent sets how the store answers a connected filex's intent request.
func (*Store) PutIntent ¶
func (s *Store) PutIntent(token string, e *IntentEntry)
PutIntent publishes an install link.
func (*Store) Refused ¶ added in v0.53.0
Refused are the reasons the store refused signed requests with.
func (*Store) ReplaceKey ¶
ReplaceKey publishes new material under an existing id (what a store whose key was swapped looks like).
func (*Store) SetIndex ¶ added in v0.53.0
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 ¶
SetKeyStatus moves a published key's status (rotation, retirement).
func (*Store) Verifies ¶
func (s *Store) Verifies() []appstore.LicenseRequest
Verifies answers the license checks received.