File tree Expand file tree Collapse file tree 2 files changed +38
-2
lines changed Expand file tree Collapse file tree 2 files changed +38
-2
lines changed Original file line number Diff line number Diff line change @@ -3,8 +3,6 @@ package sdk_proxy
33import (
44 "encoding/json"
55 "fmt"
6- "github.com/devcyclehq/go-server-sdk/v2/api"
7- "github.com/launchdarkly/eventsource"
86 "io"
97 "log"
108 "net/http"
@@ -13,8 +11,10 @@ import (
1311 "time"
1412
1513 devcycle "github.com/devcyclehq/go-server-sdk/v2"
14+ "github.com/devcyclehq/go-server-sdk/v2/api"
1615 "github.com/gin-gonic/gin"
1716 "github.com/kelseyhightower/envconfig"
17+ "github.com/launchdarkly/eventsource"
1818)
1919
2020const (
@@ -147,6 +147,14 @@ func (i *ProxyInstance) Default() {
147147 }
148148 }
149149}
150+
151+ func (i ProxyInstance ) String () string {
152+ // Use a value receiver to override the SDKKey for logging
153+ type alias ProxyInstance
154+ i .SDKKey = "***REDACTED***"
155+ return fmt .Sprintf ("%+v" , (alias )(i ))
156+ }
157+
150158func (c * ProxyConfig ) Default () {
151159 for i := range c .Instances {
152160 c .Instances [i ].Default ()
Original file line number Diff line number Diff line change 11package sdk_proxy
22
33import (
4+ "fmt"
45 "os"
6+ "strings"
57 "testing"
68 "time"
79
@@ -212,3 +214,29 @@ func TestParseConfig(t *testing.T) {
212214 })
213215 }
214216}
217+
218+ func TestProxyInstanceStringer (t * testing.T ) {
219+ // Create a test instance with a SDK key
220+ instance := ProxyInstance {
221+ SDKKey : "dvc_server_test_key_12345" ,
222+ }
223+
224+ // Test the fmt.Stringer implementation
225+ // using fmt.Sprintf to invoke the String() method
226+ result := fmt .Sprintf ("%+v" , instance )
227+
228+ // Verify that the SDK key is redacted
229+ if strings .Contains (result , "SDKKey:dvc_server_test_key_12345" ) {
230+ t .Error ("String() method should redact the SDK key, but it was found in the output" )
231+ }
232+
233+ // Verify that the redacted text is present
234+ if ! strings .Contains (result , "SDKKey:***REDACTED***" ) {
235+ t .Error ("String() method should contain '***REDACTED***' for the SDK key" )
236+ }
237+
238+ // Verify that the original instance's SDK key is not modified
239+ if instance .SDKKey != "dvc_server_test_key_12345" {
240+ t .Error ("Original instance's SDK key should not be modified by String() method" )
241+ }
242+ }
You can’t perform that action at this time.
0 commit comments