|
@@ -851,20 +851,22 @@ func Test_Health(t *testing.T) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func Test_Root(t *testing.T) {
|
|
func Test_Root(t *testing.T) {
|
|
|
|
|
+ const sha = "efc7d6b475a56fe587650bcdb999a4a308f815ba44db4bf0371ea68a786ccd36"
|
|
|
tests := []struct {
|
|
tests := []struct {
|
|
|
- name string
|
|
|
|
|
- root *x509.Certificate
|
|
|
|
|
- err error
|
|
|
|
|
- statusCode int
|
|
|
|
|
|
|
+ name string
|
|
|
|
|
+ root *x509.Certificate
|
|
|
|
|
+ err error
|
|
|
|
|
+ expectedMsg string
|
|
|
|
|
+ statusCode int
|
|
|
}{
|
|
}{
|
|
|
- {"ok", parseCertificate(rootPEM), nil, 200},
|
|
|
|
|
- {"fail", nil, fmt.Errorf("not found"), 404},
|
|
|
|
|
|
|
+ {"ok", parseCertificate(rootPEM), nil, "", 200},
|
|
|
|
|
+ {"fail", nil, fmt.Errorf("not found"), fmt.Sprintf("root certificate with fingerprint %q was not found", sha), 404},
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Request with chi context
|
|
// Request with chi context
|
|
|
chiCtx := chi.NewRouteContext()
|
|
chiCtx := chi.NewRouteContext()
|
|
|
- chiCtx.URLParams.Add("sha", "efc7d6b475a56fe587650bcdb999a4a308f815ba44db4bf0371ea68a786ccd36")
|
|
|
|
|
- req := httptest.NewRequest("GET", "http://example.com/root/efc7d6b475a56fe587650bcdb999a4a308f815ba44db4bf0371ea68a786ccd36", http.NoBody)
|
|
|
|
|
|
|
+ chiCtx.URLParams.Add("sha", sha)
|
|
|
|
|
+ req := httptest.NewRequest("GET", "http://example.com/root/"+sha, http.NoBody)
|
|
|
req = req.WithContext(context.WithValue(context.Background(), chi.RouteCtxKey, chiCtx))
|
|
req = req.WithContext(context.WithValue(context.Background(), chi.RouteCtxKey, chiCtx))
|
|
|
|
|
|
|
|
expected := []byte(`{"ca":"` + strings.ReplaceAll(rootPEM, "\n", `\n`) + `\n"}`)
|
|
expected := []byte(`{"ca":"` + strings.ReplaceAll(rootPEM, "\n", `\n`) + `\n"}`)
|
|
@@ -889,6 +891,8 @@ func Test_Root(t *testing.T) {
|
|
|
if !bytes.Equal(bytes.TrimSpace(body), expected) {
|
|
if !bytes.Equal(bytes.TrimSpace(body), expected) {
|
|
|
t.Errorf("caHandler.Root Body = %s, wants %s", body, expected)
|
|
t.Errorf("caHandler.Root Body = %s, wants %s", body, expected)
|
|
|
}
|
|
}
|
|
|
|
|
+ } else {
|
|
|
|
|
+ require.Contains(t, string(body), tt.expectedMsg)
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|