Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 75ed8ef

Browse files
committed
Linting
1 parent 5698938 commit 75ed8ef

17 files changed

+59
-29
lines changed

coderd/authz/authz.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ func Authorize(subj Subject, obj Resource, action Action) error {
77
}
88

99
// AuthorizePermissions runs the authorize function with the raw permissions in a single list.
10-
func AuthorizePermissions(subjID string, permissions []Permission, object Resource, action Action) error {
11-
10+
func AuthorizePermissions(_ string, _ []Permission, _ Resource, _ Action) error {
1211
return nil
1312
}

coderd/authz/authz_test.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,11 @@ func Test_ExhaustiveAuthorize(t *testing.T) {
7979
// Result: func(pv string) bool {
8080
// return strings.Contains(pv, "+")
8181
// },
82-
//},
82+
// },
8383
}
8484

8585
var failedTests int
86+
//nolint:paralleltest
8687
for _, c := range testCases {
8788
t.Run(c.Name, func(t *testing.T) {
8889
for _, o := range c.Objs {
@@ -106,7 +107,7 @@ func Test_ExhaustiveAuthorize(t *testing.T) {
106107
})
107108
}
108109
// TODO: @emyrk when we implement the correct authorize, we can enable this check.
109-
//require.Equal(t, 0, failedTests, fmt.Sprintf("%d tests failed", failedTests))
110+
// require.Equal(t, 0, failedTests, fmt.Sprintf("%d tests failed", failedTests))
110111
}
111112

112113
func permissionVariants(all authztest.SetGroup) map[string]*authztest.Role {
@@ -248,7 +249,8 @@ func noise(f noiseBits, lvls ...authztest.LevelGroup) *authztest.Role {
248249
}
249250

250251
if len(rs) == 1 {
251-
return rs[0].(*authztest.Role)
252+
role, _ := rs[0].(*authztest.Role)
253+
return role
252254
}
253255
return authztest.NewRole(rs...)
254256
}

coderd/authz/authztest/iterator.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ type unionIterator struct {
3232
N int
3333
}
3434

35+
//nolint:revive
3536
func Union(sets ...Set) *unionIterator {
3637
var n int
3738
for _, s := range sets {
@@ -68,7 +69,7 @@ func (si *unionIterator) Reset() {
6869
si.offset = 0
6970
}
7071

71-
func (si *unionIterator) ReturnSize() int {
72+
func (unionIterator) ReturnSize() int {
7273
return 1
7374
}
7475

coderd/authz/authztest/iterator_test.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ package authztest_test
33
import (
44
"testing"
55

6+
"github.com/google/uuid"
7+
"github.com/stretchr/testify/require"
8+
69
"github.com/coder/coder/coderd/authz"
710
"github.com/coder/coder/coderd/authz/authztest"
811
crand "github.com/coder/coder/cryptorand"
9-
"github.com/google/uuid"
10-
"github.com/stretchr/testify/require"
1112
)
1213

1314
func TestUnion(t *testing.T) {

coderd/authz/authztest/level.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func (lg LevelGroup) All() Set {
2525
var i int
2626
i += copy(all[i:], pos)
2727
i += copy(all[i:], neg)
28-
i += copy(all[i:], net)
28+
copy(all[i:], net)
2929
return all
3030
}
3131

coderd/authz/authztest/level_test.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ package authztest_test
33
import (
44
"testing"
55

6+
"github.com/stretchr/testify/require"
7+
68
"github.com/coder/coder/coderd/authz"
79
"github.com/coder/coder/coderd/authz/authztest"
8-
"github.com/stretchr/testify/require"
910
)
1011

1112
func Test_GroupedPermissions(t *testing.T) {
@@ -81,7 +82,9 @@ func Test_GroupedPermissions(t *testing.T) {
8182
}
8283

8384
for _, c := range cases {
85+
c := c
8486
t.Run(c.Name, func(t *testing.T) {
87+
t.Parallel()
8588
require.Equal(t, c.ExpPos+c.ExpNeg+c.ExpAbs, len(c.Lvl.All()), "set size")
8689
require.Equal(t, c.ExpPos, len(c.Lvl.Positive()), "correct num pos")
8790
require.Equal(t, c.ExpNeg, len(c.Lvl.Negative()), "correct num neg")

coderd/authz/authztest/permissions_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ package authztest_test
33
import (
44
"testing"
55

6-
"github.com/coder/coder/coderd/authz/authztest"
76
"github.com/stretchr/testify/require"
7+
8+
"github.com/coder/coder/coderd/authz/authztest"
89
)
910

1011
func Test_AllPermissions(t *testing.T) {

coderd/authz/authztest/role.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type Role struct {
2121
func NewRole(sets ...Iterable) *Role {
2222
setInterfaces := make([]Iterator, 0, len(sets))
2323
var retSize int
24-
var size int = 1
24+
size := 1
2525
for _, s := range sets {
2626
v := s.Iterator()
2727
setInterfaces = append(setInterfaces, v)
@@ -71,11 +71,11 @@ func (r *Role) Next() bool {
7171
for i := range r.PermissionSets {
7272
if r.PermissionSets[i].Next() {
7373
break
74-
} else {
75-
r.PermissionSets[i].Reset()
76-
if i == len(r.PermissionSets)-1 {
77-
return false
78-
}
74+
}
75+
76+
r.PermissionSets[i].Reset()
77+
if i == len(r.PermissionSets)-1 {
78+
return false
7979
}
8080
}
8181
return true

coderd/authz/authztest/role_test.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,18 @@ package authztest_test
33
import (
44
"testing"
55

6+
"github.com/stretchr/testify/require"
7+
68
"github.com/coder/coder/coderd/authz/authztest"
79
crand "github.com/coder/coder/cryptorand"
8-
"github.com/stretchr/testify/require"
910
)
1011

1112
func Test_NewRole(t *testing.T) {
13+
t.Parallel()
14+
1215
for i := 0; i < 50; i++ {
1316
sets := make([]authztest.Iterable, 1+(i%4))
14-
var total int = 1
17+
total := 1
1518
for j := range sets {
1619
size := 1 + must(crand.Intn(3))
1720
if i < 5 {

coderd/authz/authztest/set.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ func (s Set) String() string {
3333
if v == nil {
3434
continue
3535
}
36-
str.WriteString(sep)
37-
str.WriteString(v.String())
36+
_, _ = str.WriteString(sep)
37+
_, _ = str.WriteString(v.String())
3838
sep = ", "
3939
}
4040
return str.String()

coderd/authz/authztest/set_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ package authztest_test
33
import (
44
"testing"
55

6+
"github.com/stretchr/testify/require"
7+
68
"github.com/coder/coder/coderd/authz"
79
"github.com/coder/coder/coderd/authz/authztest"
810
crand "github.com/coder/coder/cryptorand"
9-
"github.com/stretchr/testify/require"
1011
)
1112

1213
func Test_Set(t *testing.T) {

coderd/authz/example_test.go

+8-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ package authz_test
33
import (
44
"testing"
55

6-
"github.com/coder/coder/coderd/authz"
76
"github.com/stretchr/testify/require"
7+
8+
"github.com/coder/coder/coderd/authz"
89
)
910

1011
// Test_Example gives some examples on how to use the authz library.
@@ -30,19 +31,22 @@ func Test_Example(t *testing.T) {
3031

3132
// TODO: Uncomment all assertions when implementation is done.
3233

34+
//nolint:paralleltest
3335
t.Run("ReadAllWorkspaces", func(t *testing.T) {
3436
// To read all workspaces on the site
3537
err := authz.Authorize(user, authz.ResourceWorkspace, authz.ActionRead)
3638
var _ = err
37-
//require.Error(t, err, "this user cannot read all workspaces")
39+
// require.Error(t, err, "this user cannot read all workspaces")
3840
})
3941

42+
//nolint:paralleltest
4043
t.Run("ReadOrgWorkspaces", func(t *testing.T) {
4144
// To read all workspaces on the org 'default'
4245
err := authz.Authorize(user, authz.ResourceWorkspace.Org("default"), authz.ActionRead)
4346
require.NoError(t, err, "this user can read all org workspaces in 'default'")
4447
})
4548

49+
//nolint:paralleltest
4650
t.Run("ReadMyWorkspace", func(t *testing.T) {
4751
// Note 'database.Workspace' could fulfill the object interface and be passed in directly
4852
err := authz.Authorize(user, authz.ResourceWorkspace.Org("default").Owner(user.UserID), authz.ActionRead)
@@ -52,10 +56,11 @@ func Test_Example(t *testing.T) {
5256
require.NoError(t, err, "this user can read workspace '1234'")
5357
})
5458

59+
//nolint:paralleltest
5560
t.Run("CreateNewSiteUser", func(t *testing.T) {
5661
err := authz.Authorize(user, authz.ResourceUser, authz.ActionCreate)
5762
var _ = err
58-
//require.Error(t, err, "this user cannot create new users")
63+
// require.Error(t, err, "this user cannot create new users")
5964
})
6065
}
6166

coderd/authz/object.go

+3
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,20 @@ func (z zObject) OrgOwnerID() string {
5151
}
5252

5353
// Org adds an org OwnerID to the resource
54+
//nolint:revive
5455
func (z zObject) Org(orgID string) zObject {
5556
z.OwnedByOrg = orgID
5657
return z
5758
}
5859

5960
// Owner adds an OwnerID to the resource
61+
//nolint:revive
6062
func (z zObject) Owner(id string) zObject {
6163
z.OwnedBy = id
6264
return z
6365
}
6466

67+
//nolint:revive
6568
func (z zObject) AsID(id string) zObject {
6669
z.ObjectID = id
6770
return z

coderd/authz/permission.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ package authz
22

33
import (
44
"fmt"
5-
"golang.org/x/xerrors"
65
"strings"
6+
7+
"golang.org/x/xerrors"
78
)
89

910
type permLevel string

coderd/authz/permission_test.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ package authz_test
33
import (
44
"testing"
55

6-
"github.com/coder/coder/coderd/authz"
76
"github.com/stretchr/testify/require"
7+
8+
"github.com/coder/coder/coderd/authz"
89
)
910

1011
func Test_PermissionString(t *testing.T) {
@@ -54,7 +55,10 @@ func Test_PermissionString(t *testing.T) {
5455
}
5556

5657
for _, c := range testCases {
58+
c := c
5759
t.Run(c.Name, func(t *testing.T) {
60+
t.Parallel()
61+
5862
require.Equal(t, c.Expected, c.Permission.String())
5963
perm, err := authz.ParsePermission(c.Expected)
6064
require.NoError(t, err, "parse perm string")
@@ -125,8 +129,11 @@ func Test_ParsePermissions(t *testing.T) {
125129
},
126130
},
127131
}
132+
128133
for _, c := range testCases {
134+
c := c
129135
t.Run(c.Name, func(t *testing.T) {
136+
t.Parallel()
130137
perms, err := authz.ParsePermissions(c.Str)
131138
if c.ErrStr != "" {
132139
require.Error(t, err)

coderd/authz/resources.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const (
1010
ResourceUser ResourceType = "user"
1111
)
1212

13-
func (t ResourceType) ID() string {
13+
func (ResourceType) ID() string {
1414
return ""
1515
}
1616

@@ -19,6 +19,7 @@ func (t ResourceType) ResourceType() ResourceType {
1919
}
2020

2121
// Org adds an org OwnerID to the resource
22+
//nolint:revive
2223
func (r ResourceType) Org(orgID string) zObject {
2324
return zObject{
2425
OwnedByOrg: orgID,
@@ -27,13 +28,15 @@ func (r ResourceType) Org(orgID string) zObject {
2728
}
2829

2930
// Owner adds an OwnerID to the resource
31+
//nolint:revive
3032
func (r ResourceType) Owner(id string) zObject {
3133
return zObject{
3234
OwnedBy: id,
3335
ObjectType: r,
3436
}
3537
}
3638

39+
//nolint:revive
3740
func (r ResourceType) AsID(id string) zObject {
3841
return zObject{
3942
ObjectID: id,

coderd/authz/subject.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,6 @@ func (s SubjectTODO) UserRoles() ([]Role, error) {
6464
return s.User, nil
6565
}
6666

67-
func (s SubjectTODO) Scopes() ([]Permission, error) {
67+
func (SubjectTODO) Scopes() ([]Permission, error) {
6868
return []Permission{}, nil
6969
}

0 commit comments

Comments
 (0)