Skip to content

Commit c61ceb9

Browse files
committed
Linting
1 parent 930e7dd commit c61ceb9

File tree

7 files changed

+30
-38
lines changed

7 files changed

+30
-38
lines changed

coderd/coderdtest/coderdtest.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,22 +1108,6 @@ func SDKError(t *testing.T, err error) *codersdk.Error {
11081108
return cerr
11091109
}
11101110

1111-
const testRSAPrivateKey = `-----BEGIN RSA PRIVATE KEY-----
1112-
MIICXQIBAAKBgQDLets8+7M+iAQAqN/5BVyCIjhTQ4cmXulL+gm3v0oGMWzLupUS
1113-
v8KPA+Tp7dgC/DZPfMLaNH1obBBhJ9DhS6RdS3AS3kzeFrdu8zFHLWF53DUBhS92
1114-
5dCAEuJpDnNizdEhxTfoHrhuCmz8l2nt1pe5eUK2XWgd08Uc93h5ij098wIDAQAB
1115-
AoGAHLaZeWGLSaen6O/rqxg2laZ+jEFbMO7zvOTruiIkL/uJfrY1kw+8RLIn+1q0
1116-
wLcWcuEIHgKKL9IP/aXAtAoYh1FBvRPLkovF1NZB0Je/+CSGka6wvc3TGdvppZJe
1117-
rKNcUvuOYLxkmLy4g9zuY5qrxFyhtIn2qZzXEtLaVOHzPQECQQDvN0mSajpU7dTB
1118-
w4jwx7IRXGSSx65c+AsHSc1Rj++9qtPC6WsFgAfFN2CEmqhMbEUVGPv/aPjdyWk9
1119-
pyLE9xR/AkEA2cGwyIunijE5v2rlZAD7C4vRgdcMyCf3uuPcgzFtsR6ZhyQSgLZ8
1120-
YRPuvwm4cdPJMmO3YwBfxT6XGuSc2k8MjQJBAI0+b8prvpV2+DCQa8L/pjxp+VhR
1121-
Xrq2GozrHrgR7NRokTB88hwFRJFF6U9iogy9wOx8HA7qxEbwLZuhm/4AhbECQC2a
1122-
d8h4Ht09E+f3nhTEc87mODkl7WJZpHL6V2sORfeq/eIkds+H6CJ4hy5w/bSw8tjf
1123-
sz9Di8sGIaUbLZI2rd0CQQCzlVwEtRtoNCyMJTTrkgUuNufLP19RZ5FpyXxBO5/u
1124-
QastnN77KfUwdj3SJt44U/uh1jAIv4oSLBr8HYUkbnI8
1125-
-----END RSA PRIVATE KEY-----`
1126-
11271111
func DeploymentValues(t testing.TB) *codersdk.DeploymentValues {
11281112
var cfg codersdk.DeploymentValues
11291113
opts := cfg.Options()

coderd/coderdtest/oidctest/idp.go

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,7 @@ type FakeIDP struct {
7070
// Custom authentication for the client. This is useful if you want
7171
// to test something like PKI auth vs a client_secret.
7272
hookAuthenticateClient func(t testing.TB, req *http.Request) (url.Values, error)
73-
// Optional if you want to use a real http network request assuming
74-
// it is not directed to the IDP.
75-
defaultClient *http.Client
76-
serve bool
73+
serve bool
7774
}
7875

7976
type FakeIDPOpt func(idp *FakeIDP)
@@ -135,8 +132,9 @@ func WithIssuer(issuer string) func(*FakeIDP) {
135132
}
136133

137134
const (
138-
authorizePath = "/oauth2/authorize"
135+
// nolint:gosec // It thinks this is a secret lol
139136
tokenPath = "/oauth2/token"
137+
authorizePath = "/oauth2/authorize"
140138
keysPath = "/oauth2/keys"
141139
userInfoPath = "/oauth2/userinfo"
142140
)
@@ -237,15 +235,15 @@ func (f *FakeIDP) AttemptLogin(t testing.TB, client *codersdk.Client, idTokenCla
237235
var err error
238236

239237
cli := f.HTTPClient(client.HTTPClient)
240-
shallowCpyCli := &(*cli)
238+
shallowCpyCli := *cli
241239

242240
if shallowCpyCli.Jar == nil {
243241
shallowCpyCli.Jar, err = cookiejar.New(nil)
244242
require.NoError(t, err, "failed to create cookie jar")
245243
}
246244

247245
unauthenticated := codersdk.New(client.URL)
248-
unauthenticated.HTTPClient = shallowCpyCli
246+
unauthenticated.HTTPClient = &shallowCpyCli
249247

250248
return f.LoginWithClient(t, unauthenticated, idTokenClaims, opts...)
251249
}
@@ -296,7 +294,7 @@ func (f *FakeIDP) LoginWithClient(t testing.TB, client *codersdk.Client, idToken
296294

297295
t.Cleanup(func() {
298296
if res.Body != nil {
299-
res.Body.Close()
297+
_ = res.Body.Close()
300298
}
301299
})
302300

@@ -326,7 +324,7 @@ func (f *FakeIDP) OIDCCallback(t testing.TB, state string, idTokenClaims jwt.Map
326324

327325
t.Cleanup(func() {
328326
if resp.Body != nil {
329-
resp.Body.Close()
327+
_ = resp.Body.Close()
330328
}
331329
})
332330
return resp, nil
@@ -444,7 +442,7 @@ func (f *FakeIDP) httpHandler(t testing.TB) http.Handler {
444442
// w/e and clicking "Allow". They will be redirected back to the redirect
445443
// when this is done.
446444
mux.Handle(authorizePath, http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
447-
f.logger.Info(r.Context(), "HTTP Call Authorize", slog.F("url", r.URL.String()))
445+
f.logger.Info(r.Context(), "http call authorize", slog.F("url", r.URL.String()))
448446

449447
clientID := r.URL.Query().Get("client_id")
450448
if !assert.Equal(t, f.clientID, clientID, "unexpected client_id") {
@@ -495,7 +493,7 @@ func (f *FakeIDP) httpHandler(t testing.TB) http.Handler {
495493

496494
mux.Handle(tokenPath, http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
497495
values, err := f.authenticateOIDCClientRequest(t, r)
498-
f.logger.Info(r.Context(), "HTTP Call Token",
496+
f.logger.Info(r.Context(), "http call token",
499497
slog.Error(err),
500498
slog.F("values", values.Encode()),
501499
)
@@ -508,10 +506,11 @@ func (f *FakeIDP) httpHandler(t testing.TB) http.Handler {
508506
if !ok {
509507
return "unknown"
510508
}
511-
if _, ok := email.(string); !ok {
509+
emailStr, ok := email.(string)
510+
if !ok {
512511
return "wrong-type"
513512
}
514-
return email.(string)
513+
return emailStr
515514
}
516515

517516
var claims jwt.MapClaims
@@ -593,7 +592,7 @@ func (f *FakeIDP) httpHandler(t testing.TB) http.Handler {
593592

594593
mux.Handle(userInfoPath, http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
595594
token, err := f.authenticateBearerTokenRequest(t, r)
596-
f.logger.Info(r.Context(), "HTTP Call UserInfo",
595+
f.logger.Info(r.Context(), "http call user info",
597596
slog.Error(err),
598597
slog.F("url", r.URL.String()),
599598
)
@@ -612,7 +611,7 @@ func (f *FakeIDP) httpHandler(t testing.TB) http.Handler {
612611
}))
613612

614613
mux.Handle(keysPath, http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
615-
f.logger.Info(r.Context(), "HTTP Call Keys")
614+
f.logger.Info(r.Context(), "http call keys")
616615
set := jose.JSONWebKeySet{
617616
Keys: []jose.JSONWebKey{
618617
{
@@ -626,7 +625,7 @@ func (f *FakeIDP) httpHandler(t testing.TB) http.Handler {
626625
}))
627626

628627
mux.NotFound(func(rw http.ResponseWriter, r *http.Request) {
629-
f.logger.Error(r.Context(), "HTTP Call NotFound", slog.F("path", r.URL.Path))
628+
f.logger.Error(r.Context(), "http call not found", slog.F("path", r.URL.Path))
630629
t.Errorf("unexpected request to IDP at path %q. Not supported", r.URL.Path)
631630
})
632631

coderd/coderdtest/oidctest/idp_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ import (
1717
)
1818

1919
// TestFakeIDPBasicFlow tests the basic flow of the fake IDP.
20+
// It is done all in memory with no actual network requests.
2021
func TestFakeIDPBasicFlow(t *testing.T) {
22+
t.Parallel()
23+
2124
fake := oidctest.NewFakeIDP(t,
2225
oidctest.WithLogging(t, nil),
2326
)

coderd/coderdtest/oidctest/map.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@ func NewSyncMap[K, V any]() *SyncMap[K, V] {
1313
}
1414
}
1515

16-
func (s *SyncMap[K, V]) Store(k K, v V) {
17-
s.m.Store(k, v)
16+
func (m *SyncMap[K, V]) Store(k K, v V) {
17+
m.m.Store(k, v)
1818
}
1919

20-
func (s *SyncMap[K, V]) Load(key K) (value V, ok bool) {
21-
v, ok := s.m.Load(key)
20+
//nolint:forcetypeassert
21+
func (m *SyncMap[K, V]) Load(key K) (value V, ok bool) {
22+
v, ok := m.m.Load(key)
2223
if !ok {
2324
var empty V
2425
return empty, false
@@ -30,6 +31,7 @@ func (m *SyncMap[K, V]) Delete(key K) {
3031
m.m.Delete(key)
3132
}
3233

34+
//nolint:forcetypeassert
3335
func (m *SyncMap[K, V]) LoadAndDelete(key K) (actual V, loaded bool) {
3436
act, loaded := m.m.LoadAndDelete(key)
3537
if !loaded {
@@ -39,6 +41,7 @@ func (m *SyncMap[K, V]) LoadAndDelete(key K) (actual V, loaded bool) {
3941
return act.(V), loaded
4042
}
4143

44+
//nolint:forcetypeassert
4245
func (m *SyncMap[K, V]) LoadOrStore(key K, value V) (actual V, loaded bool) {
4346
act, loaded := m.m.LoadOrStore(key, value)
4447
if !loaded {
@@ -56,6 +59,7 @@ func (m *SyncMap[K, V]) CompareAndDelete(key K, old V) (deleted bool) {
5659
return m.m.CompareAndDelete(key, old)
5760
}
5861

62+
//nolint:forcetypeassert
5963
func (m *SyncMap[K, V]) Swap(key K, value V) (previous any, loaded bool) {
6064
previous, loaded = m.m.Swap(key, value)
6165
if !loaded {
@@ -65,6 +69,7 @@ func (m *SyncMap[K, V]) Swap(key K, value V) (previous any, loaded bool) {
6569
return previous.(V), loaded
6670
}
6771

72+
//nolint:forcetypeassert
6873
func (m *SyncMap[K, V]) Range(f func(key K, value V) bool) {
6974
m.m.Range(func(key, value interface{}) bool {
7075
return f(key.(K), value.(V))

coderd/userauth_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
// This test specifically tests logging in with OIDC when an expired
3333
// OIDC session token exists.
3434
// The token refreshing should not happen since we are reauthenticating.
35+
// nolint:bodyclose
3536
func TestOIDCOauthLoginWithExisting(t *testing.T) {
3637
t.Parallel()
3738

@@ -946,7 +947,7 @@ func TestUserOIDC(t *testing.T) {
946947
oauthURL, err := client.URL.Parse("/api/v2/users/oidc/callback")
947948
require.NoError(t, err)
948949

949-
req, err := http.NewRequest("GET", oauthURL.String(), nil)
950+
req, err := http.NewRequestWithContext(context.Background(), "GET", oauthURL.String(), nil)
950951
require.NoError(t, err)
951952
resp, err := client.HTTPClient.Do(req)
952953
require.NoError(t, err)

coderd/users_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,7 @@ func TestPostLogout(t *testing.T) {
406406
})
407407
}
408408

409+
// nolint:bodyclose
409410
func TestPostUsers(t *testing.T) {
410411
t.Parallel()
411412
t.Run("NoAuth", func(t *testing.T) {

enterprise/coderd/userauth_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ func TestUserOIDC(t *testing.T) {
129129
t.Run("BlockAssignRoles", func(t *testing.T) {
130130
t.Parallel()
131131

132-
const oidcRoleName = "TemplateAuthor"
133132
runner := setupOIDCTest(t, oidcTestConfig{
134133
Config: func(cfg *coderd.OIDCConfig) {
135134
cfg.AllowSignups = true

0 commit comments

Comments
 (0)