File tree Expand file tree Collapse file tree 5 files changed +19
-29
lines changed Expand file tree Collapse file tree 5 files changed +19
-29
lines changed Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ import (
10
10
11
11
"github.com/exercism/cli/cli"
12
12
"github.com/exercism/cli/config"
13
- "github.com/exercism/cli/utils "
13
+ "github.com/exercism/cli/debug "
14
14
"github.com/spf13/cobra"
15
15
"github.com/spf13/viper"
16
16
)
@@ -192,7 +192,7 @@ func newConfigurationStatus(status *Status) configurationStatus {
192
192
TokenURL : config .SettingsURL (v .GetString ("apibaseurl" )),
193
193
}
194
194
if status .Censor && cs .Token != "" {
195
- cs .Token = utils .Redact (cs .Token )
195
+ cs .Token = debug .Redact (cs .Token )
196
196
}
197
197
return cs
198
198
}
Original file line number Diff line number Diff line change @@ -10,8 +10,6 @@ import (
10
10
"net/http/httputil"
11
11
"os"
12
12
"strings"
13
-
14
- "github.com/exercism/cli/utils"
15
13
)
16
14
17
15
var (
@@ -50,7 +48,7 @@ func DumpRequest(req *http.Request) {
50
48
51
49
if ! UnmaskAPIKey {
52
50
if token := strings .Split (temp , " " )[1 ]; token != "" {
53
- req .Header .Set ("Authorization" , "Bearer " + utils . Redact (token ))
51
+ req .Header .Set ("Authorization" , "Bearer " + Redact (token ))
54
52
}
55
53
}
56
54
@@ -90,3 +88,10 @@ func DumpResponse(res *http.Response) {
90
88
91
89
res .Body = ioutil .NopCloser (body )
92
90
}
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
+ }
Original file line number Diff line number Diff line change @@ -3,6 +3,8 @@ package debug
3
3
import (
4
4
"bytes"
5
5
"testing"
6
+
7
+ "github.com/stretchr/testify/assert"
6
8
)
7
9
8
10
func TestVerboseEnabled (t * testing.T ) {
@@ -26,3 +28,10 @@ func TestVerboseDisabled(t *testing.T) {
26
28
t .Error ("expected '' got" , b .String ())
27
29
}
28
30
}
31
+
32
+ func TestRedact (t * testing.T ) {
33
+ fakeToken := "1a11111aaaa111aa1a11111a11111aa1"
34
+ expected := "1a11*************************aa1"
35
+
36
+ assert .Equal (t , expected , Redact (fakeToken ))
37
+ }
Load Diff This file was deleted.
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments