mirror of
https://github.com/go-gitea/gitea.git
synced 2026-10-24 03:54:00 +09:00
Backport of https://github.com/go-gitea/gitea/pull/39934 to release/v28. Runner token verification (PBKDF2) dominated CPU on instances with many runners. Successful verifications are now cached in a dedicated LRU. Conflict resolved by keeping v28's connect v1 interceptor and adding only the cache. _Backport prepared with Codet._ Co-authored-by: silverwind <me@silverwind.io>
27 lines
866 B
Go
27 lines
866 B
Go
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package runner
|
|
|
|
import (
|
|
"crypto/sha256"
|
|
"testing"
|
|
|
|
actions_model "gitea.dev/models/actions"
|
|
auth_model "gitea.dev/models/auth"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestVerifyRunnerToken(t *testing.T) {
|
|
verifiedRunnerTokens.Purge()
|
|
runner := &actions_model.ActionRunner{TokenSalt: "salt", TokenHash: auth_model.HashToken("token", "salt")}
|
|
assert.True(t, verifyRunnerToken(runner, "token"))
|
|
assert.True(t, verifyRunnerToken(runner, "token"))
|
|
assert.False(t, verifyRunnerToken(runner, "wrong"))
|
|
|
|
other := &actions_model.ActionRunner{TokenSalt: "salt", TokenHash: auth_model.HashToken("other", "salt")}
|
|
assert.False(t, verifyRunnerToken(other, "token"))
|
|
assert.Equal(t, [][sha256.Size]byte{sha256.Sum256([]byte("token"))}, verifiedRunnerTokens.Values())
|
|
}
|