autocert: use new OCSP error type (#4437)

This commit is contained in:
Kenneth Jenkins 2023-08-04 14:41:25 -07:00 committed by GitHub
parent 9d4d31cb4f
commit 0affd9268b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 4 deletions

View file

@ -1,8 +1,9 @@
package autocert package autocert
import ( import (
"strings" "errors"
"github.com/caddyserver/certmagic"
"go.uber.org/zap" "go.uber.org/zap"
"go.uber.org/zap/zapcore" "go.uber.org/zap/zapcore"
@ -32,7 +33,7 @@ func (c certMagicLoggerCore) Check(e zapcore.Entry, ce *zapcore.CheckedEntry) *z
func (c certMagicLoggerCore) Write(e zapcore.Entry, fs []zapcore.Field) error { func (c certMagicLoggerCore) Write(e zapcore.Entry, fs []zapcore.Field) error {
fs = append(c.fields, fs...) fs = append(c.fields, fs...)
for _, f := range fs { for _, f := range fs {
if f.Type == zapcore.ErrorType && strings.Contains(f.Interface.(error).Error(), "no OCSP server specified in certificate") { if f.Type == zapcore.ErrorType && errors.Is(f.Interface.(error), certmagic.ErrNoOCSPServerSpecified) {
// ignore this error message (#4245) // ignore this error message (#4245)
return nil return nil
} }

View file

@ -2,9 +2,10 @@ package autocert
import ( import (
"bytes" "bytes"
"errors" "fmt"
"testing" "testing"
"github.com/caddyserver/certmagic"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"go.uber.org/zap" "go.uber.org/zap"
"go.uber.org/zap/zapcore" "go.uber.org/zap/zapcore"
@ -20,7 +21,8 @@ func TestCertMagicLogger(t *testing.T) {
logger := zap.New(core) logger := zap.New(core)
logger.Info("TEST", zap.Error(errors.New("no OCSP server specified in certificate"))) ocspError := fmt.Errorf("ocsp error: %w", certmagic.ErrNoOCSPServerSpecified)
logger.Info("TEST", zap.Error(ocspError))
assert.Empty(t, buf.Bytes()) assert.Empty(t, buf.Bytes())
logger.Info("TEST") logger.Info("TEST")