mirror of
https://github.com/shadow1ng/fscan.git
synced 2026-09-25 12:41:53 +08:00
refactor: 删除 deadcode 检测出的未使用函数
- proxy/detector.go: 删除 IsSOCKS5Standard, IsProxyInitialized - findnet.go: 删除 NetworkInfo.OneLine, TreeFormat 方法 - port_scan.go: 删除 estimateScanTime 函数 - web_scanner.go: 删除 GetFingerprints 函数 - 清理相关测试代码
This commit is contained in:
@@ -577,122 +577,6 @@ func TestWebServiceCache_Concurrent(t *testing.T) {
|
||||
// 指纹缓存测试
|
||||
// =============================================================================
|
||||
|
||||
// TestFingerprintCache 测试指纹缓存操作
|
||||
func TestFingerprintCache(t *testing.T) {
|
||||
// 清空缓存
|
||||
fingerprintCacheMutex.Lock()
|
||||
fingerprintCache = make(map[string][]string)
|
||||
fingerprintCacheMutex.Unlock()
|
||||
|
||||
t.Run("存储和读取指纹", func(t *testing.T) {
|
||||
fingerprints := []string{"nginx", "http", "ssl"}
|
||||
SetFingerprints("192.168.1.1", 80, fingerprints)
|
||||
|
||||
result, exists := GetFingerprints("192.168.1.1", 80)
|
||||
if !exists {
|
||||
t.Error("GetFingerprints应返回exists=true")
|
||||
}
|
||||
if len(result) != 3 {
|
||||
t.Errorf("指纹数量 = %d, 期望 3", len(result))
|
||||
}
|
||||
for i, fp := range fingerprints {
|
||||
if result[i] != fp {
|
||||
t.Errorf("指纹[%d] = %q, 期望 %q", i, result[i], fp)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("空指纹列表不存储", func(t *testing.T) {
|
||||
SetFingerprints("192.168.1.2", 80, []string{})
|
||||
|
||||
_, exists := GetFingerprints("192.168.1.2", 80)
|
||||
if exists {
|
||||
t.Error("空指纹列表不应被存储")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("不存在的指纹", func(t *testing.T) {
|
||||
result, exists := GetFingerprints("192.168.1.3", 80)
|
||||
if exists {
|
||||
t.Error("不存在的指纹应返回exists=false")
|
||||
}
|
||||
if result != nil {
|
||||
t.Errorf("不存在的指纹应返回nil, 实际 %v", result)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("覆盖写入指纹", func(t *testing.T) {
|
||||
fingerprints1 := []string{"nginx"}
|
||||
fingerprints2 := []string{"apache", "php"}
|
||||
|
||||
SetFingerprints("192.168.1.4", 80, fingerprints1)
|
||||
SetFingerprints("192.168.1.4", 80, fingerprints2)
|
||||
|
||||
result, _ := GetFingerprints("192.168.1.4", 80)
|
||||
if len(result) != 2 {
|
||||
t.Errorf("覆盖后指纹数量 = %d, 期望 2", len(result))
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("不同端口独立存储指纹", func(t *testing.T) {
|
||||
fp80 := []string{"http"}
|
||||
fp443 := []string{"https"}
|
||||
|
||||
SetFingerprints("192.168.1.5", 80, fp80)
|
||||
SetFingerprints("192.168.1.5", 443, fp443)
|
||||
|
||||
result80, _ := GetFingerprints("192.168.1.5", 80)
|
||||
result443, _ := GetFingerprints("192.168.1.5", 443)
|
||||
|
||||
if result80[0] != "http" {
|
||||
t.Errorf("端口80指纹 = %v, 期望 ['http']", result80)
|
||||
}
|
||||
if result443[0] != "https" {
|
||||
t.Errorf("端口443指纹 = %v, 期望 ['https']", result443)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// TestFingerprintCache_Concurrent 测试指纹缓存并发安全性
|
||||
func TestFingerprintCache_Concurrent(t *testing.T) {
|
||||
// 清空缓存
|
||||
fingerprintCacheMutex.Lock()
|
||||
fingerprintCache = make(map[string][]string)
|
||||
fingerprintCacheMutex.Unlock()
|
||||
|
||||
var wg sync.WaitGroup
|
||||
numGoroutines := 100
|
||||
|
||||
// 并发写入
|
||||
for i := 0; i < numGoroutines; i++ {
|
||||
wg.Add(1)
|
||||
go func(id int) {
|
||||
defer wg.Done()
|
||||
fingerprints := []string{"test"}
|
||||
SetFingerprints("192.168.1.1", id, fingerprints)
|
||||
}(i)
|
||||
}
|
||||
|
||||
// 并发读取
|
||||
for i := 0; i < numGoroutines; i++ {
|
||||
wg.Add(1)
|
||||
go func(id int) {
|
||||
defer wg.Done()
|
||||
_, _ = GetFingerprints("192.168.1.1", id)
|
||||
}(i)
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
|
||||
// 验证数据完整性
|
||||
for i := 0; i < numGoroutines; i++ {
|
||||
_, exists := GetFingerprints("192.168.1.1", i)
|
||||
if !exists {
|
||||
t.Errorf("端口 %d 指纹应存在", i)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
// 边界情况测试
|
||||
// =============================================================================
|
||||
|
||||
Reference in New Issue
Block a user