Skip to content

Commit 747708c

Browse files
committed
Run golang.org/x/tools/gopls/internal/analysis/modernize
1 parent 4d7625f commit 747708c

File tree

232 files changed

+1809
-1893
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

232 files changed

+1809
-1893
lines changed

auth/auth_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,7 +1121,7 @@ func TestAuthenticateTrustedJWT(t *testing.T) {
11211121
Expiry: jwt.NewNumericDate(time.Now().Add(5 * time.Minute)),
11221122
}
11231123

1124-
claimEmail := map[string]interface{}{"email": wantUserEmail}
1124+
claimEmail := map[string]any{"email": wantUserEmail}
11251125
builder := jwt.Signed(signer).Claims(claims).Claims(claimEmail)
11261126
token, err := builder.Serialize()
11271127
require.NoError(t, err, "Error serializing token using compact serialization format")
@@ -1162,7 +1162,7 @@ func TestAuthenticateTrustedJWT(t *testing.T) {
11621162
Expiry: jwt.NewNumericDate(time.Now().Add(5 * time.Minute)),
11631163
}
11641164

1165-
claimEmail := map[string]interface{}{"email": "emily@"}
1165+
claimEmail := map[string]any{"email": "emily@"}
11661166
builder := jwt.Signed(signer).Claims(claims).Claims(claimEmail)
11671167
token, err := builder.Serialize()
11681168
require.NoError(t, err, "Error serializing token using compact serialization format")
@@ -1197,7 +1197,7 @@ func TestAuthenticateTrustedJWT(t *testing.T) {
11971197
Expiry: jwt.NewNumericDate(time.Now().Add(5 * time.Minute)),
11981198
}
11991199

1200-
claimEmail := map[string]interface{}{"email": "layla@"}
1200+
claimEmail := map[string]any{"email": "layla@"}
12011201
builder := jwt.Signed(signer).Claims(claims).Claims(claimEmail)
12021202
token, err := builder.Serialize()
12031203
require.NoError(t, err, "Error serializing token using compact serialization format")

auth/auth_time_sensitive_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func TestAuthenticationSpeed(t *testing.T) {
3737
assert.True(t, user.Authenticate("goIsKewl"))
3838

3939
start := time.Now()
40-
for i := 0; i < 1000; i++ {
40+
for range 1000 {
4141
assert.True(t, user.Authenticate("goIsKewl"))
4242
}
4343
durationPerAuth := time.Since(start) / 1000

auth/cors.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ package auth
1010

1111
import (
1212
"net/http"
13+
"slices"
1314
"strings"
1415
)
1516

@@ -46,10 +47,8 @@ func MatchedOrigin(allowOrigins []string, rqOrigins []string) string {
4647
}
4748
}
4849
}
49-
for _, av := range allowOrigins {
50-
if av == "*" {
51-
return "*"
52-
}
50+
if slices.Contains(allowOrigins, "*") {
51+
return "*"
5352
}
5453
return ""
5554
}

auth/jwt.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"errors"
1414
"fmt"
1515
"net/url"
16+
"slices"
1617

1718
"github.com/coreos/go-oidc/v3/oidc"
1819
"github.com/couchbase/sync_gateway/base"
@@ -86,12 +87,7 @@ func (j JWTConfigCommon) ValidFor(ctx context.Context, issuer string, audiences
8687
if *j.ClientID == "" {
8788
return true
8889
}
89-
for _, aud := range audiences {
90-
if aud == *j.ClientID {
91-
return true
92-
}
93-
}
94-
return false
90+
return slices.Contains(audiences, *j.ClientID)
9591
}
9692

9793
var ErrNoMatchingProvider = errors.New("no matching OIDC/JWT provider")
@@ -209,7 +205,7 @@ func (l *LocalJWTAuthProvider) verifyToken(ctx context.Context, token string, _
209205
}
210206
base.DebugfCtx(ctx, base.KeyAuth, "Local JWT ID Token successfully parsed and verified (iss: %v; sub: %v)", base.UD(idToken.Issuer), base.UD(idToken.Subject))
211207

212-
var claims map[string]interface{}
208+
var claims map[string]any
213209
if err := idToken.Claims(&claims); err != nil {
214210
base.WarnfCtx(ctx, "Failed to unmarshal ID token claims: %v", err)
215211
}

auth/jwt_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -115,21 +115,21 @@ func TestJWTVerifyToken(t *testing.T) {
115115

116116
t.Run("valid RSA", test(baseProvider, CreateTestJWT(t, jose.RS256, testRSAKeypair, JWTHeaders{
117117
"kid": testRSAJWK.KeyID,
118-
}, map[string]interface{}{
118+
}, map[string]any{
119119
"iss": testIssuer,
120120
"aud": []string{testClientID},
121121
}), ""))
122122

123123
t.Run("valid EC", test(baseProvider, CreateTestJWT(t, jose.ES256, testECKeypair, JWTHeaders{
124124
"kid": testECJWK.KeyID,
125-
}, map[string]interface{}{
125+
}, map[string]any{
126126
"iss": testIssuer,
127127
"aud": []string{testClientID},
128128
}), ""))
129129

130130
t.Run("valid + expiry check", test(providerWithExpiryCheck, CreateTestJWT(t, jose.RS256, testRSAKeypair, JWTHeaders{
131131
"kid": testRSAJWK.KeyID,
132-
}, map[string]interface{}{
132+
}, map[string]any{
133133
"iss": testIssuer,
134134
"aud": []string{testClientID},
135135
"exp": time.Now().Add(time.Hour).Unix(),
@@ -139,7 +139,7 @@ func TestJWTVerifyToken(t *testing.T) {
139139

140140
t.Run("valid but expired", test(providerWithExpiryCheck, CreateTestJWT(t, jose.RS256, testRSAKeypair, JWTHeaders{
141141
"kid": testRSAJWK.KeyID,
142-
}, map[string]interface{}{
142+
}, map[string]any{
143143
"iss": testIssuer,
144144
"aud": []string{testClientID},
145145
// 2000-01-01T00:00:00Z
@@ -148,7 +148,7 @@ func TestJWTVerifyToken(t *testing.T) {
148148

149149
t.Run("valid but issued in the future", test(providerWithExpiryCheck, CreateTestJWT(t, jose.RS256, testRSAKeypair, JWTHeaders{
150150
"kid": testRSAJWK.KeyID,
151-
}, map[string]interface{}{
151+
}, map[string]any{
152152
"iss": testIssuer,
153153
"aud": []string{testClientID},
154154
// 3000-01-01T00:00:00Z
@@ -158,7 +158,7 @@ func TestJWTVerifyToken(t *testing.T) {
158158

159159
invalidSignature := CreateTestJWT(t, jose.RS256, testRSAKeypair, JWTHeaders{
160160
"kid": testRSAJWK.KeyID,
161-
}, map[string]interface{}{
161+
}, map[string]any{
162162
"iss": testIssuer,
163163
"aud": []string{testClientID},
164164
})
@@ -167,21 +167,21 @@ func TestJWTVerifyToken(t *testing.T) {
167167

168168
t.Run("valid JWT signed with an unknown key", test(baseProvider, CreateTestJWT(t, jose.RS256, testExtraKeypair, JWTHeaders{
169169
"kid": testExtraJWK.KeyID,
170-
}, map[string]interface{}{
170+
}, map[string]any{
171171
"iss": testIssuer,
172172
"aud": []string{testClientID},
173173
}), anyError))
174174

175175
t.Run("valid JWT signed with a mismatching KID", test(baseProvider, CreateTestJWT(t, jose.RS256, testExtraKeypair, JWTHeaders{
176176
"kid": testRSAJWK.KeyID,
177-
}, map[string]interface{}{
177+
}, map[string]any{
178178
"iss": testIssuer,
179179
"aud": []string{testClientID},
180180
}), anyError))
181181

182182
t.Run("valid RSA signed with key with use=enc", test(baseProvider, CreateTestJWT(t, jose.RS256, testRSAKeypair, JWTHeaders{
183183
"kid": testEncRSAJWK.KeyID,
184-
}, map[string]interface{}{
184+
}, map[string]any{
185185
"iss": testIssuer,
186186
"aud": []string{testClientID},
187187
}), anyError))
@@ -195,7 +195,7 @@ func TestJWTVerifyToken(t *testing.T) {
195195

196196
t.Run("valid RSA with invalid issuer", test(baseProvider, CreateTestJWT(t, jose.RS256, testRSAKeypair, JWTHeaders{
197197
"kid": testRSAJWK.KeyID,
198-
}, map[string]interface{}{
198+
}, map[string]any{
199199
"iss": "nonsense",
200200
"aud": []string{testClientID},
201201
}), "id token issued by a different provider"))

auth/jwt_test_utils.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ import (
1818

1919
// These are not in jwt_test.go to allow use in tests from other packages.
2020

21-
type JWTHeaders map[jose.HeaderKey]interface{}
21+
type JWTHeaders map[jose.HeaderKey]any
2222

2323
// CreateTestJWT creates and signs a valid JWT with the given headers and claims.
2424
// The key must be valid for use with gopkg.in/square/go-jose.v2 (https://pkg.go.dev/gopkg.in/square/go-jose.v2#readme-supported-key-types),
2525
// and the alg must match the key.
26-
func CreateTestJWT(t *testing.T, alg jose.SignatureAlgorithm, key interface{}, headers JWTHeaders, claims map[string]interface{}) string {
26+
func CreateTestJWT(t *testing.T, alg jose.SignatureAlgorithm, key any, headers JWTHeaders, claims map[string]any) string {
2727
t.Helper()
2828

2929
signerOpts := new(jose.SignerOptions)

auth/oidc.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
"net/http"
3434
"net/url"
3535
"reflect"
36+
"slices"
3637
"strconv"
3738
"strings"
3839
"sync"
@@ -220,11 +221,9 @@ func (opm OIDCProviderMap) GetProviderForIssuer(ctx context.Context, issuer stri
220221
clientID := base.ValDefault(provider.ClientID, "")
221222
if provider.Issuer == issuer && clientID != "" {
222223
// Iterate over the audiences looking for a match
223-
for _, aud := range audiences {
224-
if clientID == aud {
225-
base.DebugfCtx(ctx, base.KeyAuth, "Provider matches, returning")
226-
return provider
227-
}
224+
if slices.Contains(audiences, clientID) {
225+
base.DebugfCtx(ctx, base.KeyAuth, "Provider matches, returning")
226+
return provider
228227
}
229228
}
230229
}
@@ -436,7 +435,7 @@ func getJWTUsername(provider JWTConfigCommon, identity *Identity) (username stri
436435
}
437436

438437
// formatUsername returns the string representation of the given username value.
439-
func formatUsername(value interface{}) (string, error) {
438+
func formatUsername(value any) (string, error) {
440439
switch valueType := value.(type) {
441440
case string:
442441
return valueType, nil
@@ -725,7 +724,7 @@ func (op *OIDCProvider) stopDiscoverySync() {
725724
// amount of time in seconds that the fetched responses are allowed to be used again (from the
726725
// time when a request is made). The second value (ok) is true if max-age exists, and false if not.
727726
func cacheControlMaxAge(header http.Header) (maxAge time.Duration, ok bool, err error) {
728-
for _, field := range strings.Split(header.Get("Cache-Control"), ",") {
727+
for field := range strings.SplitSeq(header.Get("Cache-Control"), ",") {
729728
parts := strings.SplitN(strings.TrimSpace(field), "=", 2)
730729
k := strings.ToLower(strings.TrimSpace(parts[0]))
731730
if k != "max-age" {

auth/oidc_test.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -970,7 +970,7 @@ func TestIsStandardDiscovery(t *testing.T) {
970970
func TestFormatUsername(t *testing.T) {
971971
tests := []struct {
972972
name string
973-
username interface{}
973+
username any
974974
usernameExpected string
975975
errorExpected error
976976
}{{
@@ -1014,7 +1014,7 @@ func TestJWTRolesChannels(t *testing.T) {
10141014
)
10151015
type simulatedLogin struct {
10161016
explicitRoles, explicitChannels []string
1017-
claims map[string]interface{}
1017+
claims map[string]any
10181018
expectedRoles, expectedChannels []string
10191019
}
10201020
type testCase struct {
@@ -1037,7 +1037,7 @@ func TestJWTRolesChannels(t *testing.T) {
10371037
rolesClaimName: "roles",
10381038
logins: []simulatedLogin{
10391039
{
1040-
claims: map[string]interface{}{"roles": []string{"foo"}},
1040+
claims: map[string]any{"roles": []string{"foo"}},
10411041
expectedRoles: []string{"foo"},
10421042
expectedChannels: []string{"!"},
10431043
},
@@ -1048,7 +1048,7 @@ func TestJWTRolesChannels(t *testing.T) {
10481048
rolesClaimName: "roles",
10491049
logins: []simulatedLogin{
10501050
{
1051-
claims: map[string]interface{}{},
1051+
claims: map[string]any{},
10521052
expectedRoles: []string{},
10531053
expectedChannels: []string{"!"},
10541054
},
@@ -1060,7 +1060,7 @@ func TestJWTRolesChannels(t *testing.T) {
10601060
logins: []simulatedLogin{
10611061
{
10621062
explicitRoles: []string{"bar"},
1063-
claims: map[string]interface{}{"roles": []string{"foo"}},
1063+
claims: map[string]any{"roles": []string{"foo"}},
10641064
expectedRoles: []string{"foo", "bar"},
10651065
expectedChannels: []string{"!"},
10661066
},
@@ -1071,12 +1071,12 @@ func TestJWTRolesChannels(t *testing.T) {
10711071
rolesClaimName: "roles",
10721072
logins: []simulatedLogin{
10731073
{
1074-
claims: map[string]interface{}{"roles": []string{"foo"}},
1074+
claims: map[string]any{"roles": []string{"foo"}},
10751075
expectedRoles: []string{"foo"},
10761076
expectedChannels: []string{"!"},
10771077
},
10781078
{
1079-
claims: map[string]interface{}{"roles": []string{}},
1079+
claims: map[string]any{"roles": []string{}},
10801080
expectedRoles: []string{},
10811081
expectedChannels: []string{"!"},
10821082
},
@@ -1088,7 +1088,7 @@ func TestJWTRolesChannels(t *testing.T) {
10881088
logins: []simulatedLogin{
10891089
{
10901090
explicitRoles: []string{"foo"},
1091-
claims: map[string]interface{}{"roles": []string{"foo"}},
1091+
claims: map[string]any{"roles": []string{"foo"}},
10921092
expectedRoles: []string{"foo"},
10931093
expectedChannels: []string{"!"},
10941094
},
@@ -1100,13 +1100,13 @@ func TestJWTRolesChannels(t *testing.T) {
11001100
logins: []simulatedLogin{
11011101
{
11021102
explicitRoles: []string{"foo"},
1103-
claims: map[string]interface{}{"roles": []string{"foo"}},
1103+
claims: map[string]any{"roles": []string{"foo"}},
11041104
expectedRoles: []string{"foo"},
11051105
expectedChannels: []string{"!"},
11061106
},
11071107
{
11081108
explicitRoles: []string{"foo"},
1109-
claims: map[string]interface{}{"roles": []string{}},
1109+
claims: map[string]any{"roles": []string{}},
11101110
expectedRoles: []string{"foo"},
11111111
expectedChannels: []string{"!"},
11121112
},
@@ -1117,12 +1117,12 @@ func TestJWTRolesChannels(t *testing.T) {
11171117
rolesClaimName: "roles",
11181118
logins: []simulatedLogin{
11191119
{
1120-
claims: map[string]interface{}{"roles": []string{"foo"}},
1120+
claims: map[string]any{"roles": []string{"foo"}},
11211121
expectedRoles: []string{"foo"},
11221122
expectedChannels: []string{"!"},
11231123
},
11241124
{
1125-
claims: map[string]interface{}{"roles": []string{"bar"}},
1125+
claims: map[string]any{"roles": []string{"bar"}},
11261126
expectedRoles: []string{"bar"},
11271127
expectedChannels: []string{"!"},
11281128
},
@@ -1133,7 +1133,7 @@ func TestJWTRolesChannels(t *testing.T) {
11331133
channelsClaimName: "channels",
11341134
logins: []simulatedLogin{
11351135
{
1136-
claims: map[string]interface{}{"channels": []string{"foo"}},
1136+
claims: map[string]any{"channels": []string{"foo"}},
11371137
expectedRoles: []string{},
11381138
expectedChannels: []string{"!", "foo"},
11391139
},
@@ -1145,7 +1145,7 @@ func TestJWTRolesChannels(t *testing.T) {
11451145
logins: []simulatedLogin{
11461146
{
11471147
explicitChannels: []string{"bar"},
1148-
claims: map[string]interface{}{"channels": []string{"foo"}},
1148+
claims: map[string]any{"channels": []string{"foo"}},
11491149
expectedRoles: []string{},
11501150
expectedChannels: []string{"!", "foo", "bar"},
11511151
},
@@ -1157,7 +1157,7 @@ func TestJWTRolesChannels(t *testing.T) {
11571157
channelsClaimName: "channels",
11581158
logins: []simulatedLogin{
11591159
{
1160-
claims: map[string]interface{}{"roles": []string{"rFoo"}, "channels": []string{"cBar"}},
1160+
claims: map[string]any{"roles": []string{"rFoo"}, "channels": []string{"cBar"}},
11611161
expectedRoles: []string{"rFoo"},
11621162
expectedChannels: []string{"!", "cBar"},
11631163
},
@@ -1169,7 +1169,7 @@ func TestJWTRolesChannels(t *testing.T) {
11691169
channelsClaimName: "channels",
11701170
logins: []simulatedLogin{
11711171
{
1172-
claims: map[string]interface{}{"roles": []string{"rFoo"}, "channels": []string{"cBar"}},
1172+
claims: map[string]any{"roles": []string{"rFoo"}, "channels": []string{"cBar"}},
11731173
explicitRoles: []string{"rBaz"},
11741174
explicitChannels: []string{"cQux"},
11751175
expectedRoles: []string{"rFoo", "rBaz"},

0 commit comments

Comments
 (0)