MCPcopy Create free account
hub / github.com/astercloud/aster / BenchmarkPathValidation

Function BenchmarkPathValidation

pkg/middleware/filesystem_security_test.go:377–396  ·  view source on GitHub ↗

BenchmarkPathValidation 性能测试: 路径验证

(b *testing.B)

Source from the content-addressed store, hash-verified

375
376// BenchmarkPathValidation 性能测试: 路径验证
377func BenchmarkPathValidation(b *testing.B) {
378 backend := backends.NewStateBackend()
379 middleware := NewFilesystemMiddleware(&FilesystemMiddlewareConfig{
380 Backend: backend,
381 EnablePathValidation: true,
382 AllowedPathPrefixes: []string{"/workspace/", "/tmp/"},
383 })
384
385 paths := []string{
386 "/workspace/file.txt",
387 "/tmp/cache.dat",
388 "workspace/nested/deep/file.go",
389 "/workspace/./redundant/../path/file.txt",
390 }
391
392 for i := 0; b.Loop(); i++ {
393 path := paths[i%len(paths)]
394 _, _ = middleware.validatePath(path)
395 }
396}
397
398// BenchmarkPathValidation_Disabled 性能测试: 禁用路径验证
399func BenchmarkPathValidation_Disabled(b *testing.B) {

Callers

nothing calls this directly

Calls 3

validatePathMethod · 0.95
NewStateBackendFunction · 0.92
NewFilesystemMiddlewareFunction · 0.85

Tested by

no test coverage detected