fix: allow explicit native repair owner process queries
This commit is contained in:
1 parent
747ce1add2
commit
b90a9bbfab
3 files changed
+54
No files matched your search
@@ -811,3 +811,46 @@ def test_malformed_native_success_never_reopens_or_counts_repaired(tmp_path, mon
|
||||
assert result.recovery_attempts[0]['status'] == 'UNCONFIRMED'
|
||||
assert result.recovery_attempts[0]['release']['safe_to_continue'] is False
|
||||
assert maintenance_counts([result])['repaired'] == 0
|
||||
|
||||
|
||||
@pytest.mark.parametrize('owner', [None, 'iCDBProjectBackup.exe', 'ReuseBlockImporter.exe'])
|
||||
def test_repair_release_uses_real_process_query_contract(tmp_path, monkeypatch, owner):
|
||||
from types import SimpleNamespace
|
||||
import win32com.client
|
||||
from cbb_refresh_verify.native_repair import repair_release_state
|
||||
request, diagnosis, target = target_fixture(tmp_path)
|
||||
queried = []
|
||||
names = ('ExpeditionPCB.exe', 'LibraryManager.exe', 'iCDBProjectBackup.exe',
|
||||
'ReuseBlockImporter.exe', 'cscript.exe')
|
||||
queries = {"SELECT ProcessId, ParentProcessId, ExecutablePath, CommandLine "
|
||||
f"FROM Win32_Process WHERE Name='{name}'": name for name in names}
|
||||
def query(wql):
|
||||
name = queries[wql]
|
||||
queried.append(name)
|
||||
return ([SimpleNamespace(ProcessId='456', ParentProcessId='1',
|
||||
ExecutablePath=f'C:\\Mentor\\{name}', CommandLine=f'{name} target')]
|
||||
if name == owner else [])
|
||||
def service(moniker):
|
||||
assert moniker == 'winmgmts:'
|
||||
return SimpleNamespace(ExecQuery=query)
|
||||
monkeypatch.setattr(win32com.client, 'GetObject', service)
|
||||
# Keep pcb_processes, _processes, _process_details and release validation real.
|
||||
state = repair_release_state(request, target, complete_native_success(target))
|
||||
assert 'error' not in state
|
||||
assert queried == list(names)
|
||||
assert state['safe_to_continue'] is (owner is None)
|
||||
assert state['remaining_pids'] == ([] if owner is None else [456])
|
||||
assert state['database_exclusive'] is (owner is None)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('name', [
|
||||
'other.exe', 'icdbprojectbackup.exe',
|
||||
"iCDBProjectBackup.exe' OR Name='other.exe",
|
||||
"ReuseBlockImporter.exe' OR Name='other.exe",
|
||||
])
|
||||
def test_repair_process_queries_still_reject_arbitrary_input(monkeypatch, name):
|
||||
import win32com.client
|
||||
from cbb_refresh_verify.mentor_adapter import _process_details
|
||||
monkeypatch.setattr(win32com.client, 'GetObject', lambda *a: pytest.fail('Unsupported name reached WMI'))
|
||||
with pytest.raises(ValueError, match='Unsupported process query'):
|
||||
_process_details(name)
|
||||
Reference in new issue
Block a user