tighten scan session and HTTP paths

This commit is contained in:
ZacharyZcR
2026-05-23 07:46:53 +08:00
parent 1a714f6a0c
commit 3c7823355d
7 changed files with 89 additions and 66 deletions
+21
View File
@@ -1,6 +1,7 @@
package core
import (
"context"
"crypto/tls"
"fmt"
"net"
@@ -32,6 +33,26 @@ web_scanner_test.go - WebScanner核心逻辑测试
缓存操作需要验证并发安全性。"
*/
func TestDetectHTTPServiceOnlyContextHonorsCancellation(t *testing.T) {
cfg := common.GetGlobalConfig()
oldTimeout := cfg.Network.WebTimeout
cfg.Network.WebTimeout = 2 * time.Second
defer func() { cfg.Network.WebTimeout = oldTimeout }()
session := common.NewScanSession(cfg, common.NewState(), common.GetFlagVars())
ctx, cancel := context.WithCancel(context.Background())
cancel()
start := time.Now()
detected := GetWebPortDetector().DetectHTTPServiceOnlyContext(ctx, "203.0.113.1", 80, cfg, session)
if detected {
t.Fatal("canceled web detection should not report a service")
}
if elapsed := time.Since(start); elapsed > 200*time.Millisecond {
t.Fatalf("canceled web detection took %s", elapsed)
}
}
// =============================================================================
// 核心逻辑测试:Web服务识别
// =============================================================================