fix: add missing PCE parameter to GenerateTokenPair calls in test files
The JWT GenerateTokenPair functions were updated to require a PCE (Password Changed Epoch) parameter for token invalidation. This commit updates test files in concurrent and performance packages to include this parameter. - internal/concurrent/concurrent_test.go: 2 call sites fixed - internal/performance/benchmark_test.go: 3 call sites fixed - internal/performance/performance_test.go: 4 call sites fixed
This commit is contained in:
@@ -103,7 +103,7 @@ func runTokenValidationConcurrencyTest(t *testing.T, testName string, config Con
|
|||||||
jwtManager := auth.NewJWT("concurrent-test-secret", 2*time.Hour, 7*24*time.Hour)
|
jwtManager := auth.NewJWT("concurrent-test-secret", 2*time.Hour, 7*24*time.Hour)
|
||||||
tokens := make([]string, 100)
|
tokens := make([]string, 100)
|
||||||
for i := 0; i < 100; i++ {
|
for i := 0; i < 100; i++ {
|
||||||
accessToken, _, err := jwtManager.GenerateTokenPair(int64(i+1), fmt.Sprintf("user%d", i))
|
accessToken, _, err := jwtManager.GenerateTokenPair(int64(i+1), fmt.Sprintf("user%d", i), 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("生成Token失败: %v", err)
|
t.Fatalf("生成Token失败: %v", err)
|
||||||
}
|
}
|
||||||
@@ -192,7 +192,7 @@ func runConcurrencyTest(t *testing.T, testName string, config ConcurrencyTestCon
|
|||||||
}
|
}
|
||||||
reqStart := time.Now()
|
reqStart := time.Now()
|
||||||
// 模拟 Token 生成操作(代替真实登录)
|
// 模拟 Token 生成操作(代替真实登录)
|
||||||
_, _, err := jwtManager.GenerateTokenPair(int64(id+1), fmt.Sprintf("user%d", id))
|
_, _, err := jwtManager.GenerateTokenPair(int64(id+1), fmt.Sprintf("user%d", id), 0)
|
||||||
latency := time.Since(reqStart)
|
latency := time.Since(reqStart)
|
||||||
mu.Lock()
|
mu.Lock()
|
||||||
latencies = append(latencies, latency)
|
latencies = append(latencies, latency)
|
||||||
|
|||||||
@@ -68,13 +68,13 @@ func BenchmarkJWTGenerateToken(b *testing.B) {
|
|||||||
|
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
_, _, _ = jwtManager.GenerateTokenPair(int64(i), "testuser")
|
_, _, _ = jwtManager.GenerateTokenPair(int64(i), "testuser", 0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkJWTValidateToken(b *testing.B) {
|
func BenchmarkJWTValidateToken(b *testing.B) {
|
||||||
jwtManager := auth.NewJWT("benchmark-secret-key-32bytes!", 2*time.Hour, 7*24*time.Hour)
|
jwtManager := auth.NewJWT("benchmark-secret-key-32bytes!", 2*time.Hour, 7*24*time.Hour)
|
||||||
token, _, _ := jwtManager.GenerateTokenPair(1, "testuser")
|
token, _, _ := jwtManager.GenerateTokenPair(1, "testuser", 0)
|
||||||
|
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
@@ -87,7 +87,7 @@ func BenchmarkJWTGenerateAndValidate(b *testing.B) {
|
|||||||
|
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
token, _, _ := jwtManager.GenerateTokenPair(int64(i), "testuser")
|
token, _, _ := jwtManager.GenerateTokenPair(int64(i), "testuser", 0)
|
||||||
jwtManager.ValidateAccessToken(token)
|
jwtManager.ValidateAccessToken(token)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -148,7 +148,7 @@ func BenchmarkTokenGeneration(b *testing.B) {
|
|||||||
|
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
_, _, err := jwtManager.GenerateTokenPair(1, "benchuser")
|
_, _, err := jwtManager.GenerateTokenPair(1, "benchuser", 0)
|
||||||
latency := time.Since(start).Nanoseconds()
|
latency := time.Since(start).Nanoseconds()
|
||||||
metrics.RecordLatency(latency)
|
metrics.RecordLatency(latency)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
@@ -165,7 +165,7 @@ func BenchmarkTokenGeneration(b *testing.B) {
|
|||||||
// BenchmarkTokenValidation JWT验证性能测试
|
// BenchmarkTokenValidation JWT验证性能测试
|
||||||
func BenchmarkTokenValidation(b *testing.B) {
|
func BenchmarkTokenValidation(b *testing.B) {
|
||||||
jwtManager := auth.NewJWT("benchmark-secret", 2*time.Hour, 7*24*time.Hour)
|
jwtManager := auth.NewJWT("benchmark-secret", 2*time.Hour, 7*24*time.Hour)
|
||||||
accessToken, _, err := jwtManager.GenerateTokenPair(1, "benchuser")
|
accessToken, _, err := jwtManager.GenerateTokenPair(1, "benchuser", 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Fatalf("生成Token失败: %v", err)
|
b.Fatalf("生成Token失败: %v", err)
|
||||||
}
|
}
|
||||||
@@ -201,7 +201,7 @@ func TestP99LatencyThreshold(t *testing.T) {
|
|||||||
operation: func() time.Duration {
|
operation: func() time.Duration {
|
||||||
jwtManager := auth.NewJWT("test-secret", 2*time.Hour, 7*24*time.Hour)
|
jwtManager := auth.NewJWT("test-secret", 2*time.Hour, 7*24*time.Hour)
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
jwtManager.GenerateTokenPair(1, "testuser")
|
jwtManager.GenerateTokenPair(1, "testuser", 0)
|
||||||
return time.Since(start)
|
return time.Since(start)
|
||||||
},
|
},
|
||||||
thresholdMs: 100,
|
thresholdMs: 100,
|
||||||
@@ -322,7 +322,7 @@ func TestMemoryUsage(t *testing.T) {
|
|||||||
|
|
||||||
jwtManager := auth.NewJWT("test-secret", 2*time.Hour, 7*24*time.Hour)
|
jwtManager := auth.NewJWT("test-secret", 2*time.Hour, 7*24*time.Hour)
|
||||||
for i := 0; i < 10000; i++ {
|
for i := 0; i < 10000; i++ {
|
||||||
accessToken, _, _ := jwtManager.GenerateTokenPair(int64(i%100), "testuser")
|
accessToken, _, _ := jwtManager.GenerateTokenPair(int64(i%100), "testuser", 0)
|
||||||
jwtManager.ValidateAccessToken(accessToken)
|
jwtManager.ValidateAccessToken(accessToken)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user