Policy Tests
OpenFrame Documentation
Get the most out of OpenFrame · Book 30 minutes with Conrad, 25 years in IT. He'll show you what Mingo and Fae can take off your list.
OpenFrame Documentation
Policy Tests are integration tests in the openframe-test-service-core library that validate the Fleet policy lifecycle used by OpenFrame monitoring: policy creation, host targeting, compliance re-evaluation, aggregation, and deletion. The tenant repository runs this library through its OpenFrame test service; the implementation lives in the OpenFrame OSS Library artifact com.openframe.oss:openframe-test-service-core.
The suite covers two deliberately different fixtures:
flowchart TD
TestRunner["Test Runner"] --> CreateTest["Create Policy Test"]
TestRunner --> TriggerTest["Trigger Policy Test"]
TestRunner --> DeleteTest["Delete Policy Test"]
CreateTest --> MonitoringApi["Monitoring API"]
CreateTest --> DeviceApi["Device API"]
TriggerTest --> MonitoringApi
TriggerTest --> DeviceApi
DeleteTest --> MonitoringApi
MonitoringApi --> Fleet["Fleet Policy Service"]
DeviceApi --> Fleet
Fleet --> Host["Online Managed Host"]
Host --> Fleet
Fleet --> PolicyCounts["Policy Compliance Counts"]
The tests use MonitoringApi for policy operations and Fleet scheduling actions. DeviceApi locates eligible devices and reads host policy timestamps. Fleet evaluates policies on managed hosts, then aggregates host outcomes into the policy's passing and failing host counts.
flowchart LR
Create["Create Policy"] --> Assign["Assign Online Windows Host"]
Assign --> Refetch["Request Host Re-evaluation"]
Refetch --> VerifyHost["Verify Host Policy Timestamp"]
VerifyHost --> Trigger["Trigger Fleet Aggregation"]
Trigger --> VerifyCounts["Verify Fresh Compliance Counts"]
VerifyCounts --> Delete["Delete Policy"]
Creation and assignment establish the fixtures that compliance checks expect. Compliance checks do not trust Fleet's periodic aggregation timing: they refetch targeted hosts, explicitly request the cleanup-and-aggregation schedule, and wait for a newer aggregation timestamp. Deletion verifies that both untargeted and host-targeted policies can be removed.
CreatePolicyTest creates the two fixture shapes.
Both cases are tagged feature and device. The targeted case has an environmental prerequisite: at least one online Windows device must be available, must expose a tool connection, and must have a Fleet identifier.
TriggerPolicyTest validates compliance after producing a fresh state. Its tests are tagged mdm and scheduled.
Before asserting compliance, the test resolves each named fixture and verifies its query against the generator's expected definition. This detects fixture drift early: changing a policy query resets Fleet results, so a count-only assertion would otherwise obscure the underlying cause.
For a policy with hosts, the test:
host_count_updated_at to advance.A Fleet conflict response means an aggregation was already running rather than that this test initiated one. The test therefore retries until it receives the accepted status, within its 60-second acceptance window. It then allows up to 180 seconds for an aggregation stamp newer than the captured baseline.
The Empty-policy case normalizes a null host list to an empty list, triggers the same aggregation process without host refetches, and asserts zero passing and zero failing hosts. This reflects Fleet's representation of an untargeted policy: no hosts evaluate it, but aggregation still updates its count timestamp.
sequenceDiagram
participant Test as "Trigger Policy Test"
participant DeviceApi as "Device API"
participant MonitoringApi as "Monitoring API"
participant Fleet
participant Host as "Managed Host"
Test->>MonitoringApi: Read policy and verify seeded query
Test->>DeviceApi: Read host policy timestamp
Test->>MonitoringApi: Request host refetch
MonitoringApi->>Fleet: Forward refetch
Fleet->>Host: Request policy evaluation
Host->>Fleet: Report updated policy state
Test->>DeviceApi: Poll for newer host timestamp
Test->>MonitoringApi: Trigger cleanup and aggregation
MonitoringApi->>Fleet: Request aggregation schedule
Test->>MonitoringApi: Poll policy detail
Fleet-->>MonitoringApi: Return refreshed counts and timestamp
MonitoringApi-->>Test: Return aggregated policy
DeletePolicyTest is tagged archive and covers removal of both fixture variants.
Each case lists policies, resolves a policy by its expected name, deletes it through MonitoringApi, and verifies that the deletion response includes the deleted policy identifier. The separate cases prove that deletion works for an unassigned policy and for a policy that has a device assignment.
| Contract | Verified behavior |
|---|---|
| Policy definition | Creation returns the requested identifier-bearing policy with matching name, description, and query. |
| Target assignment | The Windows version policy contains the selected device in its include-any host collection. |
| Seeded fixture integrity | Trigger tests require the expected policy names and exact generated queries. |
| Fresh host evaluation | A targeted host's policy-update timestamp advances after refetch. |
| Fresh aggregation | host_count_updated_at advances after Fleet accepts an aggregation trigger. |
| Targeted compliance | The Windows version policy has no failing hosts and all assigned hosts pass. |
| Untargeted compliance | The Empty policy has no assigned hosts and reports zero passing and failing hosts. |
| Deletion response | The returned deleted-ID collection contains the requested policy ID. |