-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
redact password when logging Redis URL (#8)
- Loading branch information
1 parent
e998229
commit 8ed7b65
Showing
3 changed files
with
66 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package ldredis | ||
|
||
import ( | ||
"testing" | ||
|
||
"gopkg.in/launchdarkly/go-sdk-common.v2/ldlog" | ||
"gopkg.in/launchdarkly/go-sdk-common.v2/ldlogtest" | ||
"gopkg.in/launchdarkly/go-server-sdk.v5/ldcomponents" | ||
"gopkg.in/launchdarkly/go-server-sdk.v5/testhelpers" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func doStartupLoggingTest(t *testing.T, url string, expectedLogURL string) { | ||
mockLog1 := ldlogtest.NewMockLog() | ||
mockLog2 := ldlogtest.NewMockLog() | ||
defer mockLog1.DumpIfTestFailed(t) | ||
defer mockLog2.DumpIfTestFailed(t) | ||
context1 := testhelpers.NewSimpleClientContext("sdk-key"). | ||
WithLogging(ldcomponents.Logging().Loggers(mockLog1.Loggers)) | ||
context2 := testhelpers.NewSimpleClientContext("sdk-key"). | ||
WithLogging(ldcomponents.Logging().Loggers(mockLog2.Loggers)) | ||
|
||
store1, err := DataStore().URL(url).CreatePersistentDataStore(context1) | ||
require.NoError(t, err) | ||
_ = store1.Close() | ||
mockLog1.AssertMessageMatch(t, true, ldlog.Info, "Using URL: "+expectedLogURL) | ||
|
||
store2, err := DataStore().URL(url).CreateBigSegmentStore(context2) | ||
require.NoError(t, err) | ||
_ = store2.Close() | ||
mockLog2.AssertMessageMatch(t, true, ldlog.Info, "Using URL: "+expectedLogURL) | ||
} | ||
|
||
func TestURLAppearsInLogAtStartup(t *testing.T) { | ||
doStartupLoggingTest(t, "redis://localhost:6379", "redis://localhost:6379") | ||
doStartupLoggingTest(t, "redis://localhost:6379/1", "redis://localhost:6379/1") | ||
} | ||
|
||
func TestURLPasswordIsObfuscatedInLog(t *testing.T) { | ||
doStartupLoggingTest(t, "redis://username@localhost:6379", "redis://username@localhost:6379") | ||
doStartupLoggingTest(t, "redis://username:very-secret-password@localhost:6379", "redis://username:xxxxx@localhost:6379") | ||
} |