Skip to content

Commit

Permalink
test whether logrus printing also masks license keys
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorik van der Werf committed Oct 18, 2019
1 parent bca3081 commit 775c74d
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions internal/cmd/scraper/scraper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
package scraper

import (
"bytes"
"fmt"
"strings"
"testing"

"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -41,3 +43,26 @@ func TestLicenseKeyMasking(t *testing.T) {
assert.Equal(t, licenseKeyString, unmasked)
})
}

func TestLogrusDebugPrintMasksLicenseKey(t *testing.T) {

const licenseKey = "SECRET_LICENSE_KEY"

cfg := Config{
LicenseKey: licenseKey,
}

var b bytes.Buffer

logrus.SetOutput(&b)
logrus.SetLevel(logrus.DebugLevel)
logrus.Debugf("Config: %#v", cfg)

msg := b.String()
if strings.Contains(msg, licenseKey) {
t.Error("Log output contains the license key")
}
if !strings.Contains(msg, maskedLicenseKey) {
t.Error("Log output does not contain the masked licenseKey")
}
}

0 comments on commit 775c74d

Please sign in to comment.