aboutsummaryrefslogtreecommitdiff
path: root/handler_test.go
diff options
context:
space:
mode:
authorRasmus Dahlberg <rasmus.dahlberg@kau.se>2020-11-11 16:10:41 +0100
committerRasmus Dahlberg <rasmus.dahlberg@kau.se>2020-11-11 16:10:41 +0100
commitc42378e477e547c9d427aae95e64155e0f7b2da3 (patch)
treec7257a9551efcf91a710497ca0e1809da9b3e93d /handler_test.go
parentb0dcf1e78769006ce8154389476d45aa3fb4d654 (diff)
added get-anchors handler tests
Diffstat (limited to 'handler_test.go')
-rw-r--r--handler_test.go30
1 files changed, 30 insertions, 0 deletions
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