Skip to content

Commit 7b118ac

Browse files
committed
Check indexes in dbmem
Might have no match, and a -1 will panic.
1 parent d54e56a commit 7b118ac

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

coderd/database/dbmem/dbmem.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -1310,7 +1310,8 @@ func (q *FakeQuerier) DeleteOAuth2ProviderAppTokensByAppAndUserID(_ context.Cont
13101310
keyIdx := slices.IndexFunc(q.apiKeys, func(key database.APIKey) bool {
13111311
return key.ID == token.APIKeyID
13121312
})
1313-
if q.oauth2ProviderAppSecrets[secretIdx].AppID == arg.AppID && q.apiKeys[keyIdx].UserID == arg.UserID {
1313+
if secretIdx != -1 && q.oauth2ProviderAppSecrets[secretIdx].AppID == arg.AppID &&
1314+
keyIdx != -1 && q.apiKeys[keyIdx].UserID == arg.UserID {
13141315
keyIDsToDelete = append(keyIDsToDelete, token.APIKeyID)
13151316
} else {
13161317
tokens = append(tokens, token)
@@ -2312,7 +2313,7 @@ func (q *FakeQuerier) GetOAuth2ProviderAppsByUserID(_ context.Context, userID uu
23122313
keyIdx := slices.IndexFunc(q.apiKeys, func(key database.APIKey) bool {
23132314
return key.ID == token.APIKeyID
23142315
})
2315-
if q.apiKeys[keyIdx].UserID == userID {
2316+
if keyIdx != -1 && q.apiKeys[keyIdx].UserID == userID {
23162317
tokens = append(tokens, token)
23172318
}
23182319
}

0 commit comments

Comments
 (0)