Repository navigation
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: add-uos The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Reviewer's GuideFixes authorized-table queries to match the existing Sequence diagram for corrected device-enabled status lookupsequenceDiagram
participant ControlInterface
participant EnableSqlManager
participant SQLite
ControlInterface->>EnableSqlManager: isUniqueIdEnabled(key)
EnableSqlManager->>SQLite: SELECT exist FROM authorized WHERE unique_id=:key
SQLite-->>EnableSqlManager: exist value
EnableSqlManager-->>ControlInterface: enabled status
Flow diagram for authorized-record cleanupflowchart LR
A[clearEnableFromAuthorizedTable] --> B[DELETE FROM authorized WHERE exist=1]
B --> C[SQLite removes enabled authorization records]
C --> D[Records with exist=0 remain]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
deepin pr auto review🤖 AI 代码审查报告📊 总体评价
🔍 详细分析1. 语法逻辑 ✅评价: 语法正确,逻辑清晰 ✅ 通过 潜在问题: 建议: ['无语法逻辑问题'] 2. 代码质量 ✅评价: 代码结构清晰,注释完整 ✅ 通过 潜在问题: 建议: ['在 disableOutDevice_moduleAliasOnly_stripsTrailingTag 和 disableOutDevice_noIdentifiableId_skipsItem 的 Arrange 阶段添加 ut_qfileOpen_calls = 0', '移除 ut_wakeuputils.cpp 中重复的 #define private public / #define protected public 宏定义', '在 noSuchTable 测试的 removePathList 调用后添加 EXPECT_EQ(paths.size(), 0) 断言', '考虑在 TearDown() 中统一重置全局桩变量,避免测试间状态污染'] 3. 代码性能 ✅评价: 性能良好,资源使用合理 ✅ 通过 潜在问题: 建议: ['无性能问题'] 4. 代码安全 🔒评价: 存在0个安全漏洞 ✅ 通过
安全漏洞详情: 建议: ['ut_testdbhelper.h 中 tableHas 函数可考虑对 table 参数添加白名单校验,增强防御性编程', 'ut_qtSym 函数建议添加 dlopen/dlsym 返回值 nullptr 检查,避免测试中未定义行为'] 💡 改进建议代码示例// 建议修复:在 ut_enableutils.cpp 两个测试的 Arrange 阶段重置全局变量
// 1. disableOutDevice_moduleAliasOnly_stripsTrailingTag (约第 1561 行)
TEST_F(EnableUtilsTest, disableOutDevice_moduleAliasOnly_stripsTrailingTag)
{
Stub stub;
EnableSqlManager *mgr = EnableSqlManager::getInstance();
ASSERT_TRUE(UTDB::setup(mgr));
ut_isSafeSysfs_ret = true;
ut_qfileOpen_ret = true;
ut_qfileOpen_calls = 0; // 新增:重置全局计数器
ut_qfileWrites.clear();
stub.set(isSafeSysfsPath, ut_isSafeSysfs_stub);
stub.set((char *)ut_qtSym(UT_QSYM_QFILE_OPEN), ut_qfileOpen_stub);
stub.set((char *)ut_qtSym(UT_QSYM_QIOWRITE), ut_qfileWriteData_stub);
// ... 其余不变
}
// 2. disableOutDevice_noIdentifiableId_skipsItem (约第 1577 行)
TEST_F(EnableUtilsTest, disableOutDevice_noIdentifiableId_skipsItem)
{
Stub stub;
ASSERT_TRUE(UTDB::setup(EnableSqlManager::getInstance()));
ut_qfileOpen_ret = true;
ut_qfileOpen_calls = 0; // 新增:重置全局计数器
ut_qfileWrites.clear();
stub.set((char *)ut_qtSym(UT_QSYM_QFILE_OPEN), ut_qfileOpen_stub);
stub.set((char *)ut_qtSym(UT_QSYM_QIOWRITE), ut_qfileWriteData_stub);
// ... 其余不变
}本报告由 AI 代码审查工具自动生成 |
- 新增 ut_enablesqlmanager.cpp:31 个用例覆盖单例/initDB/authorized/ remove/printer/wake/net_wake/monitor_dev 读写与错误分支 - 新增 ut_testdbhelper.h:进程内 QTemporaryDir SQLite 注入夹具, 测试自建自清,不触碰 /var/lib 系统路径 - 标红疑似缺陷:isUniqueIdEnabled/clearEnableFromAuthorizedTable 引用不存在的 enable 列(用例 pinning,未改源码)
- 在上游已有用例基础上补充 disableOutDevice/getMapInfo/ enableNetworkByDBus/enableNetworkByIoctl 分支用例至 42 个 - 外部依赖全部桩化:DBus/socket/ioctl/QFile/sysfs,不依赖真实设备 - 标红疑似缺陷:USB authorized 打开失败 return 中断循环、 USB 接口号 [1-9]$ 强制归一化为 0(用例 pinning,未改源码)
- 在上游已有用例基础上补充 wakeOnLanIsOpen/setWakeOnLan/ writeTlpWolConfig/getPS2Syspath/updateWakeupDeviceInfo 等用例至 49 个 - ethtool ioctl/sysfs//proc/tlp 配置文件全部桩化,测试不写系统路径 - 三个目标文件行覆盖 97.5%、函数 100%、分支 84.3%,分级门禁全过
1. Root cause: authorized table CREATE statement only defines an exist boolean column, but clearEnableFromAuthorizedTable and isUniqueIdEnabled reference a non-existent enable column, causing SQLite error "no such column: enable" and silent failure 2. Fix: replace enable with exist in both SQL statements; change .arg(true) to .arg(1) to match SQLite boolean integer storage 3. Impact: isUniqueIdEnabled now returns actual exist value instead of always false; clearEnableFromAuthorizedTable now correctly deletes rows where exist=1; ControlInterface::isDeviceEnabled reports correct device enabled state Influence: 1. Test clearEnableFromAuthorizedTable with exist=true and exist=false rows to verify only exist=true rows are deleted 2. Test isUniqueIdEnabled with exist=true and exist=false records to verify correct return values 3. Verify ControlInterface::isDeviceEnabled DBus interface returns correct device enabled state after fix fix: 修复 authorized 表列名 enable 为 exist 1. 根因:authorized 表建表语句仅定义了 exist boolean 列,但 clearEnableFromAuthorizedTable 和 isUniqueIdEnabled 引用了不存在 的 enable 列,导致 SQLite 报错 no such column: enable 并静默失败 2. 方案:将两处 SQL 中的 enable 替换为 exist;.arg(true) 改为 .arg(1) 以匹配 SQLite 布尔值的整数存储方式 3. 影响:isUniqueIdEnabled 修复后返回实际 exist 值而非恒返回 false; clearEnableFromAuthorizedTable 正确删除 exist=1 的行; ControlInterface::isDeviceEnabled 正确报告设备启用状态 Influence: 1. 测试 clearEnableFromAuthorizedTable 在 exist=true 和 exist=false 行 共存时仅删除 exist=true 的行 2. 测试 isUniqueIdEnabled 在 exist=true 和 exist=false 记录下返回 正确的布尔值 3. 验证 ControlInterface::isDeviceEnabled DBus 接口修复后返回正确的 设备启用状态 PMS: BUG-UT-DEF-001
The license-check CI (SPDX Header Validation) requires the copyright year range of touched sources to end with the current year. Extend the SPDX-FileCopyrightText range of enablesqlmanager.cpp from 2019 ~ 2023 so that 2026 is covered and the SPDX summary reports 0 failures.
4de0b61 to
efafca9
Compare
|
TAG Bot New tag: 6.0.75 |
Root Cause Analysis
The
authorizedtable's CREATE statement (line 402) only defines anexistboolean column — there is noenablecolumn. However,clearEnableFromAuthorizedTable(line 101) andisUniqueIdEnabled(line 156) both reference a non-existentenablecolumn in their SQL statements, causing SQLite to error withno such column: enableand silently fail. Key evidence:insertDataToAuthorizedTablewrites to theexistcolumn;controlinterface.cpp:629passes anenablevariable directly into theexistparameter position, confirming semantic confusion between the two names.Fix
Replace
enablewithexistin both SQL statements. Change.arg(true)to.arg(1)in the DELETE statement to match SQLite's integer boolean storage format. Three pinning test cases updated to verify the fixed behavior.Change Safety Assessment
Risk Level: LOW
existcolumn already exists and is populated byinsertDataToAuthorizedTable). Behavioral change inisUniqueIdEnabled(from always-false to actual value) is the intended fix.ControlInterface::isDeviceEnabledDBus interface will now correctly report device enabled status instead of always returning false.clearEnableFromAuthorizedTablewill now correctly clear authorized records.clearEnableFromAuthorizedTablewith exist=true and exist=false rows to verify only exist=true rows are deleted. TestisUniqueIdEnabledwith exist=true and exist=false records to verify correct boolean return values.根因分析
authorized表建表语句(line 402)仅定义了existboolean 列,不存在enable列。但clearEnableFromAuthorizedTable(line 101)和isUniqueIdEnabled(line 156)的 SQL 语句引用了不存在的enable列,导致 SQLite 报错no such column: enable并静默失败。关键证据:insertDataToAuthorizedTable写入exist列;controlinterface.cpp:629将enable变量直接传入exist参数位置,证实语义混淆。修复方案
将两处 SQL 语句中的
enable替换为exist,并将 DELETE 语句中的.arg(true)改为.arg(1)以匹配 SQLite 布尔值的整数存储格式。3 个 pinning 测试用例同步更新。改动安全评估
风险等级:LOW
exist列已存在且由insertDataToAuthorizedTable写入)。isUniqueIdEnabled行为变更(从恒返回 false 到返回实际值)为预期修复行为。ControlInterface::isDeviceEnabledDBus 接口修复后将正确报告设备启用状态。clearEnableFromAuthorizedTable修复后可正确清理授权记录。clearEnableFromAuthorizedTable在 exist=true 和 exist=false 行共存时仅删除 exist=true 行;测试isUniqueIdEnabled返回正确布尔值。PMS: BUG-UT-DEF-001
Summary by Sourcery
Fix authorized-device state queries and expand isolated unit-test coverage for device and wake-control functionality.
Bug Fixes:
existcolumn, restoring authorized-record cleanup and device-enabled status reporting.Enhancements:
Tests: