|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
| 3 | +from pathlib import PureWindowsPath |
3 | 4 | from typing import TYPE_CHECKING, Any |
4 | 5 | from unittest.mock import Mock |
5 | 6 |
|
@@ -308,6 +309,55 @@ def test_windows_user_from_sam(target_win_users: Target) -> None: |
308 | 309 | assert users[1].home == windows_path("C:\\Users\\John") |
309 | 310 |
|
310 | 311 |
|
| 312 | +def test_windows_user_registry_parsing(target_win_users: Target) -> None: |
| 313 | + """Verify ProfileList parsing relies on resolved path objects.""" |
| 314 | + |
| 315 | + # 1. Setup the Registry Mock Structure |
| 316 | + sid_str = "S-1-5-21-99999-88888-77777-1001" |
| 317 | + raw_path_str = "C:\\Users\\DuaLipa" |
| 318 | + |
| 319 | + # Create the subkey (The user SID) |
| 320 | + subkey_mock = Mock() |
| 321 | + subkey_mock.name = sid_str |
| 322 | + |
| 323 | + # Create the value for ProfileImagePath |
| 324 | + value_mock = Mock() |
| 325 | + value_mock.value = raw_path_str |
| 326 | + subkey_mock.value.return_value = value_mock |
| 327 | + |
| 328 | + # Create the registry key |
| 329 | + key_mock = Mock() |
| 330 | + key_mock.subkeys.return_value = [subkey_mock] |
| 331 | + |
| 332 | + # We must overwrite the real .registry attribute with a Mock object first |
| 333 | + target_win_users.registry = Mock() |
| 334 | + # Now we can configure the .keys() method on that mock |
| 335 | + target_win_users.registry.keys.return_value = [key_mock] |
| 336 | + |
| 337 | + # 2. Setup the Resolve Mock |
| 338 | + resolved_path = PureWindowsPath("C:/Users/DuaLipa") |
| 339 | + |
| 340 | + # Overwrite the real .resolve method with a Mock |
| 341 | + target_win_users.resolve = Mock(return_value=resolved_path) |
| 342 | + |
| 343 | + # Disable SAM and Machine SID |
| 344 | + target_win_users.sam = Mock(return_value=[]) |
| 345 | + target_win_users.machine_sid = Mock(return_value=iter([])) |
| 346 | + |
| 347 | + # 4. Run the function |
| 348 | + users = list(target_win_users.users()) |
| 349 | + |
| 350 | + assert len(users) == 1 |
| 351 | + record = users[0] |
| 352 | + |
| 353 | + assert record.sid == sid_str |
| 354 | + assert record.name == "DuaLipa" |
| 355 | + assert record.home == resolved_path |
| 356 | + |
| 357 | + # Verify resolve was called correctly |
| 358 | + target_win_users.resolve.assert_called_with(raw_path_str) |
| 359 | + |
| 360 | + |
311 | 361 | @pytest.mark.parametrize( |
312 | 362 | ("registry_value", "expected_hostname"), |
313 | 363 | [ |
|
0 commit comments