Documentation ¶
Overview ¶
Package testonly holds test-specific code for Trillian storage layers.
Index ¶
- Variables
- func MustCreateNodeIDForTreeCoords(depth, index int64, maxPathBits int) storage.NodeID
- func NodeIDEq(n storage.NodeID) gomock.Matcher
- func NodeSet(nodes []storage.Node) gomock.Matcher
- func RunOnAdminTX(tx storage.AdminTX) func(ctx context.Context, f storage.AdminTXFunc) error
- func RunOnLogTX(tx storage.LogTreeTX) func(ctx context.Context, treeID int64, f storage.LogTXFunc) error
- func RunOnMapTX(tx storage.MapTreeTX) func(ctx context.Context, treeID int64, f storage.MapTXFunc) error
- type AdminStorageTester
- func (tester *AdminStorageTester) RunAllTests(t *testing.T)
- func (tester *AdminStorageTester) TestAdminTXReadWriteTransaction(t *testing.T)
- func (tester *AdminStorageTester) TestCreateTree(t *testing.T)
- func (tester *AdminStorageTester) TestHardDeleteTree(t *testing.T)
- func (tester *AdminStorageTester) TestHardDeleteTreeErrors(t *testing.T)
- func (tester *AdminStorageTester) TestListTrees(t *testing.T)
- func (tester *AdminStorageTester) TestSoftDeleteTree(t *testing.T)
- func (tester *AdminStorageTester) TestSoftDeleteTreeErrors(t *testing.T)
- func (tester *AdminStorageTester) TestUndeleteTree(t *testing.T)
- func (tester *AdminStorageTester) TestUndeleteTreeErrors(t *testing.T)
- func (tester *AdminStorageTester) TestUpdateTree(t *testing.T)
- type FakeAdminStorage
- func (f *FakeAdminStorage) Begin(ctx context.Context) (storage.AdminTX, error)
- func (f *FakeAdminStorage) CheckDatabaseAccessible(ctx context.Context) error
- func (f *FakeAdminStorage) ReadWriteTransaction(ctx context.Context, fn storage.AdminTXFunc) error
- func (f *FakeAdminStorage) Snapshot(ctx context.Context) (storage.ReadOnlyAdminTX, error)
- type FakeLogStorage
- func (f *FakeLogStorage) AddSequencedLeaves(ctx context.Context, tree *trillian.Tree, leaves []*trillian.LogLeaf, ...) ([]*trillian.QueuedLogLeaf, error)
- func (f *FakeLogStorage) CheckDatabaseAccessible(ctx context.Context) error
- func (f *FakeLogStorage) QueueLeaves(ctx context.Context, tree *trillian.Tree, leaves []*trillian.LogLeaf, ...) ([]*trillian.QueuedLogLeaf, error)
- func (f *FakeLogStorage) ReadWriteTransaction(ctx context.Context, tree *trillian.Tree, fn storage.LogTXFunc) error
- func (f *FakeLogStorage) Snapshot(ctx context.Context) (storage.ReadOnlyLogTX, error)
- func (f *FakeLogStorage) SnapshotForTree(ctx context.Context, _ *trillian.Tree) (storage.ReadOnlyLogTreeTX, error)
- type FakeMapStorage
- func (f *FakeMapStorage) CheckDatabaseAccessible(ctx context.Context) error
- func (f *FakeMapStorage) ReadWriteTransaction(ctx context.Context, tree *trillian.Tree, fn storage.MapTXFunc) error
- func (f *FakeMapStorage) Snapshot(ctx context.Context) (storage.ReadOnlyMapTX, error)
- func (f *FakeMapStorage) SnapshotForTree(ctx context.Context, _ *trillian.Tree) (storage.ReadOnlyMapTreeTX, error)
- type FakeNodeReader
- type LeafBatch
- type MultiFakeNodeReader
- type NodeMapping
Constants ¶
This section is empty.
Variables ¶
var ( // LogTree is a valid, LOG-type trillian.Tree for tests. LogTree = &trillian.Tree{ TreeState: trillian.TreeState_ACTIVE, TreeType: trillian.TreeType_LOG, HashStrategy: trillian.HashStrategy_RFC6962_SHA256, HashAlgorithm: spb.DigitallySigned_SHA256, SignatureAlgorithm: spb.DigitallySigned_ECDSA, DisplayName: "Llamas Log", Description: "Registry of publicly-owned llamas", PrivateKey: mustMarshalAny(&keyspb.PrivateKey{ Der: ktestonly.MustMarshalPrivatePEMToDER(privateKeyPEM, privateKeyPass), }), PublicKey: &keyspb.PublicKey{ Der: ktestonly.MustMarshalPublicPEMToDER(publicKeyPEM), }, MaxRootDuration: ptypes.DurationProto(0 * time.Millisecond), } // LogTreeEmptyRootHash is the root hash of LogTree when empty. LogTreeEmptyRootHash = func() []byte { hasher, err := hash(LogTree) if err != nil { panic(err) } return hasher.New().Sum(nil) }() // PreorderedLogTree is a valid, PREORDERED_LOG-type trillian.Tree for tests. PreorderedLogTree = &trillian.Tree{ TreeState: trillian.TreeState_ACTIVE, TreeType: trillian.TreeType_PREORDERED_LOG, HashStrategy: trillian.HashStrategy_RFC6962_SHA256, HashAlgorithm: spb.DigitallySigned_SHA256, SignatureAlgorithm: spb.DigitallySigned_ECDSA, DisplayName: "Pre-ordered Log", Description: "Mirror registry of publicly-owned llamas", PrivateKey: mustMarshalAny(&keyspb.PrivateKey{ Der: ktestonly.MustMarshalPrivatePEMToDER(privateKeyPEM, privateKeyPass), }), PublicKey: &keyspb.PublicKey{ Der: ktestonly.MustMarshalPublicPEMToDER(publicKeyPEM), }, MaxRootDuration: ptypes.DurationProto(0 * time.Millisecond), } // MapTree is a valid, MAP-type trillian.Tree for tests. MapTree = &trillian.Tree{ TreeState: trillian.TreeState_ACTIVE, TreeType: trillian.TreeType_MAP, HashStrategy: trillian.HashStrategy_TEST_MAP_HASHER, HashAlgorithm: spb.DigitallySigned_SHA256, SignatureAlgorithm: spb.DigitallySigned_ECDSA, DisplayName: "Llamas Map", Description: "Key Transparency map for all your digital llama needs.", PrivateKey: mustMarshalAny(&keyspb.PrivateKey{ Der: ktestonly.MustMarshalPrivatePEMToDER(testonly.DemoPrivateKey, testonly.DemoPrivateKeyPass), }), PublicKey: &keyspb.PublicKey{ Der: ktestonly.MustMarshalPublicPEMToDER(testonly.DemoPublicKey), }, MaxRootDuration: ptypes.DurationProto(0 * time.Millisecond), } // MapTreeEmptyRootHash is the root hash of MapTree when 'empty' (i.e. no leaves are set). MapTreeEmptyRootHash = func() []byte { hasher, err := hash(MapTree) if err != nil { panic(err) } mh := maphasher.New(hasher) return mh.HashEmpty(0, nil, mh.BitLen()) }() )
var ErrNotImplemented = errors.New("not implemented")
ErrNotImplemented is returned by unimplemented methods on the storage fakes.
Functions ¶
func MustCreateNodeIDForTreeCoords ¶
MustCreateNodeIDForTreeCoords creates a NodeID for the given position in the tree.
func RunOnAdminTX ¶ added in v1.0.7
RunOnAdminTX is a helper for mocking out the AdminStorage.ReadWriteTransaction method.
Types ¶
type AdminStorageTester ¶
type AdminStorageTester struct { // NewAdminStorage returns an AdminStorage instance pointing to a clean // test database. NewAdminStorage func() storage.AdminStorage }
AdminStorageTester runs a suite of tests against AdminStorage implementations.
func (*AdminStorageTester) RunAllTests ¶
func (tester *AdminStorageTester) RunAllTests(t *testing.T)
RunAllTests runs all AdminStorage tests.
func (*AdminStorageTester) TestAdminTXReadWriteTransaction ¶ added in v1.0.7
func (tester *AdminStorageTester) TestAdminTXReadWriteTransaction(t *testing.T)
TestAdminTXReadWriteTransaction tests the ReadWriteTransaction method on AdminStorage.
func (*AdminStorageTester) TestCreateTree ¶
func (tester *AdminStorageTester) TestCreateTree(t *testing.T)
TestCreateTree tests AdminStorage Tree creation.
func (*AdminStorageTester) TestHardDeleteTree ¶
func (tester *AdminStorageTester) TestHardDeleteTree(t *testing.T)
TestHardDeleteTree tests success scenarios of HardDeleteTree.
func (*AdminStorageTester) TestHardDeleteTreeErrors ¶
func (tester *AdminStorageTester) TestHardDeleteTreeErrors(t *testing.T)
TestHardDeleteTreeErrors tests error scenarios of HardDeleteTree.
func (*AdminStorageTester) TestListTrees ¶
func (tester *AdminStorageTester) TestListTrees(t *testing.T)
TestListTrees tests both ListTreeIDs and ListTrees.
func (*AdminStorageTester) TestSoftDeleteTree ¶
func (tester *AdminStorageTester) TestSoftDeleteTree(t *testing.T)
TestSoftDeleteTree tests success scenarios of SoftDeleteTree.
func (*AdminStorageTester) TestSoftDeleteTreeErrors ¶
func (tester *AdminStorageTester) TestSoftDeleteTreeErrors(t *testing.T)
TestSoftDeleteTreeErrors tests error scenarios of SoftDeleteTree.
func (*AdminStorageTester) TestUndeleteTree ¶
func (tester *AdminStorageTester) TestUndeleteTree(t *testing.T)
TestUndeleteTree tests success scenarios of UndeleteTree.
func (*AdminStorageTester) TestUndeleteTreeErrors ¶
func (tester *AdminStorageTester) TestUndeleteTreeErrors(t *testing.T)
TestUndeleteTreeErrors tests error scenarios of UndeleteTree.
func (*AdminStorageTester) TestUpdateTree ¶
func (tester *AdminStorageTester) TestUpdateTree(t *testing.T)
TestUpdateTree tests AdminStorage Tree updates.
type FakeAdminStorage ¶ added in v1.0.7
type FakeAdminStorage struct { TX []storage.AdminTX ReadOnlyTX []storage.ReadOnlyAdminTX TXErr []error SnapshotErr []error }
FakeAdminStorage is a AdminStorage implementation which is used for testing.
func (*FakeAdminStorage) CheckDatabaseAccessible ¶ added in v1.0.7
func (f *FakeAdminStorage) CheckDatabaseAccessible(ctx context.Context) error
CheckDatabaseAccessible implements AdminStorage.CheckDatabaseAccessible
func (*FakeAdminStorage) ReadWriteTransaction ¶ added in v1.0.7
func (f *FakeAdminStorage) ReadWriteTransaction(ctx context.Context, fn storage.AdminTXFunc) error
ReadWriteTransaction implements AdminStorage.ReadWriteTransaction
func (*FakeAdminStorage) Snapshot ¶ added in v1.0.7
func (f *FakeAdminStorage) Snapshot(ctx context.Context) (storage.ReadOnlyAdminTX, error)
Snapshot implements AdminStorage.Snapshot
type FakeLogStorage ¶ added in v1.0.7
type FakeLogStorage struct { TX storage.LogTreeTX ReadOnlyTX storage.ReadOnlyLogTreeTX TXErr error QueueLeavesErr error AddSequencedLeavesErr error }
FakeLogStorage is a LogStorage implementation which is used for testing.
func (*FakeLogStorage) AddSequencedLeaves ¶ added in v1.0.7
func (f *FakeLogStorage) AddSequencedLeaves(ctx context.Context, tree *trillian.Tree, leaves []*trillian.LogLeaf, timestamp time.Time) ([]*trillian.QueuedLogLeaf, error)
AddSequencedLeaves implements LogStorage.AddSequencedLeaves.
func (*FakeLogStorage) CheckDatabaseAccessible ¶ added in v1.0.7
func (f *FakeLogStorage) CheckDatabaseAccessible(ctx context.Context) error
CheckDatabaseAccessible implements LogStorage.CheckDatabaseAccessible
func (*FakeLogStorage) QueueLeaves ¶ added in v1.0.7
func (f *FakeLogStorage) QueueLeaves(ctx context.Context, tree *trillian.Tree, leaves []*trillian.LogLeaf, queueTimestamp time.Time) ([]*trillian.QueuedLogLeaf, error)
QueueLeaves implements LogStorage.QueueLeaves.
func (*FakeLogStorage) ReadWriteTransaction ¶ added in v1.0.7
func (f *FakeLogStorage) ReadWriteTransaction(ctx context.Context, tree *trillian.Tree, fn storage.LogTXFunc) error
ReadWriteTransaction implements LogStorage.ReadWriteTransaction
func (*FakeLogStorage) Snapshot ¶ added in v1.0.7
func (f *FakeLogStorage) Snapshot(ctx context.Context) (storage.ReadOnlyLogTX, error)
Snapshot implements LogStorage.Snapshot
func (*FakeLogStorage) SnapshotForTree ¶ added in v1.0.7
func (f *FakeLogStorage) SnapshotForTree(ctx context.Context, _ *trillian.Tree) (storage.ReadOnlyLogTreeTX, error)
SnapshotForTree implements LogStorage.SnapshotForTree
type FakeMapStorage ¶ added in v1.0.7
type FakeMapStorage struct { TX storage.MapTreeTX ReadOnlyTX storage.ReadOnlyMapTreeTX SnapshotErr error }
FakeMapStorage is a MapStorage implementation which is used for testing.
func (*FakeMapStorage) CheckDatabaseAccessible ¶ added in v1.0.7
func (f *FakeMapStorage) CheckDatabaseAccessible(ctx context.Context) error
CheckDatabaseAccessible implements MapStorage.CheckDatabaseAccessible
func (*FakeMapStorage) ReadWriteTransaction ¶ added in v1.0.7
func (f *FakeMapStorage) ReadWriteTransaction(ctx context.Context, tree *trillian.Tree, fn storage.MapTXFunc) error
ReadWriteTransaction implements MapStorage.ReadWriteTransaction
func (*FakeMapStorage) Snapshot ¶ added in v1.0.7
func (f *FakeMapStorage) Snapshot(ctx context.Context) (storage.ReadOnlyMapTX, error)
Snapshot implements MapStorage.Snapshot
func (*FakeMapStorage) SnapshotForTree ¶ added in v1.0.7
func (f *FakeMapStorage) SnapshotForTree(ctx context.Context, _ *trillian.Tree) (storage.ReadOnlyMapTreeTX, error)
SnapshotForTree implements MapStorage.SnapshotForTree
type FakeNodeReader ¶
type FakeNodeReader struct {
// contains filtered or unexported fields
}
FakeNodeReader is an implementation of storage.NodeReader that's preloaded with a set of NodeID -> Node mappings and will return only those. Requesting any other nodes results in an error. For use in tests only, does not implement any other storage APIs.
func NewFakeNodeReader ¶
func NewFakeNodeReader(mappings []NodeMapping, treeSize, treeRevision int64) *FakeNodeReader
NewFakeNodeReader creates and returns a FakeNodeReader with the supplied nodeID -> Node mappings assuming that all the nodes are at a specified tree revision. All the nodeIDs must be distinct.
func (FakeNodeReader) GetMerkleNodes ¶
func (f FakeNodeReader) GetMerkleNodes(treeRevision int64, NodeIDs []storage.NodeID) ([]storage.Node, error)
GetMerkleNodes implements the corresponding NodeReader API.
func (FakeNodeReader) GetTreeRevisionIncludingSize ¶
func (f FakeNodeReader) GetTreeRevisionIncludingSize(treeSize int64) (int64, error)
GetTreeRevisionIncludingSize implements the corresponding NodeReader API.
type LeafBatch ¶
LeafBatch describes a set of leaves to be loaded into a MultiFakeNodeReader via a compact merkle tree. As each batch is added to the tree a set of node updates are collected and recorded in a FakeNodeReader for that revision. The expected root should be the result of calling CurrentRoot() on the compact Merkle tree encoded by hex.EncodeToString().
type MultiFakeNodeReader ¶
type MultiFakeNodeReader struct {
// contains filtered or unexported fields
}
MultiFakeNodeReader can provide nodes at multiple revisions. It delegates to a number of FakeNodeReaders, each set up to handle one revision.
func NewMultiFakeNodeReader ¶
func NewMultiFakeNodeReader(readers []FakeNodeReader) *MultiFakeNodeReader
NewMultiFakeNodeReader creates a MultiFakeNodeReader delegating to a number of FakeNodeReaders
func NewMultiFakeNodeReaderFromLeaves ¶
func NewMultiFakeNodeReaderFromLeaves(batches []LeafBatch) *MultiFakeNodeReader
NewMultiFakeNodeReaderFromLeaves uses a compact Merkle tree to set up the nodes at various revisions. It collates all node updates from a batch of leaf data into one FakeNodeReader. This has the advantage of not needing to manually create all the data structures but the disadvantage is that a bug in the compact tree could be reflected in test using this code. To help guard against this we check the tree root hash after each batch has been processed. The supplied batches should be in ascending order of tree revision.
func (MultiFakeNodeReader) GetMerkleNodes ¶
func (m MultiFakeNodeReader) GetMerkleNodes(ctx context.Context, treeRevision int64, NodeIDs []storage.NodeID) ([]storage.Node, error)
GetMerkleNodes implements the corresponding NodeReader API.
func (MultiFakeNodeReader) GetTreeRevisionIncludingSize ¶
func (m MultiFakeNodeReader) GetTreeRevisionIncludingSize(treeSize int64) (int64, int64, error)
GetTreeRevisionIncludingSize implements the corresponding NodeReader API.