-
Notifications
You must be signed in to change notification settings - Fork 242
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mask password in error returned when mounting CIFS share fails
this adds a new error type MaskedSecretError to the errors package
- Loading branch information
Showing
3 changed files
with
36 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,16 @@ | ||
package errors | ||
|
||
import ( | ||
"strings" | ||
) | ||
|
||
const mask = "*****" | ||
|
||
type MaskedSecretError struct { | ||
Err error | ||
Secret string | ||
} | ||
|
||
func (err *MaskedSecretError) Error() string { | ||
return strings.ReplaceAll(err.Err.Error(), err.Secret, 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,16 @@ | ||
package errors | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestMaskedError(t *testing.T) { | ||
err := errors.New("The password is: pass@122") | ||
maskedErr := &MaskedSecretError{err, "pass@122"} | ||
expectedErrMsg := fmt.Sprintf("The password is: %s", mask) | ||
assert.EqualError(t, maskedErr, expectedErrMsg) | ||
} |
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