Files
gitea/routers/api/actions/runner/interceptor_test.go
T
b140311d54 perf(actions): cache successful runner token verification (#39934) (#39959)
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>
2026-10-23 02:36:43 -07:00

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())
}