| 123456789101112131415161718192021222324252627282930313233343536373839404142 |
- import pathlib
- import unittest
- PROJECT_ROOT = pathlib.Path(__file__).resolve().parent.parent
- class TestRouterScriptsBugsAndContracts(unittest.TestCase):
- """测试并锁定路由器 BusyBox 脚本中的文件原子性与选优漏洞,并纠正旧报告虚假报警"""
- def test_p1_router_local_update_atomic_file_write(self):
- """[P1/P2 修复验证] 验证 router_local_update.sh 采用 .tmp.$$ + mv -f 原子替换写入文件"""
- script_path = PROJECT_ROOT / "scripts" / "router_local_update.sh"
- content = script_path.read_text()
- self.assertIn("atomic_write_file()", content)
- self.assertIn(".tmp.$$", content)
- self.assertIn('atomic_write_file "$CURRENT_JSON_PATH"', content)
- def test_p2_router_local_update_filters_zero_speed(self):
- """[P2 修复验证] 验证 router_local_update.sh 在开启测速时优先挑选 download_speed > 0 的候选行"""
- script_path = PROJECT_ROOT / "scripts" / "router_local_update.sh"
- content = script_path.read_text()
- self.assertIn("speed = trim($6) + 0", content)
- self.assertIn("speed > 0", content)
- def test_recheck_correction_router_cfst_params_already_supported(self):
- """[复核纠偏] 验证初审报告关于 'router_local_update.sh 缺少 -dt/-dn/-dd 参数' 系虚假误报"""
- script_path = PROJECT_ROOT / "scripts" / "router_local_update.sh"
- content = script_path.read_text()
- # 验证源码中实际已存在这些参数映射
- self.assertIn('CFST_DOWNLOAD_COUNT', content)
- self.assertIn('-dn "$CFST_DOWNLOAD_COUNT"', content)
- self.assertIn('CFST_DOWNLOAD_TIME', content)
- self.assertIn('-dt "$CFST_DOWNLOAD_TIME"', content)
- self.assertIn('CFST_DISABLE_DOWNLOAD', content)
- self.assertIn('-dd', content)
- if __name__ == "__main__":
- unittest.main()
|