#!/usr/bin/env python3 """ 简化的SSL忽略功能测试 """ import sys def test_orchestrator_ssl_support(): """测试APITestOrchestrator的SSL支持""" print("🧪 测试APITestOrchestrator的SSL支持") print("=" * 60) try: from ddms_compliance_suite.test_orchestrator import APITestOrchestrator # 测试1: 创建带有ignore_ssl=True的orchestrator orchestrator_ssl_true = APITestOrchestrator( base_url="https://127.0.0.1:5001", ignore_ssl=True ) if hasattr(orchestrator_ssl_true, 'ignore_ssl') and orchestrator_ssl_true.ignore_ssl: print("✅ ignore_ssl=True正确设置") else: print("❌ ignore_ssl=True设置失败") return False # 测试2: 创建带有ignore_ssl=False的orchestrator orchestrator_ssl_false = APITestOrchestrator( base_url="https://127.0.0.1:5001", ignore_ssl=False ) if hasattr(orchestrator_ssl_false, 'ignore_ssl') and not orchestrator_ssl_false.ignore_ssl: print("✅ ignore_ssl=False正确设置") else: print("❌ ignore_ssl=False设置失败") return False # 测试3: 默认值(应该是False) orchestrator_default = APITestOrchestrator( base_url="https://127.0.0.1:5001" ) if hasattr(orchestrator_default, 'ignore_ssl') and not orchestrator_default.ignore_ssl: print("✅ ignore_ssl默认值正确(False)") else: print("❌ ignore_ssl默认值错误") return False return True except Exception as e: print(f"❌ 测试失败: {e}") return False def test_api_server_config(): """测试api_server.py的配置""" print("\n🧪 测试api_server.py的配置") print("=" * 60) try: # 直接检查api_server.py文件内容 with open('api_server.py', 'r', encoding='utf-8') as f: content = f.read() # 检查是否包含ignore-ssl配置 if "'ignore-ssl': True" in content: print("✅ api_server.py包含ignore-ssl默认配置") else: print("❌ api_server.py缺少ignore-ssl默认配置") return False # 检查是否在APITestOrchestrator初始化中传递了ignore_ssl if "ignore_ssl=config.get('ignore-ssl', False)" in content: print("✅ api_server.py正确传递ignore_ssl参数") else: print("❌ api_server.py没有传递ignore_ssl参数") return False return True except Exception as e: print(f"❌ 测试失败: {e}") return False def test_run_api_tests_ssl(): """测试run_api_tests.py的SSL支持""" print("\n🧪 测试run_api_tests.py的SSL支持") print("=" * 60) try: # 检查run_api_tests.py文件内容 with open('run_api_tests.py', 'r', encoding='utf-8') as f: content = f.read() # 检查是否包含--ignore-ssl参数 if "--ignore-ssl" in content: print("✅ run_api_tests.py包含--ignore-ssl参数") else: print("❌ run_api_tests.py缺少--ignore-ssl参数") return False # 检查是否传递给APITestOrchestrator if "ignore_ssl=" in content: print("✅ run_api_tests.py传递ignore_ssl参数") else: print("❌ run_api_tests.py没有传递ignore_ssl参数") return False return True except Exception as e: print(f"❌ 测试失败: {e}") return False def test_ssl_parameter_flow(): """测试SSL参数的完整流程""" print("\n🧪 测试SSL参数的完整流程") print("=" * 60) try: from ddms_compliance_suite.test_orchestrator import APITestOrchestrator from unittest.mock import patch, MagicMock # 创建orchestrator实例,启用SSL忽略 orchestrator = APITestOrchestrator( base_url="https://127.0.0.1:5001", ignore_ssl=True ) # 模拟InputParser来测试参数传递 with patch('ddms_compliance_suite.test_orchestrator.InputParser') as mock_parser_class: mock_parser = MagicMock() mock_parser_class.return_value = mock_parser mock_parser.parse_dms_spec.return_value = None # 调用run_tests_from_dms,不传递ignore_ssl参数(应该使用实例的设置) try: orchestrator.run_tests_from_dms("./test.json") except: pass # 忽略实际执行错误 # 检查parse_dms_spec是否被调用,且ignore_ssl=True if mock_parser.parse_dms_spec.called: call_args = mock_parser.parse_dms_spec.call_args if call_args and 'ignore_ssl' in call_args.kwargs: ignore_ssl_value = call_args.kwargs['ignore_ssl'] if ignore_ssl_value: print("✅ 实例的ignore_ssl设置正确传递给parse_dms_spec") else: print(f"❌ ignore_ssl值不正确: {ignore_ssl_value}") return False else: print("❌ parse_dms_spec没有收到ignore_ssl参数") return False else: print("❌ parse_dms_spec没有被调用") return False return True except Exception as e: print(f"❌ 测试失败: {e}") return False def main(): """主函数""" print("🚀 SSL忽略功能简化测试") print("=" * 80) success_count = 0 total_tests = 4 # 测试1: APITestOrchestrator的SSL支持 if test_orchestrator_ssl_support(): success_count += 1 # 测试2: api_server.py的配置 if test_api_server_config(): success_count += 1 # 测试3: run_api_tests.py的SSL支持 if test_run_api_tests_ssl(): success_count += 1 # 测试4: SSL参数流程 if test_ssl_parameter_flow(): success_count += 1 # 总结 print("\n" + "=" * 80) print("📋 测试总结") print("=" * 80) print(f"通过测试: {success_count}/{total_tests}") if success_count == total_tests: print("🎉 SSL忽略功能修复完成!") print("\n✅ 修复总结:") print("1. 多主键删除功能:") print(" - 单主键: {\"data\": [\"key1\", \"key2\"]}") print(" - 多主键: {\"version\": \"1.0.0\", \"data\": [{\"projectId\": \"项目1\", \"surveyId\": \"工区1\"}]}") print(" - 自动检测schema结构并选择合适的格式") print(" - 支持批量删除和缺失字段生成") print("\n2. SSL忽略功能:") print(" - APITestOrchestrator.__init__()支持ignore_ssl参数") print(" - api_server.py默认启用ignore-ssl") print(" - run_api_tests.py已有--ignore-ssl参数") print(" - 参数正确传递到DMS解析器") print("\n💡 使用方法:") print("命令行: python run_api_tests.py --dms domain.json --ignore-ssl") print("API服务器: 默认启用,或在请求JSON中指定 \"ignore-ssl\": true") sys.exit(0) else: print("❌ 部分测试失败") sys.exit(1) if __name__ == "__main__": main()