-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(): add maskSecret function for plugins
- Loading branch information
Showing
2 changed files
with
28 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package model | ||
|
||
const mask = "########" | ||
|
||
// MaskSecret mask secret string | ||
func MaskSecret(secret string) string { | ||
l := len(secret) | ||
if l > 8 { | ||
return string(secret[:3] + mask + secret[l-3:]) | ||
|
||
} else { | ||
return mask | ||
} | ||
} |
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,14 @@ | ||
package test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/ncarlier/feedpushr/pkg/assert" | ||
"github.com/ncarlier/feedpushr/pkg/model" | ||
) | ||
|
||
func TestMaskSecret(t *testing.T) { | ||
mask := "########" | ||
assert.Equal(t, mask, model.MaskSecret("zzz"), "") | ||
assert.Equal(t, "111"+mask+"999", model.MaskSecret("111zzz999"), "") | ||
} |