aboutsummaryrefslogtreecommitdiff
path: root/pkg/instance
diff options
context:
space:
mode:
authorRasmus Dahlberg <rasmus@mullvad.net>2022-01-25 01:06:54 +0100
committerRasmus Dahlberg <rasmus@mullvad.net>2022-01-26 01:17:24 +0100
commitdf8455a97090cb06e26a881162b86887c4dfcca5 (patch)
tree3e1b9a66736a693f2da9f5cdbb581620e77d7687 /pkg/instance
parenta8df88efdb0adf014e524c813193228d06e9ac6a (diff)
instance: Use the new tree-head endpoints
Diffstat (limited to 'pkg/instance')
-rw-r--r--pkg/instance/experimental.go2
-rw-r--r--pkg/instance/handler.go21
-rw-r--r--pkg/instance/handler_test.go56
-rw-r--r--pkg/instance/instance.go3
4 files changed, 10 insertions, 72 deletions
diff --git a/pkg/instance/experimental.go b/pkg/instance/experimental.go
index ab81ada..5dab870 100644
--- a/pkg/instance/experimental.go
+++ b/pkg/instance/experimental.go
@@ -22,7 +22,7 @@ const algEd25519 byte = 1
// Sigsum API. Documentation can be found in the transparency-dev repo.
func getCheckpoint(ctx context.Context, i *Instance, w http.ResponseWriter, r *http.Request) (int, error) {
glog.V(3).Info("handling get-checkpoint request")
- sth, err := i.Stateman.ToSign(ctx)
+ sth, err := i.Stateman.ToCosignTreeHead(ctx)
if err != nil {
return http.StatusInternalServerError, err
}
diff --git a/pkg/instance/handler.go b/pkg/instance/handler.go
index 66a20a5..f2bc621 100644
--- a/pkg/instance/handler.go
+++ b/pkg/instance/handler.go
@@ -79,21 +79,9 @@ func addCosignature(ctx context.Context, i *Instance, w http.ResponseWriter, r *
return http.StatusOK, nil
}
-func getTreeHeadLatest(ctx context.Context, i *Instance, w http.ResponseWriter, _ *http.Request) (int, error) {
- glog.V(3).Info("handling get-tree-head-latest request")
- sth, err := i.Stateman.Latest(ctx)
- if err != nil {
- return http.StatusInternalServerError, err
- }
- if err := sth.ToASCII(w); err != nil {
- return http.StatusInternalServerError, err
- }
- return http.StatusOK, nil
-}
-
-func getTreeHeadToSign(ctx context.Context, i *Instance, w http.ResponseWriter, _ *http.Request) (int, error) {
+func getTreeHeadToCosign(ctx context.Context, i *Instance, w http.ResponseWriter, _ *http.Request) (int, error) {
glog.V(3).Info("handling get-tree-head-to-sign request")
- sth, err := i.Stateman.ToSign(ctx)
+ sth, err := i.Stateman.ToCosignTreeHead(ctx)
if err != nil {
return http.StatusInternalServerError, err
}
@@ -105,7 +93,7 @@ func getTreeHeadToSign(ctx context.Context, i *Instance, w http.ResponseWriter,
func getTreeHeadCosigned(ctx context.Context, i *Instance, w http.ResponseWriter, _ *http.Request) (int, error) {
glog.V(3).Info("handling get-tree-head-cosigned request")
- cth, err := i.Stateman.Cosigned(ctx)
+ cth, err := i.Stateman.CosignedTreeHead(ctx)
if err != nil {
return http.StatusInternalServerError, err
}
@@ -121,6 +109,7 @@ func getConsistencyProof(ctx context.Context, i *Instance, w http.ResponseWriter
if err != nil {
return http.StatusBadRequest, err
}
+ // XXX: check tree size of latest thing we signed?
proof, err := i.Client.GetConsistencyProof(ctx, req)
if err != nil {
@@ -138,6 +127,7 @@ func getInclusionProof(ctx context.Context, i *Instance, w http.ResponseWriter,
if err != nil {
return http.StatusBadRequest, err
}
+ // XXX: check tree size of latest thing we signed?
proof, err := i.Client.GetInclusionProof(ctx, req)
if err != nil {
@@ -155,6 +145,7 @@ func getLeaves(ctx context.Context, i *Instance, w http.ResponseWriter, r *http.
if err != nil {
return http.StatusBadRequest, err
}
+ // XXX: check tree size of latest thing we signed?
leaves, err := i.Client.GetLeaves(ctx, req)
if err != nil {
diff --git a/pkg/instance/handler_test.go b/pkg/instance/handler_test.go
index ba5b60c..f8817dc 100644
--- a/pkg/instance/handler_test.go
+++ b/pkg/instance/handler_test.go
@@ -53,7 +53,6 @@ func TestHandlers(t *testing.T) {
endpoints := map[types.Endpoint]bool{
types.EndpointAddLeaf: false,
types.EndpointAddCosignature: false,
- types.EndpointGetTreeHeadLatest: false,
types.EndpointGetTreeHeadToSign: false,
types.EndpointGetTreeHeadCosigned: false,
types.EndpointGetConsistencyProof: false,
@@ -296,57 +295,6 @@ func TestAddCosignature(t *testing.T) {
}
}
-func TestGetTreeHeadLatest(t *testing.T) {
- for _, table := range []struct {
- description string
- expect bool // set if a mock answer is expected
- rsp *types.SignedTreeHead // signed tree head from Trillian client
- err error // error from Trillian client
- wantCode int // HTTP status ok
- }{
- {
- description: "invalid: backend failure",
- expect: true,
- err: fmt.Errorf("something went wrong"),
- wantCode: http.StatusInternalServerError,
- },
- {
- description: "valid",
- expect: true,
- rsp: testSTH,
- wantCode: http.StatusOK,
- },
- } {
- // Run deferred functions at the end of each iteration
- func() {
- ctrl := gomock.NewController(t)
- defer ctrl.Finish()
- stateman := mocksState.NewMockStateManager(ctrl)
- if table.expect {
- stateman.EXPECT().Latest(gomock.Any()).Return(table.rsp, table.err)
- }
- i := Instance{
- Config: testConfig,
- Stateman: stateman,
- }
-
- // Create HTTP request
- url := types.EndpointGetTreeHeadLatest.Path("http://example.com", i.Prefix)
- req, err := http.NewRequest("GET", url, nil)
- if err != nil {
- t.Fatalf("must create http request: %v", err)
- }
-
- // Run HTTP request
- w := httptest.NewRecorder()
- mustHandle(t, i, types.EndpointGetTreeHeadLatest).ServeHTTP(w, req)
- if got, want := w.Code, table.wantCode; got != want {
- t.Errorf("got HTTP status code %v but wanted %v in test %q", got, want, table.description)
- }
- }()
- }
-}
-
func TestGetTreeToSign(t *testing.T) {
for _, table := range []struct {
description string
@@ -374,7 +322,7 @@ func TestGetTreeToSign(t *testing.T) {
defer ctrl.Finish()
stateman := mocksState.NewMockStateManager(ctrl)
if table.expect {
- stateman.EXPECT().ToSign(gomock.Any()).Return(table.rsp, table.err)
+ stateman.EXPECT().ToCosignTreeHead(gomock.Any()).Return(table.rsp, table.err)
}
i := Instance{
Config: testConfig,
@@ -425,7 +373,7 @@ func TestGetTreeCosigned(t *testing.T) {
defer ctrl.Finish()
stateman := mocksState.NewMockStateManager(ctrl)
if table.expect {
- stateman.EXPECT().Cosigned(gomock.Any()).Return(table.rsp, table.err)
+ stateman.EXPECT().CosignedTreeHead(gomock.Any()).Return(table.rsp, table.err)
}
i := Instance{
Config: testConfig,
diff --git a/pkg/instance/instance.go b/pkg/instance/instance.go
index 9f71aa3..bbd6cde 100644
--- a/pkg/instance/instance.go
+++ b/pkg/instance/instance.go
@@ -42,8 +42,7 @@ func (i *Instance) Handlers() []Handler {
return []Handler{
Handler{Instance: i, Handler: addLeaf, Endpoint: types.EndpointAddLeaf, Method: http.MethodPost},
Handler{Instance: i, Handler: addCosignature, Endpoint: types.EndpointAddCosignature, Method: http.MethodPost},
- Handler{Instance: i, Handler: getTreeHeadLatest, Endpoint: types.EndpointGetTreeHeadLatest, Method: http.MethodGet},
- Handler{Instance: i, Handler: getTreeHeadToSign, Endpoint: types.EndpointGetTreeHeadToSign, Method: http.MethodGet},
+ Handler{Instance: i, Handler: getTreeHeadToCosign, Endpoint: types.EndpointGetTreeHeadToSign, Method: http.MethodGet}, // XXX: ToCosign
Handler{Instance: i, Handler: getTreeHeadCosigned, Endpoint: types.EndpointGetTreeHeadCosigned, Method: http.MethodGet},
Handler{Instance: i, Handler: getCheckpoint, Endpoint: types.Endpoint("get-checkpoint"), Method: http.MethodGet},
Handler{Instance: i, Handler: getConsistencyProof, Endpoint: types.EndpointGetConsistencyProof, Method: http.MethodPost},