@@ -2,9 +2,12 @@ package gfspconfig
22
33import (
44 "errors"
5+ "strings"
56 "testing"
67
78 "github.com/stretchr/testify/assert"
9+
10+ storeconfig "github.com/bnb-chain/greenfield-storage-provider/store/config"
811)
912
1013var mockErr = errors .New ("mock error" )
@@ -28,3 +31,64 @@ func TestGfSpConfig_StringSuccess(t *testing.T) {
2831 result := cfg .String ()
2932 assert .NotNil (t , result )
3033}
34+
35+ func TestGfSpConfig_StringRedactsSecrets (t * testing.T ) {
36+ cfg := & GfSpConfig {
37+ Env : "mainnet" ,
38+ SpAccount : SpAccountConfig {
39+ SpOperatorAddress : "0xABCD" ,
40+ OperatorPrivateKey : "secret_operator" ,
41+ FundingPrivateKey : "secret_funding" ,
42+ SealPrivateKey : "secret_seal" ,
43+ ApprovalPrivateKey : "secret_approval" ,
44+ GcPrivateKey : "secret_gc" ,
45+ BlsPrivateKey : "secret_bls" ,
46+ },
47+ P2P : P2PConfig {
48+ P2PPrivateKey : "secret_p2p" ,
49+ },
50+ SpDB : storeconfig.SQLDBConfig {Passwd : "secret_spdb" },
51+ BsDB : storeconfig.SQLDBConfig {Passwd : "secret_bsdb" },
52+ }
53+
54+ result := cfg .String ()
55+
56+ secrets := []string {
57+ "secret_operator" , "secret_funding" , "secret_seal" ,
58+ "secret_approval" , "secret_gc" , "secret_bls" ,
59+ "secret_p2p" , "secret_spdb" , "secret_bsdb" ,
60+ }
61+ for _ , s := range secrets {
62+ assert .False (t , strings .Contains (result , s ), "output must not contain plaintext secret: %s" , s )
63+ }
64+
65+ // 9 sensitive fields should each appear as [REDACTED]
66+ assert .Equal (t , 9 , strings .Count (result , redactedPlaceholder ),
67+ "output must contain exactly 9 [REDACTED] placeholders" )
68+
69+ assert .Contains (t , result , "0xABCD" , "non-secret fields must still be present" )
70+ }
71+
72+ func TestGfSpConfig_StringDoesNotMutateOriginal (t * testing.T ) {
73+ cfg := & GfSpConfig {
74+ Env : "mainnet" ,
75+ SpAccount : SpAccountConfig {
76+ OperatorPrivateKey : "original_key" ,
77+ },
78+ P2P : P2PConfig {
79+ P2PPrivateKey : "original_p2p" ,
80+ },
81+ }
82+
83+ _ = cfg .String ()
84+
85+ assert .Equal (t , "original_key" , cfg .SpAccount .OperatorPrivateKey , "String() must not mutate original config" )
86+ assert .Equal (t , "original_p2p" , cfg .P2P .P2PPrivateKey , "String() must not mutate original config" )
87+ }
88+
89+ func TestGfSpConfig_StringEmptySecretsNotRedacted (t * testing.T ) {
90+ cfg := & GfSpConfig {Env : "mainnet" }
91+ result := cfg .String ()
92+ assert .False (t , strings .Contains (result , redactedPlaceholder ),
93+ "empty secret fields should not produce [REDACTED]" )
94+ }
0 commit comments