Skip to content

Commit

Permalink
feat: make password in log hide
Browse files Browse the repository at this point in the history
  • Loading branch information
macrat committed Apr 26, 2021
1 parent 8501db6 commit bac1719
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion store/record.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func (r Record) String() string {
r.CheckedAt.Format(time.RFC3339),
r.Status.String(),
strconv.FormatFloat(float64(r.Latency.Microseconds())/1000, 'f', 3, 64),
r.Target.String(),
r.Target.Redacted(),
EscapeMessage(r.Message),
}, "\t")
}
Expand Down
22 changes: 22 additions & 0 deletions store/record_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package store_test

import (
"net/url"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -93,6 +94,27 @@ func TestRecord(t *testing.T) {
}
}

func TestRecord_redact(t *testing.T) {
record := store.Record{
CheckedAt: time.Date(2021, 1, 2, 15, 4, 5, 0, time.UTC),
Target: &url.URL{Scheme: "http", Path: "/path/to/file", User: url.UserPassword("MyName", "HideMe")},
Status: store.STATUS_HEALTHY,
Message: "hello world",
Latency: 123456 * time.Microsecond,
}

str := record.String()
if !strings.Contains(str, "/path/to/file") {
t.Errorf("record does not contain URL path\n%#v", str)
}
if !strings.Contains(str, "MyName") {
t.Errorf("record does not contain username\n%#v", str)
}
if strings.Contains(str, "HideMe") {
t.Errorf("record contains password\n%#v", str)
}
}

func TestUnescapeMessage(t *testing.T) {
tests := []struct {
Input string
Expand Down

0 comments on commit bac1719

Please sign in to comment.