forked from TrueCloudLab/certificates
Error handle non existent provisioner downstream and disable debug route logging
This commit is contained in:
parent
497ec0c79b
commit
93c3c2bf2e
3 changed files with 28 additions and 14 deletions
|
@ -87,14 +87,14 @@ func (h *Handler) addDirLink(next nextHTTP) nextHTTP {
|
|||
// application/jose+json.
|
||||
func (h *Handler) verifyContentType(next nextHTTP) nextHTTP {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var (
|
||||
expected []string
|
||||
provName string
|
||||
)
|
||||
if p, err := provisionerFromContext(r.Context()); err == nil && p != nil {
|
||||
provName = p.GetName()
|
||||
var expected []string
|
||||
p, err := provisionerFromContext(r.Context())
|
||||
if err != nil {
|
||||
api.WriteError(w, err)
|
||||
return
|
||||
}
|
||||
u := url.URL{Path: h.linker.GetUnescapedPathSuffix(CertificateLinkType, provName, "")}
|
||||
|
||||
u := url.URL{Path: h.linker.GetUnescapedPathSuffix(CertificateLinkType, p.GetName(), "")}
|
||||
if strings.Contains(r.URL.String(), u.EscapedPath()) {
|
||||
// GET /certificate requests allow a greater range of content types.
|
||||
expected = []string{"application/jose+json", "application/pkix-cert", "application/pkcs7-mime"}
|
||||
|
|
|
@ -240,6 +240,18 @@ func TestHandler_verifyContentType(t *testing.T) {
|
|||
url string
|
||||
}
|
||||
var tests = map[string]func(t *testing.T) test{
|
||||
"fail/provisioner-not-set": func(t *testing.T) test {
|
||||
return test{
|
||||
h: Handler{
|
||||
linker: NewLinker("dns", "acme"),
|
||||
},
|
||||
url: url,
|
||||
ctx: context.Background(),
|
||||
contentType: "foo",
|
||||
statusCode: 500,
|
||||
err: acme.NewErrorISE("provisioner expected in request context"),
|
||||
}
|
||||
},
|
||||
"fail/general-bad-content-type": func(t *testing.T) test {
|
||||
return test{
|
||||
h: Handler{
|
||||
|
|
2
ca/ca.go
2
ca/ca.go
|
@ -168,6 +168,7 @@ func (ca *CA) Init(config *authority.Config) (*CA, error) {
|
|||
})
|
||||
|
||||
// helpful routine for logging all routes //
|
||||
/*
|
||||
walkFunc := func(method string, route string, handler http.Handler, middlewares ...func(http.Handler) http.Handler) error {
|
||||
fmt.Printf("%s %s\n", method, route)
|
||||
return nil
|
||||
|
@ -175,6 +176,7 @@ func (ca *CA) Init(config *authority.Config) (*CA, error) {
|
|||
if err := chi.Walk(mux, walkFunc); err != nil {
|
||||
fmt.Printf("Logging err: %s\n", err.Error())
|
||||
}
|
||||
*/
|
||||
|
||||
// Add monitoring if configured
|
||||
if len(config.Monitoring) > 0 {
|
||||
|
|
Loading…
Reference in a new issue