-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(FFM-7329) Mask sdk keys in logs (#139)
- Loading branch information
1 parent
e22ed8c
commit c260ffb
Showing
3 changed files
with
57 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package token | ||
|
||
func MaskRight(s string) string { | ||
rs := []rune(s) | ||
for i := len(rs) - 1; i > 3; i-- { | ||
rs[i] = '*' | ||
} | ||
return string(rs) | ||
} |
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,38 @@ | ||
package token | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func Test_MaskRight(t *testing.T) { | ||
testCases := map[string]struct { | ||
input string | ||
expected string | ||
}{ | ||
"Test key gets all characters after first 4 masked": { | ||
input: "abcdef12-1234-5678-abcd-012345678901", | ||
expected: "abcd********************************", | ||
}, | ||
"Test exactly 4 characters": { | ||
input: "abcd", | ||
expected: "abcd", | ||
}, | ||
"Test less than 4 characters": { | ||
input: "ab", | ||
expected: "ab", | ||
}, | ||
"Test empty string": { | ||
input: "", | ||
expected: "", | ||
}, | ||
} | ||
|
||
for desc, tc := range testCases { | ||
t.Run(desc, func(t *testing.T) { | ||
actual := MaskRight(tc.input) | ||
assert.Equal(t, tc.expected, actual) | ||
}) | ||
} | ||
} |