Skip to content

Commit c7bab26

Browse files
author
Jamario Rankins
committed
Removing utils package and moving Redact to the debug package
1 parent 7f4bb27 commit c7bab26

File tree

5 files changed

+19
-29
lines changed

5 files changed

+19
-29
lines changed

cmd/troubleshoot.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010

1111
"github.com/exercism/cli/cli"
1212
"github.com/exercism/cli/config"
13-
"github.com/exercism/cli/utils"
13+
"github.com/exercism/cli/debug"
1414
"github.com/spf13/cobra"
1515
"github.com/spf13/viper"
1616
)
@@ -192,7 +192,7 @@ func newConfigurationStatus(status *Status) configurationStatus {
192192
TokenURL: config.SettingsURL(v.GetString("apibaseurl")),
193193
}
194194
if status.Censor && cs.Token != "" {
195-
cs.Token = utils.Redact(cs.Token)
195+
cs.Token = debug.Redact(cs.Token)
196196
}
197197
return cs
198198
}

debug/debug.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ import (
1010
"net/http/httputil"
1111
"os"
1212
"strings"
13-
14-
"github.com/exercism/cli/utils"
1513
)
1614

1715
var (
@@ -50,7 +48,7 @@ func DumpRequest(req *http.Request) {
5048

5149
if !UnmaskAPIKey {
5250
if token := strings.Split(temp, " ")[1]; token != "" {
53-
req.Header.Set("Authorization", "Bearer "+utils.Redact(token))
51+
req.Header.Set("Authorization", "Bearer "+Redact(token))
5452
}
5553
}
5654

@@ -90,3 +88,10 @@ func DumpResponse(res *http.Response) {
9088

9189
res.Body = ioutil.NopCloser(body)
9290
}
91+
92+
// Redact masks the given token by replacing part of the string with *
93+
func Redact(token string) string {
94+
str := token[4 : len(token)-3]
95+
redaction := strings.Repeat("*", len(str))
96+
return string(token[:4]) + redaction + string(token[len(token)-3:])
97+
}

debug/debug_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package debug
33
import (
44
"bytes"
55
"testing"
6+
7+
"github.com/stretchr/testify/assert"
68
)
79

810
func TestVerboseEnabled(t *testing.T) {
@@ -26,3 +28,10 @@ func TestVerboseDisabled(t *testing.T) {
2628
t.Error("expected '' got", b.String())
2729
}
2830
}
31+
32+
func TestRedact(t *testing.T) {
33+
fakeToken := "1a11111aaaa111aa1a11111a11111aa1"
34+
expected := "1a11*************************aa1"
35+
36+
assert.Equal(t, expected, Redact(fakeToken))
37+
}

utils/utils.go

Lines changed: 0 additions & 10 deletions
This file was deleted.

utils/utils_test.go

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)