aboutsummaryrefslogtreecommitdiff
path: root/trillian_test.go
diff options
context:
space:
mode:
authorRasmus Dahlberg <rasmus.dahlberg@kau.se>2020-11-16 21:21:52 +0100
committerRasmus Dahlberg <rasmus.dahlberg@kau.se>2020-11-16 21:21:52 +0100
commitdef4ef7b3b47d955a9a4932549536f36aa6b4745 (patch)
treef794529be8444810993ec08782b225fa5fb8c4b1 /trillian_test.go
parent5496f081c1cbb9c9f92403a3023eaf6b393dad18 (diff)
fixed structure to include trillian_tests.go
Moved trillian test helpers and added TODO functions.
Diffstat (limited to 'trillian_test.go')
-rw-r--r--trillian_test.go115
1 files changed, 115 insertions, 0 deletions
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,
+ }
+}