Skip to content

Commit

Permalink
Merge pull request #529 from sudo-bmitch/pr-fix-redaction
Browse files Browse the repository at this point in the history
Fix redaction of conformance tests
  • Loading branch information
dmcgowan authored Mar 15, 2024
2 parents a47ad51 + 4d091a9 commit 7ac9a4c
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions conformance/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,17 +447,20 @@ func (l *httpDebugLogger) Warnf(format string, v ...interface{}) {
}

func (l *httpDebugLogger) Debugf(format string, v ...interface{}) {
re := regexp.MustCompile("(?i)(\"?\\w*(authorization|token|state)\\w*\"?(:|=)\\s*)(\")?\\s*((bearer|basic)? )?[^\\s&\"]*(\")?")
format = re.ReplaceAllString(format, "$1$4$5*****$7")
l.output("DEBUG "+format, v...)
}

var (
redactRegexp = regexp.MustCompile(`(?i)("?\w*(authorization|token|state)\w*"?(:|=)\s*)(")?\s*((bearer|basic)? )?[^\s&"]*(")?`)
redactReplace = "$1$4$5*****$7"
)

func (l *httpDebugLogger) output(format string, v ...interface{}) {
if len(v) == 0 {
l.l.Print(format)
l.l.Print(redactRegexp.ReplaceAllString(format, redactReplace))
return
}
_, err := l.w.Write([]byte(fmt.Sprintf(format, v...)))
_, err := l.w.Write([]byte(redactRegexp.ReplaceAllString(fmt.Sprintf(format, v...), redactReplace)))
if err != nil {
l.Errorf(err.Error())
}
Expand Down

0 comments on commit 7ac9a4c

Please sign in to comment.