Documentation
¶
Index ¶
- Variables
- type DelegationSpec
- type FTMetadata
- type FTTargets
- type FetchTracker
- type RepositorySimulator
- func (rs *RepositorySimulator) AddDelegation(delegatorName string, role metadata.DelegatedRole, ...)
- func (rs *RepositorySimulator) AddSigner(role string, keyID string, signer signature.Signer)
- func (rs *RepositorySimulator) AddSuccinctRoles(delegatorName string, bitLength int, namePrefix string)
- func (rs *RepositorySimulator) AddTarget(role string, data []byte, path string)
- func (rs *RepositorySimulator) AllTargets() <-chan metadata.TargetsType
- func (rs *RepositorySimulator) DownloadFile(urlPath string, maxLength int64, _ time.Duration) ([]byte, error)
- func (rs *RepositorySimulator) FetchMetadata(role string, version *int) ([]byte, error)
- func (rs *RepositorySimulator) FetchTarget(targetPath string, targetHash string) ([]byte, error)
- func (rs *RepositorySimulator) PublishRoot()
- func (rs *RepositorySimulator) Root() metadata.RootType
- func (rs *RepositorySimulator) RotateKeys(role string)
- func (rs *RepositorySimulator) Snapshot() metadata.SnapshotType
- func (rs *RepositorySimulator) Targets() metadata.TargetsType
- func (rs *RepositorySimulator) Timestamp() metadata.TimestampType
- func (rs *RepositorySimulator) UpdateSnapshot()
- func (rs *RepositorySimulator) UpdateTimestamp()
- func (rs *RepositorySimulator) Write()
- type RepositoryTarget
- type SimulatorBuilder
- func (b *SimulatorBuilder) Build(t *testing.T) *RepositorySimulator
- func (b *SimulatorBuilder) WithComputeHashesAndLength(enabled bool) *SimulatorBuilder
- func (b *SimulatorBuilder) WithConsistentSnapshot(enabled bool) *SimulatorBuilder
- func (b *SimulatorBuilder) WithDelegation(delegatorName string, role metadata.DelegatedRole, ...) *SimulatorBuilder
- func (b *SimulatorBuilder) WithExpiredRole(role string) *SimulatorBuilder
- func (b *SimulatorBuilder) WithExpiry(d time.Duration) *SimulatorBuilder
- func (b *SimulatorBuilder) WithPrefixTargetsWithHash(enabled bool) *SimulatorBuilder
- func (b *SimulatorBuilder) WithRootRotations(count int) *SimulatorBuilder
- func (b *SimulatorBuilder) WithSnapshotVersionBump(bump int64) *SimulatorBuilder
- func (b *SimulatorBuilder) WithSuccinctRoles(delegatorName string, bitLength int, namePrefix string) *SimulatorBuilder
- func (b *SimulatorBuilder) WithTarget(path string, content []byte) *SimulatorBuilder
- func (b *SimulatorBuilder) WithTargets(targets map[string][]byte) *SimulatorBuilder
- func (b *SimulatorBuilder) WithTargetsVersionBump(bump int64) *SimulatorBuilder
- func (b *SimulatorBuilder) WithTimestampVersionBump(bump int64) *SimulatorBuilder
- func (b *SimulatorBuilder) WithVersion(role string, version int64) *SimulatorBuilder
- func (b *SimulatorBuilder) WithoutSigners(role string) *SimulatorBuilder
- type TestRepository
- func (r *TestRepository) AddTarget(role string, content []byte, path string)
- func (r *TestRepository) AssertContentEquals(role string, version *int)
- func (r *TestRepository) AssertFilesExact(roles []string)
- func (r *TestRepository) AssertFilesExist(roles []string)
- func (r *TestRepository) AssertVersionEquals(role string, expectedVersion int64)
- func (r *TestRepository) BumpVersion(role string)
- func (r *TestRepository) Cleanup()
- func (r *TestRepository) DisableComputeHashesAndLength()
- func (r *TestRepository) EnableComputeHashesAndLength()
- func (r *TestRepository) GetUnsafeUpdaterConfig() (*config.UpdaterConfig, error)
- func (r *TestRepository) GetUpdaterConfig() (*config.UpdaterConfig, error)
- func (r *TestRepository) GetVersion(role string) int64
- func (r *TestRepository) PastTime() time.Time
- func (r *TestRepository) PublishRoot()
- func (r *TestRepository) ReloadRootBytes() error
- func (r *TestRepository) RemoveSigners(role string)
- func (r *TestRepository) RotateKeys(role string)
- func (r *TestRepository) SetExpired(role string)
- func (r *TestRepository) SetExpiresAt(role string, expires time.Time)
- func (r *TestRepository) SetSnapshotMeta(role string, version int64)
- func (r *TestRepository) SetTimestampSnapshotMeta(version int64)
- func (r *TestRepository) SetVersion(role string, version int64)
- func (r *TestRepository) UpdateSnapshot()
- func (r *TestRepository) UpdateTimestamp()
- func (r *TestRepository) WriteRoot(version int) error
Constants ¶
This section is empty.
Variables ¶
var SPEC_VER = "." + metadata.SPECIFICATION_VERSION
Functions ¶
This section is empty.
Types ¶
type DelegationSpec ¶ added in v2.5.0
type DelegationSpec struct {
DelegatorName string
Role metadata.DelegatedRole
Targets metadata.TargetsType
}
DelegationSpec defines a delegation to be created in the repository
type FTMetadata ¶
type FetchTracker ¶
type FetchTracker struct {
Metadata []FTMetadata
Targets []FTTargets
}
FetchTracker contains actual target data and the related target metadata
type RepositorySimulator ¶
type RepositorySimulator struct {
fetcher.Fetcher
MDDelegates map[string]metadata.Metadata[metadata.TargetsType]
SignedRoots [][]byte
Signers map[string]map[string]*signature.Signer
TargetFiles map[string]RepositoryTarget
ComputeMetafileHashesAndLength bool
PrefixTargetsWithHash bool
DumpDir string
DumpVersion int64
FetchTracker FetchTracker
SafeExpiry time.Time
MDTargets *metadata.Metadata[metadata.TargetsType]
MDSnapshot *metadata.Metadata[metadata.SnapshotType]
MDTimestamp *metadata.Metadata[metadata.TimestampType]
MDRoot *metadata.Metadata[metadata.RootType]
LocalDir string
// contains filtered or unexported fields
}
RepositorySimulator simulates a repository that can be used for testing
func NewRepository ¶
func NewRepository() *RepositorySimulator
New initializes a RepositorySimulator
func (*RepositorySimulator) AddDelegation ¶
func (rs *RepositorySimulator) AddDelegation(delegatorName string, role metadata.DelegatedRole, targets metadata.TargetsType)
AddDelegation adds delegated target role to the repository
func (*RepositorySimulator) AddSigner ¶
func (rs *RepositorySimulator) AddSigner(role string, keyID string, signer signature.Signer)
func (*RepositorySimulator) AddSuccinctRoles ¶
func (rs *RepositorySimulator) AddSuccinctRoles(delegatorName string, bitLength int, namePrefix string)
AddSuccinctRoles adds succinct roles info to a delegator with name "delegatorName".
Note that for each delegated role represented by succinct roles an empty Targets instance is created
func (*RepositorySimulator) AddTarget ¶
func (rs *RepositorySimulator) AddTarget(role string, data []byte, path string)
AddTarget creates a target from data and adds it to the TargetFiles.
func (*RepositorySimulator) AllTargets ¶
func (rs *RepositorySimulator) AllTargets() <-chan metadata.TargetsType
AllTargets allows receiving role name and signed portion of targets one by one
func (*RepositorySimulator) DownloadFile ¶
func (*RepositorySimulator) FetchMetadata ¶
func (rs *RepositorySimulator) FetchMetadata(role string, version *int) ([]byte, error)
FetchMetadata returns signed metadata for 'role', using 'version' if it is given. If version is None, non-versioned metadata is being requested
func (*RepositorySimulator) FetchTarget ¶
func (rs *RepositorySimulator) FetchTarget(targetPath string, targetHash string) ([]byte, error)
FetchTarget returns data for 'targetPath', checking 'targetHash' if it is given. If hash is None, then consistentSnapshot is not used
func (*RepositorySimulator) PublishRoot ¶
func (rs *RepositorySimulator) PublishRoot()
PublishRoot signs and stores a new serialized version of root
func (*RepositorySimulator) Root ¶
func (rs *RepositorySimulator) Root() metadata.RootType
func (*RepositorySimulator) RotateKeys ¶
func (rs *RepositorySimulator) RotateKeys(role string)
RotateKeys removes all keys for role, then add threshold of new keys
func (*RepositorySimulator) Snapshot ¶
func (rs *RepositorySimulator) Snapshot() metadata.SnapshotType
func (*RepositorySimulator) Targets ¶
func (rs *RepositorySimulator) Targets() metadata.TargetsType
func (*RepositorySimulator) Timestamp ¶
func (rs *RepositorySimulator) Timestamp() metadata.TimestampType
func (*RepositorySimulator) UpdateSnapshot ¶
func (rs *RepositorySimulator) UpdateSnapshot()
UpdateSnapshot updates snapshot, assigns targets versions and updates timestamp
func (*RepositorySimulator) UpdateTimestamp ¶
func (rs *RepositorySimulator) UpdateTimestamp()
UpdateTimestamp updates timestamp and assign snapshot version to snapshot meta version
func (*RepositorySimulator) Write ¶
func (rs *RepositorySimulator) Write()
This is a debugging tool: dumping repository state before running Updater refresh may be useful while debugging a test.
type RepositoryTarget ¶
type RepositoryTarget struct {
Data []byte
TargetFile *metadata.TargetFiles
}
RepositoryTarget contains actual target data and the related target metadata
type SimulatorBuilder ¶ added in v2.5.0
type SimulatorBuilder struct {
// contains filtered or unexported fields
}
SimulatorBuilder creates configured RepositorySimulator instances using a fluent API
func NewSimulator ¶ added in v2.5.0
func NewSimulator() *SimulatorBuilder
NewSimulator creates a new SimulatorBuilder with sensible defaults
func (*SimulatorBuilder) Build ¶ added in v2.5.0
func (b *SimulatorBuilder) Build(t *testing.T) *RepositorySimulator
Build creates the configured RepositorySimulator
func (*SimulatorBuilder) WithComputeHashesAndLength ¶ added in v2.5.0
func (b *SimulatorBuilder) WithComputeHashesAndLength(enabled bool) *SimulatorBuilder
WithComputeHashesAndLength enables or disables hash/length computation for meta files
func (*SimulatorBuilder) WithConsistentSnapshot ¶ added in v2.5.0
func (b *SimulatorBuilder) WithConsistentSnapshot(enabled bool) *SimulatorBuilder
WithConsistentSnapshot enables or disables consistent snapshots
func (*SimulatorBuilder) WithDelegation ¶ added in v2.5.0
func (b *SimulatorBuilder) WithDelegation(delegatorName string, role metadata.DelegatedRole, targets metadata.TargetsType) *SimulatorBuilder
WithDelegation adds a delegated targets role
func (*SimulatorBuilder) WithExpiredRole ¶ added in v2.5.0
func (b *SimulatorBuilder) WithExpiredRole(role string) *SimulatorBuilder
WithExpiredRole marks a role's metadata as expired
func (*SimulatorBuilder) WithExpiry ¶ added in v2.5.0
func (b *SimulatorBuilder) WithExpiry(d time.Duration) *SimulatorBuilder
WithExpiry sets the default metadata expiration duration
func (*SimulatorBuilder) WithPrefixTargetsWithHash ¶ added in v2.5.0
func (b *SimulatorBuilder) WithPrefixTargetsWithHash(enabled bool) *SimulatorBuilder
WithPrefixTargetsWithHash enables or disables hash-prefixed target file names
func (*SimulatorBuilder) WithRootRotations ¶ added in v2.5.0
func (b *SimulatorBuilder) WithRootRotations(count int) *SimulatorBuilder
WithRootRotations performs the specified number of root rotations
func (*SimulatorBuilder) WithSnapshotVersionBump ¶ added in v2.5.0
func (b *SimulatorBuilder) WithSnapshotVersionBump(bump int64) *SimulatorBuilder
WithSnapshotVersionBump bumps the snapshot version by the specified amount
func (*SimulatorBuilder) WithSuccinctRoles ¶ added in v2.5.0
func (b *SimulatorBuilder) WithSuccinctRoles(delegatorName string, bitLength int, namePrefix string) *SimulatorBuilder
WithSuccinctRoles adds succinct roles to a delegator
func (*SimulatorBuilder) WithTarget ¶ added in v2.5.0
func (b *SimulatorBuilder) WithTarget(path string, content []byte) *SimulatorBuilder
WithTarget adds a target file to the repository
func (*SimulatorBuilder) WithTargets ¶ added in v2.5.0
func (b *SimulatorBuilder) WithTargets(targets map[string][]byte) *SimulatorBuilder
WithTargets adds multiple target files to the repository
func (*SimulatorBuilder) WithTargetsVersionBump ¶ added in v2.5.0
func (b *SimulatorBuilder) WithTargetsVersionBump(bump int64) *SimulatorBuilder
WithTargetsVersionBump bumps the targets version by the specified amount
func (*SimulatorBuilder) WithTimestampVersionBump ¶ added in v2.5.0
func (b *SimulatorBuilder) WithTimestampVersionBump(bump int64) *SimulatorBuilder
WithTimestampVersionBump bumps the timestamp version by the specified amount
func (*SimulatorBuilder) WithVersion ¶ added in v2.5.0
func (b *SimulatorBuilder) WithVersion(role string, version int64) *SimulatorBuilder
WithVersion sets the initial version for a top-level role. Explicit version bumps and root rotations are applied on top of this version.
func (*SimulatorBuilder) WithoutSigners ¶ added in v2.5.0
func (b *SimulatorBuilder) WithoutSigners(role string) *SimulatorBuilder
WithoutSigners removes signers for a role (for testing unsigned metadata)
type TestRepository ¶ added in v2.5.0
type TestRepository struct {
Simulator *RepositorySimulator
MetadataDir string
TargetsDir string
RootBytes []byte
LocalDir string
// contains filtered or unexported fields
}
TestRepository encapsulates all test state for an isolated repository (no globals)
func NewTestRepository ¶ added in v2.5.0
func NewTestRepository(t *testing.T) *TestRepository
NewTestRepository creates an isolated test repository with a fresh simulator
func NewTestRepositoryWithBuilder ¶ added in v2.5.0
func NewTestRepositoryWithBuilder(t *testing.T, builder *SimulatorBuilder) *TestRepository
NewTestRepositoryWithBuilder creates an isolated test repository using a SimulatorBuilder
func (*TestRepository) AddTarget ¶ added in v2.5.0
func (r *TestRepository) AddTarget(role string, content []byte, path string)
AddTarget adds a target file to the repository
func (*TestRepository) AssertContentEquals ¶ added in v2.5.0
func (r *TestRepository) AssertContentEquals(role string, version *int)
AssertContentEquals asserts that local file content matches the simulator's metadata
func (*TestRepository) AssertFilesExact ¶ added in v2.5.0
func (r *TestRepository) AssertFilesExact(roles []string)
AssertFilesExact asserts that exactly these files exist in the metadata dir
func (*TestRepository) AssertFilesExist ¶ added in v2.5.0
func (r *TestRepository) AssertFilesExist(roles []string)
AssertFilesExist asserts that local metadata files exist for the given roles
func (*TestRepository) AssertVersionEquals ¶ added in v2.5.0
func (r *TestRepository) AssertVersionEquals(role string, expectedVersion int64)
AssertVersionEquals asserts that a local metadata file has the expected version
func (*TestRepository) BumpVersion ¶ added in v2.5.0
func (r *TestRepository) BumpVersion(role string)
BumpVersion increments version for a role
func (*TestRepository) Cleanup ¶ added in v2.5.0
func (r *TestRepository) Cleanup()
Cleanup is a no-op: the temporary directory is removed automatically when the test completes because it was created with t.TempDir(). It is kept for call-site compatibility.
func (*TestRepository) DisableComputeHashesAndLength ¶ added in v2.5.0
func (r *TestRepository) DisableComputeHashesAndLength()
DisableComputeHashesAndLength disables hash/length computation for meta files
func (*TestRepository) EnableComputeHashesAndLength ¶ added in v2.5.0
func (r *TestRepository) EnableComputeHashesAndLength()
EnableComputeHashesAndLength enables hash/length computation for meta files
func (*TestRepository) GetUnsafeUpdaterConfig ¶ added in v2.5.0
func (r *TestRepository) GetUnsafeUpdaterConfig() (*config.UpdaterConfig, error)
GetUnsafeUpdaterConfig returns an UpdaterConfig with UnsafeLocalMode enabled
func (*TestRepository) GetUpdaterConfig ¶ added in v2.5.0
func (r *TestRepository) GetUpdaterConfig() (*config.UpdaterConfig, error)
GetUpdaterConfig returns an UpdaterConfig configured to use this test repository. The root.json bytes are re-read from MetadataDir on every call: after a successful Refresh, Updater persists an updated root.json to disk, and re-using the bytes captured at repository initialization would silently roll the persisted root back to its initial version on the next Updater.New.
func (*TestRepository) GetVersion ¶ added in v2.5.0
func (r *TestRepository) GetVersion(role string) int64
GetVersion returns the current version for a role
func (*TestRepository) PastTime ¶ added in v2.5.0
func (r *TestRepository) PastTime() time.Time
PastTime returns a time in the past for expiration testing
func (*TestRepository) PublishRoot ¶ added in v2.5.0
func (r *TestRepository) PublishRoot()
PublishRoot signs and publishes a new root
func (*TestRepository) ReloadRootBytes ¶ added in v2.5.0
func (r *TestRepository) ReloadRootBytes() error
ReloadRootBytes reloads the root bytes from the metadata directory
func (*TestRepository) RemoveSigners ¶ added in v2.5.0
func (r *TestRepository) RemoveSigners(role string)
RemoveSigners removes signers for a role (for testing unsigned metadata)
func (*TestRepository) RotateKeys ¶ added in v2.5.0
func (r *TestRepository) RotateKeys(role string)
RotateKeys rotates keys for a role
func (*TestRepository) SetExpired ¶ added in v2.5.0
func (r *TestRepository) SetExpired(role string)
SetExpired marks a role's metadata as expired
func (*TestRepository) SetExpiresAt ¶ added in v2.5.0
func (r *TestRepository) SetExpiresAt(role string, expires time.Time)
SetExpiresAt sets the expiration time for a role's metadata
func (*TestRepository) SetSnapshotMeta ¶ added in v2.5.0
func (r *TestRepository) SetSnapshotMeta(role string, version int64)
SetSnapshotMeta sets the meta information for a role in snapshot
func (*TestRepository) SetTimestampSnapshotMeta ¶ added in v2.5.0
func (r *TestRepository) SetTimestampSnapshotMeta(version int64)
SetTimestampSnapshotMeta sets the snapshot meta information in timestamp
func (*TestRepository) SetVersion ¶ added in v2.5.0
func (r *TestRepository) SetVersion(role string, version int64)
SetVersion changes version for a role
func (*TestRepository) UpdateSnapshot ¶ added in v2.5.0
func (r *TestRepository) UpdateSnapshot()
UpdateSnapshot updates snapshot metadata and timestamp
func (*TestRepository) UpdateTimestamp ¶ added in v2.5.0
func (r *TestRepository) UpdateTimestamp()
UpdateTimestamp updates only timestamp metadata
func (*TestRepository) WriteRoot ¶ added in v2.5.0
func (r *TestRepository) WriteRoot(version int) error
WriteRoot writes root metadata to the metadata directory