aboutsummaryrefslogtreecommitdiff
path: root/instance_test.go
diff options
context:
space:
mode:
authorRasmus Dahlberg <rasmus.dahlberg@kau.se>2021-02-17 19:58:27 +0100
committerRasmus Dahlberg <rasmus.dahlberg@kau.se>2021-02-17 19:58:27 +0100
commit238518951868db81cd3a004e5c3f0b99f8e82b06 (patch)
tree1df8e71e869272bc5324e7412eab9236276f3548 /instance_test.go
parent72c8492ee1bd07d5960c9920e51b7addac11b806 (diff)
added basic server-side cosigning (work in progress)
Diffstat (limited to 'instance_test.go')
-rw-r--r--instance_test.go61
1 files changed, 37 insertions, 24 deletions
diff --git a/instance_test.go b/instance_test.go
index 3e55b5b..50302fb 100644
--- a/instance_test.go
+++ b/instance_test.go
@@ -32,20 +32,23 @@ var (
}
testIndex = uint64(0)
testHashLen = 31
- testDeadline = time.Second * 10
+ testDeadline = time.Second * 5
+ testInterval = time.Second * 10
)
+// TestNewLogParamters checks that invalid ones are rejected and that a valid
+// set of parameters are accepted.
func TestNewLogParameters(t *testing.T) {
testLogId := mustNewNamespaceEd25519V1(t, testdata.Ed25519Vk3)
namespaces := mustNewNamespacePool(t, []*namespace.Namespace{
mustNewNamespaceEd25519V1(t, testdata.Ed25519Vk),
})
+ witnesses := mustNewNamespacePool(t, []*namespace.Namespace{})
signer := ed25519.PrivateKey(testdata.Ed25519Sk)
for _, table := range []struct {
description string
logId *namespace.Namespace
maxRange int64
- namespaces *namespace.NamespacePool
signer crypto.Signer
wantErr bool
}{
@@ -53,7 +56,6 @@ func TestNewLogParameters(t *testing.T) {
description: "invalid signer: nil",
logId: testLogId,
maxRange: testMaxRange,
- namespaces: namespaces,
signer: nil,
wantErr: true,
},
@@ -61,15 +63,6 @@ func TestNewLogParameters(t *testing.T) {
description: "invalid max range",
logId: testLogId,
maxRange: 0,
- namespaces: namespaces,
- signer: signer,
- wantErr: true,
- },
- {
- description: "no namespaces",
- logId: testLogId,
- maxRange: testMaxRange,
- namespaces: mustNewNamespacePool(t, []*namespace.Namespace{}),
signer: signer,
wantErr: true,
},
@@ -81,20 +74,18 @@ func TestNewLogParameters(t *testing.T) {
Namespace: make([]byte, 31), // too short
},
},
- maxRange: testMaxRange,
- namespaces: namespaces,
- signer: signer,
- wantErr: true,
+ maxRange: testMaxRange,
+ signer: signer,
+ wantErr: true,
},
{
description: "valid log parameters",
logId: testLogId,
maxRange: testMaxRange,
- namespaces: namespaces,
signer: signer,
},
} {
- lp, err := NewLogParameters(table.signer, table.logId, testTreeId, testPrefix, table.namespaces, table.maxRange)
+ lp, err := NewLogParameters(table.signer, table.logId, testTreeId, testPrefix, namespaces, witnesses, table.maxRange, testInterval, testDeadline)
if got, want := err != nil, table.wantErr; got != want {
t.Errorf("got error=%v but wanted %v in test %q: %v", got, want, table.description, err)
}
@@ -118,7 +109,10 @@ func TestNewLogParameters(t *testing.T) {
if got, want := lp.MaxRange, testMaxRange; got != want {
t.Errorf("got max range %d but wanted %d in test %q", got, want, table.description)
}
- if got, want := len(lp.Namespaces.List()), len(namespaces.List()); got != want {
+ if got, want := len(lp.Submitters.List()), len(namespaces.List()); got != want {
+ t.Errorf("got %d anchors but wanted %d in test %q", got, want, table.description)
+ }
+ if got, want := len(lp.Witnesses.List()), len(witnesses.List()); got != want {
t.Errorf("got %d anchors but wanted %d in test %q", got, want, table.description)
}
}
@@ -134,8 +128,11 @@ func TestHandlers(t *testing.T) {
EndpointGetProofByHash: false,
EndpointGetConsistencyProof: false,
EndpointGetAnchors: false,
+ EndpointGetStableSth: false,
+ EndpointGetCosi: false,
+ EndpointAddCosi: false,
}
- i := NewInstance(makeTestLogParameters(t, nil), nil, testDeadline)
+ i := NewInstance(makeTestLogParameters(t, nil), nil, nil)
for _, handler := range i.Handlers() {
if _, ok := endpoints[handler.endpoint]; !ok {
t.Errorf("got unexpected endpoint: %s", handler.endpoint)
@@ -149,6 +146,7 @@ func TestHandlers(t *testing.T) {
}
}
+// TestEndpointPath checks that the endpoint path builder works as expected
func TestEndpointPath(t *testing.T) {
base, prefix := "http://example.com", "test"
for _, table := range []struct {
@@ -179,6 +177,18 @@ func TestEndpointPath(t *testing.T) {
endpoint: EndpointGetAnchors,
want: "http://example.com/test/get-anchors",
},
+ {
+ endpoint: EndpointGetStableSth,
+ want: "http://example.com/test/get-stable-sth",
+ },
+ {
+ endpoint: EndpointGetCosi,
+ want: "http://example.com/test/get-cosi",
+ },
+ {
+ endpoint: EndpointAddCosi,
+ want: "http://example.com/test/add-cosi",
+ },
} {
if got, want := table.endpoint.Path(base, prefix), table.want; got != want {
t.Errorf("got %s but wanted %s with multiple components", got, want)
@@ -216,8 +226,9 @@ func mustNewNamespacePool(t *testing.T, anchors []*namespace.Namespace) *namespa
// makeTestLogParameters makes a collection of test log parameters.
//
// The log's identity is based on testdata.Ed25519{Vk3,Sk3}. The log's accepted
-// namespaces is based on testdata.Ed25519{Vk,Vk2}. The remaining log
-// parameters are based on the global test* variables in this file.
+// submitters are based on testdata.Ed25519Vk. The log's accepted witnesses are
+// based on testdata.Ed25519Vk. The remaining log parameters are based on the
+// global test* variables in this file.
//
// For convenience the passed signer is optional (i.e., it may be nil).
func makeTestLogParameters(t *testing.T, signer crypto.Signer) *LogParameters {
@@ -226,9 +237,11 @@ func makeTestLogParameters(t *testing.T, signer crypto.Signer) *LogParameters {
TreeId: testTreeId,
Prefix: testPrefix,
MaxRange: testMaxRange,
- Namespaces: mustNewNamespacePool(t, []*namespace.Namespace{
+ Submitters: mustNewNamespacePool(t, []*namespace.Namespace{
+ mustNewNamespaceEd25519V1(t, testdata.Ed25519Vk),
+ }),
+ Witnesses: mustNewNamespacePool(t, []*namespace.Namespace{
mustNewNamespaceEd25519V1(t, testdata.Ed25519Vk),
- mustNewNamespaceEd25519V1(t, testdata.Ed25519Vk2),
}),
Signer: signer,
HashType: testHashType,