-
Notifications
You must be signed in to change notification settings - Fork 467
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mask redis credentials in logs (#347)
* use golang 1.18 in docker images Signed-off-by: Marcel Wiederer <[email protected]> * mask redis credentials when logging the connection strings Signed-off-by: Marcel Wiederer <[email protected]> Co-authored-by: Marcel Wiederer <[email protected]>
- Loading branch information
Showing
4 changed files
with
67 additions
and
4 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
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,41 @@ | ||
package utils_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/envoyproxy/ratelimit/src/utils" | ||
) | ||
|
||
func TestMaskCredentialsInUrl(t *testing.T) { | ||
url := "redis:6379" | ||
assert.Equal(t, url, utils.MaskCredentialsInUrl(url)) | ||
|
||
url = "redis://foo:bar@redis:6379" | ||
expected := "redis://*****@redis:6379" | ||
assert.Equal(t, expected, utils.MaskCredentialsInUrl(url)) | ||
} | ||
|
||
func TestMaskCredentialsInUrlCluster(t *testing.T) { | ||
url := "redis1:6379,redis2:6379" | ||
assert.Equal(t, url, utils.MaskCredentialsInUrl(url)) | ||
|
||
url = "redis://foo:bar@redis1:6379,redis://foo:bar@redis2:6379" | ||
expected := "redis://*****@redis1:6379,redis://*****@redis2:6379" | ||
assert.Equal(t, expected, utils.MaskCredentialsInUrl(url)) | ||
|
||
url = "redis://foo:b@r@redis1:6379,redis://foo:b@r@redis2:6379" | ||
expected = "redis://*****@redis1:6379,redis://*****@redis2:6379" | ||
assert.Equal(t, expected, utils.MaskCredentialsInUrl(url)) | ||
} | ||
|
||
func TestMaskCredentialsInUrlSentinel(t *testing.T) { | ||
url := "foobar,redis://foo:bar@redis1:6379,redis://foo:bar@redis2:6379" | ||
expected := "foobar,redis://*****@redis1:6379,redis://*****@redis2:6379" | ||
assert.Equal(t, expected, utils.MaskCredentialsInUrl(url)) | ||
|
||
url = "foob@r,redis://foo:b@r@redis1:6379,redis://foo:b@r@redis2:6379" | ||
expected = "foob@r,redis://*****@redis1:6379,redis://*****@redis2:6379" | ||
assert.Equal(t, expected, utils.MaskCredentialsInUrl(url)) | ||
} |