Skip to content

Commit b4ed8b5

Browse files
ashmckenzieArchish27
authored andcommitted
Merge branch '785-twofactor-lint' into 'main'
Lint fixes for twofactor packages Closes #785 See merge request https://gitlab.com/gitlab-org/gitlab-shell/-/merge_requests/1143 Merged-by: Ash McKenzie <[email protected]> Approved-by: Ash McKenzie <[email protected]> Co-authored-by: Archish <[email protected]>
2 parents 3f2462e + 0ef0056 commit b4ed8b5

File tree

7 files changed

+24
-40
lines changed

7 files changed

+24
-40
lines changed

internal/command/twofactorrecover/twofactorrecover.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func (c *Command) Execute(ctx context.Context) (context.Context, error) {
3434
c.displayRecoveryCodes(ctx)
3535
} else {
3636
ctxlog.Debug("twofactorrecover: execute: User chose not to continue")
37-
fmt.Fprintln(c.ReadWriter.Out, "\nNew recovery codes have *not* been generated. Existing codes will remain valid.")
37+
_, _ = fmt.Fprintln(c.ReadWriter.Out, "\nNew recovery codes have *not* been generated. Existing codes will remain valid.")
3838
}
3939

4040
return ctx, nil
@@ -44,7 +44,7 @@ func (c *Command) getUserAnswer(ctx context.Context) string {
4444
question :=
4545
"Are you sure you want to generate new two-factor recovery codes?\n" +
4646
"Any existing recovery codes you saved will be invalidated. (yes/no)"
47-
fmt.Fprintln(c.ReadWriter.Out, question)
47+
_, _ = fmt.Fprintln(c.ReadWriter.Out, question)
4848

4949
var answer string
5050
if _, err := fmt.Fscanln(io.LimitReader(c.ReadWriter.In, readerLimit), &answer); err != nil {
@@ -67,10 +67,10 @@ func (c *Command) displayRecoveryCodes(ctx context.Context) {
6767
"\n\nDuring sign in, use one of the codes above when prompted for\n" +
6868
"your two-factor code. Then, visit your Profile Settings and add\n" +
6969
"a new device so you do not lose access to your account again.\n"
70-
fmt.Fprint(c.ReadWriter.Out, messageWithCodes)
70+
_, _ = fmt.Fprint(c.ReadWriter.Out, messageWithCodes)
7171
} else {
7272
ctxlog.WithError(err).Error("twofactorrecover: displayRecoveryCodes: failed to generate recovery codes")
73-
fmt.Fprintf(c.ReadWriter.Out, "\nAn error occurred while trying to generate new recovery codes.\n%v\n", err)
73+
_, _ = fmt.Fprintf(c.ReadWriter.Out, "\nAn error occurred while trying to generate new recovery codes.\n%v\n", err)
7474
}
7575
}
7676

internal/command/twofactorrecover/twofactorrecover_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"strings"
1010
"testing"
1111

12+
"github.com/stretchr/testify/assert"
1213
"github.com/stretchr/testify/require"
1314

1415
"gitlab.com/gitlab-org/gitlab-shell/v14/client/testserver"
@@ -28,7 +29,7 @@ func setup(t *testing.T) {
2829
b, err := io.ReadAll(r.Body)
2930
defer r.Body.Close()
3031

31-
require.NoError(t, err)
32+
assert.NoError(t, err)
3233

3334
var requestBody *twofactorrecover.RequestBody
3435
json.Unmarshal(b, &requestBody)

internal/command/twofactorverify/twofactorverify.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func (c *Command) Execute(ctx context.Context) (context.Context, error) {
3737
ctx, cancel := context.WithTimeout(ctx, timeout)
3838
defer cancel()
3939

40-
fmt.Fprint(c.ReadWriter.Out, prompt)
40+
_, _ = fmt.Fprint(c.ReadWriter.Out, prompt)
4141

4242
resultCh := make(chan string)
4343
go func() {
@@ -68,7 +68,7 @@ func (c *Command) Execute(ctx context.Context) (context.Context, error) {
6868
}
6969

7070
log.WithContextFields(ctx, log.Fields{"message": message}).Info("Two factor verify command finished")
71-
fmt.Fprintf(c.ReadWriter.Out, "\n%v\n", message)
71+
_, _ = fmt.Fprintf(c.ReadWriter.Out, "\n%v\n", message)
7272

7373
return ctx, nil
7474
}

internal/command/twofactorverify/twofactorverify_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"net/http"
99
"testing"
1010

11+
"github.com/stretchr/testify/assert"
1112
"github.com/stretchr/testify/require"
1213

1314
"gitlab.com/gitlab-org/gitlab-shell/v14/client/testserver"
@@ -35,10 +36,10 @@ func setup(t *testing.T) []testserver.TestRequestHandler {
3536
b, err := io.ReadAll(r.Body)
3637
defer r.Body.Close()
3738

38-
require.NoError(t, err)
39+
assert.NoError(t, err)
3940

4041
var requestBody *twofactorverify.RequestBody
41-
require.NoError(t, json.Unmarshal(b, &requestBody))
42+
assert.NoError(t, json.Unmarshal(b, &requestBody))
4243

4344
switch requestBody.KeyID {
4445
case "verify_via_otp", "verify_via_otp_with_push_error":
@@ -53,7 +54,7 @@ func setup(t *testing.T) []testserver.TestRequestHandler {
5354
"success": false,
5455
"message": "error message",
5556
}
56-
require.NoError(t, json.NewEncoder(w).Encode(body))
57+
assert.NoError(t, json.NewEncoder(w).Encode(body))
5758
case "broken":
5859
w.WriteHeader(http.StatusInternalServerError)
5960
}
@@ -65,10 +66,10 @@ func setup(t *testing.T) []testserver.TestRequestHandler {
6566
b, err := io.ReadAll(r.Body)
6667
defer r.Body.Close()
6768

68-
require.NoError(t, err)
69+
assert.NoError(t, err)
6970

7071
var requestBody *twofactorverify.RequestBody
71-
require.NoError(t, json.Unmarshal(b, &requestBody))
72+
assert.NoError(t, json.Unmarshal(b, &requestBody))
7273

7374
switch requestBody.KeyID {
7475
case "verify_via_push":

internal/gitlabnet/twofactorrecover/client_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"net/http"
88
"testing"
99

10+
"github.com/stretchr/testify/assert"
1011
"github.com/stretchr/testify/require"
1112
"gitlab.com/gitlab-org/gitlab-shell/v14/client"
1213
"gitlab.com/gitlab-org/gitlab-shell/v14/client/testserver"
@@ -27,7 +28,7 @@ func initialize(t *testing.T) {
2728
b, err := io.ReadAll(r.Body)
2829
defer r.Body.Close()
2930

30-
require.NoError(t, err)
31+
assert.NoError(t, err)
3132

3233
var requestBody *RequestBody
3334
json.Unmarshal(b, &requestBody)

internal/gitlabnet/twofactorverify/client_test.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
"gitlab.com/gitlab-org/gitlab-shell/v14/internal/gitlabnet/discover"
1111

12+
"github.com/stretchr/testify/assert"
1213
"github.com/stretchr/testify/require"
1314
"gitlab.com/gitlab-org/gitlab-shell/v14/client"
1415
"gitlab.com/gitlab-org/gitlab-shell/v14/client/testserver"
@@ -21,29 +22,29 @@ func initialize(t *testing.T) []testserver.TestRequestHandler {
2122
b, err := io.ReadAll(r.Body)
2223
defer r.Body.Close()
2324

24-
require.NoError(t, err)
25+
assert.NoError(t, err)
2526

2627
var requestBody *RequestBody
27-
require.NoError(t, json.Unmarshal(b, &requestBody))
28+
assert.NoError(t, json.Unmarshal(b, &requestBody))
2829

2930
switch requestBody.KeyID {
3031
case "0":
3132
body := map[string]interface{}{
3233
"success": true,
3334
}
34-
require.NoError(t, json.NewEncoder(w).Encode(body))
35+
assert.NoError(t, json.NewEncoder(w).Encode(body))
3536
case "1":
3637
body := map[string]interface{}{
3738
"success": false,
3839
"message": "error message",
3940
}
40-
require.NoError(t, json.NewEncoder(w).Encode(body))
41+
assert.NoError(t, json.NewEncoder(w).Encode(body))
4142
case "2":
4243
w.WriteHeader(http.StatusForbidden)
4344
body := &client.ErrorResponse{
4445
Message: "Not allowed!",
4546
}
46-
require.NoError(t, json.NewEncoder(w).Encode(body))
47+
assert.NoError(t, json.NewEncoder(w).Encode(body))
4748
case "3":
4849
w.Write([]byte("{ \"message\": \"broken json!\""))
4950
case "4":
@@ -54,7 +55,7 @@ func initialize(t *testing.T) []testserver.TestRequestHandler {
5455
body := map[string]interface{}{
5556
"success": true,
5657
}
57-
require.NoError(t, json.NewEncoder(w).Encode(body))
58+
assert.NoError(t, json.NewEncoder(w).Encode(body))
5859
}
5960
}
6061

@@ -75,7 +76,7 @@ func initialize(t *testing.T) []testserver.TestRequestHandler {
7576
Username: "jane-doe",
7677
Name: "Jane Doe",
7778
}
78-
require.NoError(t, json.NewEncoder(w).Encode(body))
79+
assert.NoError(t, json.NewEncoder(w).Encode(body))
7980
},
8081
},
8182
}

support/lint_last_known_acceptable.txt

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -278,18 +278,6 @@ internal/command/shared/customaction/customaction_test.go:118:5: go-require: do
278278
internal/command/shared/customaction/customaction_test.go:121:5: go-require: do not use require in http handlers (testifylint)
279279
internal/command/shared/disallowedcommand/disallowedcommand.go:1:1: package-comments: should have a package comment (revive)
280280
internal/command/shared/disallowedcommand/disallowedcommand.go:6:2: exported: exported var Error should have comment or be unexported (revive)
281-
internal/command/twofactorrecover/twofactorrecover.go:37:15: Error return value of `fmt.Fprintln` is not checked (errcheck)
282-
internal/command/twofactorrecover/twofactorrecover.go:47:14: Error return value of `fmt.Fprintln` is not checked (errcheck)
283-
internal/command/twofactorrecover/twofactorrecover.go:70:13: Error return value of `fmt.Fprint` is not checked (errcheck)
284-
internal/command/twofactorrecover/twofactorrecover.go:73:14: Error return value of `fmt.Fprintf` is not checked (errcheck)
285-
internal/command/twofactorrecover/twofactorrecover_test.go:31:5: go-require: do not use require in http handlers (testifylint)
286-
internal/command/twofactorverify/twofactorverify.go:40:12: Error return value of `fmt.Fprint` is not checked (errcheck)
287-
internal/command/twofactorverify/twofactorverify.go:71:13: Error return value of `fmt.Fprintf` is not checked (errcheck)
288-
internal/command/twofactorverify/twofactorverify_test.go:38:5: go-require: do not use require in http handlers (testifylint)
289-
internal/command/twofactorverify/twofactorverify_test.go:41:5: go-require: do not use require in http handlers (testifylint)
290-
internal/command/twofactorverify/twofactorverify_test.go:56:6: go-require: do not use require in http handlers (testifylint)
291-
internal/command/twofactorverify/twofactorverify_test.go:68:5: go-require: do not use require in http handlers (testifylint)
292-
internal/command/twofactorverify/twofactorverify_test.go:71:5: go-require: do not use require in http handlers (testifylint)
293281
internal/command/uploadarchive/gitalycall_test.go:24:4: S1038: should use t.Logf(...) instead of t.Log(fmt.Sprintf(...)) (gosimple)
294282
internal/command/uploadarchive/gitalycall_test.go:32:4: var-naming: var userId should be userID (revive)
295283
internal/config/config.go:1:1: package-comments: should have a package comment (revive)
@@ -381,14 +369,6 @@ internal/gitlabnet/lfstransfer/client.go:214:1: exported: exported method Client
381369
internal/gitlabnet/lfstransfer/client.go:271:1: exported: exported method Client.Unlock should have comment or be unexported (revive)
382370
internal/gitlabnet/lfstransfer/client.go:321:1: exported: exported method Client.ListLocksVerify should have comment or be unexported (revive)
383371
internal/gitlabnet/personalaccesstoken/client_test.go:30:5: go-require: do not use require in http handlers (testifylint)
384-
internal/gitlabnet/twofactorrecover/client_test.go:30:5: go-require: do not use require in http handlers (testifylint)
385-
internal/gitlabnet/twofactorverify/client_test.go:24:3: go-require: do not use require in http handlers (testifylint)
386-
internal/gitlabnet/twofactorverify/client_test.go:27:3: go-require: do not use require in http handlers (testifylint)
387-
internal/gitlabnet/twofactorverify/client_test.go:34:4: go-require: do not use require in http handlers (testifylint)
388-
internal/gitlabnet/twofactorverify/client_test.go:40:4: go-require: do not use require in http handlers (testifylint)
389-
internal/gitlabnet/twofactorverify/client_test.go:46:4: go-require: do not use require in http handlers (testifylint)
390-
internal/gitlabnet/twofactorverify/client_test.go:57:4: go-require: do not use require in http handlers (testifylint)
391-
internal/gitlabnet/twofactorverify/client_test.go:78:5: go-require: do not use require in http handlers (testifylint)
392372
internal/logger/logger.go:1:1: package-comments: should have a package comment (revive)
393373
internal/logger/logger.go:55:9: ST1005: error strings should not be capitalized (stylecheck)
394374
internal/logger/logger.go:69:27: printf: non-constant format string in call to fmt.Fprintf (govet)

0 commit comments

Comments
 (0)