1. Overview
The PolicyLoaderTests.cpp executable validates successful policy parsing, rule-ID assignment, safety constraints, trusted/denied conflict detection, symlink rejection, and secure policy ownership/permission enforcement.
The file integrates the following components, APIs, or runtime concepts:
- PolicyLoader
- PolicySecurity
- std::filesystem temporary files
2. Valid Policy Coverage
A complete version-2 enforce policy is written to a temporary file. Assertions verify engine actions, burst controls, /run behavior, integrity interval, service/home settings, and the contents of trusted-app, trusted, denied, protected, and ignored vectors.
3. Rule ID and Flags
The test confirms sequential rule IDs across sections and checks required/recursive flags: trusted entries begin at ID 1, denied follows them, then protected and ignored rules continue the same global sequence.
4. Unsafe Global Blocking
A policy requesting global_metadata_action=block must throw std::runtime_error, validating the audit-only design of broad global metadata surveillance.
5. Burst Range Validation
An undersized threshold/window/cooldown configuration is expected to fail, covering numeric safety bounds and cooldown/window consistency.
6. Trust Conflicts and Enforcement Preconditions
The test rejects a path that is simultaneously a trusted application and denied executable, and rejects enforce mode with blocking elevation actions when no trusted executable is defined.
7. PolicySecurity Checks
A symbolic link to the policy must fail even without ownership enforcement. The real policy is then made group-writable, and a secure-ownership read must fail.
8. Cleanup and Result
Temporary files are removed and the executable prints PolicyLoaderTests: OK.
9. Runtime and Security Considerations
- Negative tests are security-oriented: unsafe global enforcement, malformed burst tuning, trust conflicts, symlinks, and weak permissions are all expected failures.
