Skip to content

Commit 73552bc

Browse files
committed
Check indexes in dbmem
Might have no match, and a -1 will panic.
1 parent f69a629 commit 73552bc

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

coderd/database/dbmem/dbmem.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,7 +1300,8 @@ func (q *FakeQuerier) DeleteOAuth2ProviderAppTokensByAppAndUserID(_ context.Cont
13001300
keyIdx := slices.IndexFunc(q.apiKeys, func(key database.APIKey) bool {
13011301
return key.ID == token.APIKeyID
13021302
})
1303-
if q.oauth2ProviderAppSecrets[secretIdx].AppID == arg.AppID && q.apiKeys[keyIdx].UserID == arg.UserID {
1303+
if secretIdx != -1 && q.oauth2ProviderAppSecrets[secretIdx].AppID == arg.AppID &&
1304+
keyIdx != -1 && q.apiKeys[keyIdx].UserID == arg.UserID {
13041305
keyIDsToDelete = append(keyIDsToDelete, token.APIKeyID)
13051306
} else {
13061307
tokens = append(tokens, token)
@@ -2370,7 +2371,7 @@ func (q *FakeQuerier) GetOAuth2ProviderAppsByUserID(_ context.Context, userID uu
23702371
keyIdx := slices.IndexFunc(q.apiKeys, func(key database.APIKey) bool {
23712372
return key.ID == token.APIKeyID
23722373
})
2373-
if q.apiKeys[keyIdx].UserID == userID {
2374+
if keyIdx != -1 && q.apiKeys[keyIdx].UserID == userID {
23742375
tokens = append(tokens, token)
23752376
}
23762377
}

0 commit comments

Comments
 (0)