mirror of
https://github.com/coder/coder.git
synced 2025-07-12 00:14:10 +00:00
- Update go.mod to use Go 1.24.1 - Update GitHub Actions setup-go action to use Go 1.24.1 - Fix linting issues with golangci-lint by: - Updating to golangci-lint v1.57.1 (more compatible with Go 1.24.1) 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Claude <claude@anthropic.com>
52 lines
1.3 KiB
Go
52 lines
1.3 KiB
Go
package agentrsa_test
|
|
|
|
import (
|
|
"crypto/rsa"
|
|
"math/rand/v2"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/coder/coder/v2/agent/agentrsa"
|
|
)
|
|
|
|
func TestGenerateDeterministicKey(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
key1 := agentrsa.GenerateDeterministicKey(1234)
|
|
key2 := agentrsa.GenerateDeterministicKey(1234)
|
|
|
|
assert.Equal(t, key1, key2)
|
|
assert.EqualExportedValues(t, key1, key2)
|
|
}
|
|
|
|
var result *rsa.PrivateKey
|
|
|
|
func BenchmarkGenerateDeterministicKey(b *testing.B) {
|
|
var r *rsa.PrivateKey
|
|
|
|
for range b.N {
|
|
// always record the result of DeterministicPrivateKey to prevent
|
|
// the compiler eliminating the function call.
|
|
// #nosec G404 - Using math/rand is acceptable for benchmarking deterministic keys
|
|
r = agentrsa.GenerateDeterministicKey(rand.Int64())
|
|
}
|
|
|
|
// always store the result to a package level variable
|
|
// so the compiler cannot eliminate the Benchmark itself.
|
|
result = r
|
|
}
|
|
|
|
func FuzzGenerateDeterministicKey(f *testing.F) {
|
|
testcases := []int64{0, 1234, 1010101010}
|
|
for _, tc := range testcases {
|
|
f.Add(tc) // Use f.Add to provide a seed corpus
|
|
}
|
|
f.Fuzz(func(t *testing.T, seed int64) {
|
|
key1 := agentrsa.GenerateDeterministicKey(seed)
|
|
key2 := agentrsa.GenerateDeterministicKey(seed)
|
|
assert.Equal(t, key1, key2)
|
|
assert.EqualExportedValues(t, key1, key2)
|
|
})
|
|
}
|