testonly

package
v0.0.0-...-f1c747c Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2017 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package testonly holds test-specific code for Trillian storage layers.

Index

Constants

This section is empty.

Variables

View Source
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_RFC_6962,
		HashAlgorithm:      spb.DigitallySigned_SHA256,
		SignatureAlgorithm: spb.DigitallySigned_ECDSA,
		DisplayName:        "Llamas Log",
		Description:        "Registry of publicly-owned llamas",
		PrivateKey: mustMarshalAny(&keyspb.PEMKeyFile{
			Path:     ttestonly.RelativeToPackage("../../testdata/log-rpc-server.privkey.pem"),
			Password: "towel",
		}),
		PublicKey: &keyspb.PublicKey{
			Der: loadPublicPEMFileAsDER("../../testdata/log-rpc-server.pubkey.pem"),
		},
	}

	// MapTree is a valid, MAP-type trillian.Tree for tests.
	MapTree = &trillian.Tree{
		TreeState:          trillian.TreeState_ACTIVE,
		TreeType:           trillian.TreeType_MAP,
		HashStrategy:       trillian.HashStrategy_RFC_6962,
		HashAlgorithm:      spb.DigitallySigned_SHA256,
		SignatureAlgorithm: spb.DigitallySigned_ECDSA,
		DisplayName:        "Llamas Map",
		Description:        "Key Transparency map for all your digital llama needs.",
		PrivateKey: mustMarshalAny(&keyspb.PEMKeyFile{
			Path:     ttestonly.RelativeToPackage("../../testdata/map-rpc-server.privkey.pem"),
			Password: "towel",
		}),
		PublicKey: &keyspb.PublicKey{
			Der: loadPublicPEMFileAsDER("../../testdata/map-rpc-server.pubkey.pem"),
		},
	}
)

Functions

func MustCreateNodeIDForTreeCoords

func MustCreateNodeIDForTreeCoords(depth, index int64, maxPathBits int) storage.NodeID

MustCreateNodeIDForTreeCoords creates a NodeID for the given position in the tree.

func NodeIDEq

func NodeIDEq(n storage.NodeID) gomock.Matcher

NodeIDEq returns a matcher that expects the specified NodeID.

func NodeSet

func NodeSet(nodes []storage.Node) gomock.Matcher

NodeSet returns a matcher that expects the given set of Nodes.

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

func (tester *AdminStorageTester) TestAdminTXClose(t *testing.T)

TestAdminTXClose verifies the behavior of Close() with and without explicit Commit() / Rollback() calls.

func (*AdminStorageTester) TestCreateTree

func (tester *AdminStorageTester) TestCreateTree(t *testing.T)

TestCreateTree tests AdminStorage Tree creation.

func (*AdminStorageTester) TestListTrees

func (tester *AdminStorageTester) TestListTrees(t *testing.T)

TestListTrees tests both ListTreeIDs and ListTrees.

func (*AdminStorageTester) TestUpdateTree

func (tester *AdminStorageTester) TestUpdateTree(t *testing.T)

TestUpdateTree tests AdminStorage Tree updates.

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

type LeafBatch struct {
	TreeRevision int64
	Leaves       []string
	ExpectedRoot []byte
}

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.

type NodeMapping

type NodeMapping struct {
	NodeID storage.NodeID
	Node   storage.Node
}

NodeMapping is a struct we use because we can't use NodeIDs as map keys. Callers pass this and FakeNodeReader internally manages derived keys.

Jump to

Keyboard shortcuts

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