Skip to content

Commit

Permalink
feat(): add maskSecret function for plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
ncarlier committed Apr 25, 2019
1 parent 28850d1 commit e6440f6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
14 changes: 14 additions & 0 deletions pkg/model/helpers.go
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
}
}
14 changes: 14 additions & 0 deletions pkg/model/test/helpers_test.go
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"), "")
}

0 comments on commit e6440f6

Please sign in to comment.