generated from nginxinc/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: use SecretBytes type for cert values to prevent accidental print…
…ing. Fixes 145
- Loading branch information
Showing
7 changed files
with
95 additions
and
32 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 @@ | ||
golang 1.19.13 |
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
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,15 @@ | ||
package core | ||
|
||
import ( | ||
"encoding/json" | ||
) | ||
|
||
type SecretBytes []byte | ||
|
||
func (sb SecretBytes) String() string { | ||
return "[REDACTED]" | ||
} | ||
|
||
func (sb SecretBytes) MarshalJSON() ([]byte, error) { | ||
return json.Marshal("[REDACTED]") | ||
} |
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,31 @@ | ||
/* | ||
* Copyright 2023 F5 Inc. All rights reserved. | ||
* Use of this source code is governed by the Apache License that can be found in the LICENSE file. | ||
*/ | ||
|
||
package core | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"testing" | ||
) | ||
|
||
func TestSecretBytesToString(t *testing.T) { | ||
sensitive := SecretBytes([]byte("If you can see this we have a problem")) | ||
|
||
expected := "foo [REDACTED] bar" | ||
result := fmt.Sprintf("foo %v bar", sensitive) | ||
if result != expected { | ||
t.Errorf("Expected %s, got %s", expected, result) | ||
} | ||
} | ||
|
||
func TestSecretBytesToJSON(t *testing.T) { | ||
sensitive, _ := json.Marshal(SecretBytes([]byte("If you can see this we have a problem"))) | ||
expected := `foo "[REDACTED]" bar` | ||
result := fmt.Sprintf("foo %v bar", string(sensitive)) | ||
if result != expected { | ||
t.Errorf("Expected %s, got %s", expected, result) | ||
} | ||
} |