diff options
| author | Rasmus Dahlberg <rasmus.dahlberg@kau.se> | 2020-11-16 21:21:52 +0100 | 
|---|---|---|
| committer | Rasmus Dahlberg <rasmus.dahlberg@kau.se> | 2020-11-16 21:21:52 +0100 | 
| commit | def4ef7b3b47d955a9a4932549536f36aa6b4745 (patch) | |
| tree | f794529be8444810993ec08782b225fa5fb8c4b1 | |
| parent | 5496f081c1cbb9c9f92403a3023eaf6b393dad18 (diff) | |
fixed structure to include trillian_tests.go
Moved trillian test helpers and added TODO functions.
| -rw-r--r-- | handler_test.go | 70 | ||||
| -rw-r--r-- | trillian_test.go | 115 | 
2 files changed, 115 insertions, 70 deletions
| diff --git a/handler_test.go b/handler_test.go index 87f06a2..277c74f 100644 --- a/handler_test.go +++ b/handler_test.go @@ -22,9 +22,6 @@ import (  	"github.com/google/trillian"  	"github.com/system-transparency/stfe/server/testdata"  	"github.com/system-transparency/stfe/x509util" - -	"google.golang.org/grpc/codes" -	"google.golang.org/grpc/status"  )  type testHandler struct { @@ -776,70 +773,3 @@ func makeTestLeafBuffer(t *testing.T, name, pemChain, pemKey []byte, valid bool)  	}  	return bytes.NewBuffer(data)  } - -// makeTrillianQueueLeafResponse creates a valid trillian QueueLeafResponse -func makeTrillianQueueLeafResponse(t *testing.T, name, pemChain, pemKey []byte) *trillian.QueueLeafResponse { -	t.Helper() -	leaf, appendix := makeTestLeaf(t, name, pemChain, pemKey) -	return &trillian.QueueLeafResponse{ -		QueuedLeaf: &trillian.QueuedLogLeaf{ -			Leaf: &trillian.LogLeaf{ -				MerkleLeafHash:   nil, // not used by stfe -				LeafValue:        leaf, -				ExtraData:        appendix, -				LeafIndex:        0,   // not applicable (log is not pre-ordered) -				LeafIdentityHash: nil, // not used by stfe -			}, -			Status: status.New(codes.OK, "ok").Proto(), -		}, -	} -} - -// makeTrillianGetInclusionProofByHashResponse -func makeTrillianGetInclusionProofByHashResponse(t *testing.T, index int64, path [][]byte) *trillian.GetInclusionProofByHashResponse { -	t.Helper() -	return &trillian.GetInclusionProofByHashResponse{ -		Proof: []*trillian.Proof{ -			&trillian.Proof{ -				LeafIndex: index, -				Hashes:    path, -			}, -		}, -		SignedLogRoot: nil, // not used by stfe -	} -} - -// makeTrillianGetInclusionProofByHashResponse -func makeTrillianGetConsistencyProofResponse(t *testing.T, path [][]byte) *trillian.GetConsistencyProofResponse { -	t.Helper() -	return &trillian.GetConsistencyProofResponse{ -		Proof: &trillian.Proof{ -			LeafIndex: 0, // not used by consistency proofs -			Hashes:    path, -		}, -		SignedLogRoot: nil, // not used by stfe -	} -} - -// makeTrillianGetLeavesByRangeResponse -func makeTrillianGetLeavesByRangeResponse(t *testing.T, start, end int64, name, pemChain, pemKey []byte, valid bool) *trillian.GetLeavesByRangeResponse { -	t.Helper() -	leaves := make([]*trillian.LogLeaf, 0, start-end+1) -	for i, n := start, end+1; i < n; i++ { -		leaf, appendix := makeTestLeaf(t, append(name, []byte(fmt.Sprintf("_%d", i))...), pemChain, pemKey) -		if !valid { -			appendix = []byte{0, 1, 2, 3} -		} -		leaves = append(leaves, &trillian.LogLeaf{ -			MerkleLeafHash:   nil, // not used by stfe -			LeafValue:        leaf, -			ExtraData:        appendix, -			LeafIndex:        i, -			LeafIdentityHash: nil, // not used by stfe -		}) -	} -	return &trillian.GetLeavesByRangeResponse{ -		Leaves:        leaves, -		SignedLogRoot: testdata.NewGetLatestSignedLogRootResponse(t, 0, uint64(end)+1, make([]byte, 32)).SignedLogRoot, -	} -} diff --git a/trillian_test.go b/trillian_test.go new file mode 100644 index 0000000..66ad647 --- /dev/null +++ b/trillian_test.go @@ -0,0 +1,115 @@ +package stfe + +import ( +	"testing" +	"fmt" + +	"github.com/google/trillian" +	"github.com/system-transparency/stfe/server/testdata" + +	"google.golang.org/grpc/codes" +	"google.golang.org/grpc/status" +) + +// TODO: TestCheckQueueLeaf +func TestCheckQueueLeaf(t *testing.T) { +} + +// TODO: TestCheckGetLeavesByRange +func TestCheckGetLeavesByRange(t *testing.T) { +} + +// TODO: TestCheckGetInclusionProofByHash +func TestCheckGetInclusionProofByHash(t *testing.T) { +} + +// TODO: TestGetConsistencyProof +func TestCheckGetConsistencyProof(t *testing.T) { +} + +// TODO: TestCheckGetLatestSignedLogRoot +func TestCheckGetLatestSignedLogRoot(t *testing.T) { +} + + +// makeTrillianQueueLeafResponse creates a valid trillian QueueLeafResponse +// for a package `name` where the checksum is all zeros (32 bytes).  The pemKey +// is a PEM-encoded ed25519 signing key, and pemChain its certificate chain. +// +// Note: MerkleLeafHash and LeafIdentityHash are unset (not used by stfe). +func makeTrillianQueueLeafResponse(t *testing.T, name, pemChain, pemKey []byte) *trillian.QueueLeafResponse { +	t.Helper() +	leaf, appendix := makeTestLeaf(t, name, pemChain, pemKey) +	return &trillian.QueueLeafResponse{ +		QueuedLeaf: &trillian.QueuedLogLeaf{ +			Leaf: &trillian.LogLeaf{ +				MerkleLeafHash:   nil, // not used by stfe +				LeafValue:        leaf, +				ExtraData:        appendix, +				LeafIndex:        0,   // not applicable (log is not pre-ordered) +				LeafIdentityHash: nil, // not used by stfe +			}, +			Status: status.New(codes.OK, "ok").Proto(), +		}, +	} +} + +// makeTrillianGetInclusionProofByHashResponse populates a get-proof-by-hash +// response. +// +// Note: SignedLogRoot is unset (not used by stfe). +func makeTrillianGetInclusionProofByHashResponse(t *testing.T, index int64, path [][]byte) *trillian.GetInclusionProofByHashResponse { +	t.Helper() +	return &trillian.GetInclusionProofByHashResponse{ +		Proof: []*trillian.Proof{ +			&trillian.Proof{ +				LeafIndex: index, +				Hashes:    path, +			}, +		}, +		SignedLogRoot: nil, +	} +} + +// makeTrillianGetConsistencyProofResponse populates a get-consistency response. +// +// Note: LeafIndex is not applicable for a consistency proof (0), and +// SignedLogRoot is unset (not used by stfe). +func makeTrillianGetConsistencyProofResponse(t *testing.T, path [][]byte) *trillian.GetConsistencyProofResponse { +	t.Helper() +	return &trillian.GetConsistencyProofResponse{ +		Proof: &trillian.Proof{ +			LeafIndex: 0, +			Hashes:    path, +		}, +		SignedLogRoot: nil, +	} +} + +// makeTrillianGetLeavesByRangeResponse creates a range of leaves [start,end] +// such that the package is `name`_<index> and the checksum is all zeros (32 +// bytes).  The pemKey is a PEM-encoded ed25519 signing key, and pemChain its +// certificate chain.  Set `valid` to false to make an invalid Appendix. +// +// Note: MerkleLeafHash and LeafIdentityHash are unset (not used by stfe). +func makeTrillianGetLeavesByRangeResponse(t *testing.T, start, end int64, name, pemChain, pemKey []byte, valid bool) *trillian.GetLeavesByRangeResponse { +	t.Helper() +	leaves := make([]*trillian.LogLeaf, 0, start-end+1) +	for i, n := start, end+1; i < n; i++ { +		leaf, appendix := makeTestLeaf(t, append(name, []byte(fmt.Sprintf("_%d", i))...), pemChain, pemKey) +		if !valid { +			appendix = []byte{0, 1, 2, 3} +		} +		leaves = append(leaves, &trillian.LogLeaf{ +			MerkleLeafHash:   nil, +			LeafValue:        leaf, +			ExtraData:        appendix, +			LeafIndex:        i, +			LeafIdentityHash: nil, +		}) +	} +	return &trillian.GetLeavesByRangeResponse{ +		Leaves:        leaves, +		SignedLogRoot: testdata.NewGetLatestSignedLogRootResponse(t, 0, uint64(end)+1, make([]byte, 32)).SignedLogRoot, +	} +} | 
