From c42378e477e547c9d427aae95e64155e0f7b2da3 Mon Sep 17 00:00:00 2001 From: Rasmus Dahlberg Date: Wed, 11 Nov 2020 16:10:41 +0100 Subject: added get-anchors handler tests --- handler_test.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/handler_test.go b/handler_test.go index 6a2e7d8..e1805fc 100644 --- a/handler_test.go +++ b/handler_test.go @@ -130,6 +130,36 @@ func TestPostHandlersRejectGet(t *testing.T) { } } +func TestGetAnchors(t *testing.T) { + th := newTestHandler(t, nil) + defer th.mockCtrl.Finish() + + url := "http://example.com" + th.instance.LogParameters.Prefix + "/get-anchors" + req, err := http.NewRequest("GET", url, nil) + if err != nil { + t.Fatalf("failed creating http request: %v", err) + } + + w := httptest.NewRecorder() + th.getHandler(t, "get-anchors").ServeHTTP(w, req) + if w.Code != http.StatusOK { + t.Errorf("GET(%s)=%d, want http status code %d", url, w.Code, http.StatusOK) + return + } + + var derAnchors [][]byte + if err := json.Unmarshal([]byte(w.Body.String()), &derAnchors); err != nil { + t.Errorf("failed unmarshaling trust anchors response: %v", err) + return + } + if got, want := len(derAnchors), len(th.instance.LogParameters.AnchorList); got != want { + t.Errorf("unexpected trust anchor count %d, want %d", got, want) + } + if _, err := x509util.ParseDerList(derAnchors); err != nil { + t.Errorf("failed decoding trust anchors: %v", err) + } +} + func TestGetSth(t *testing.T) { for _, table := range []struct { description string -- cgit v1.2.3