How Collectors Are Tested
How a collector's values are checked against written definitions on every change, and against real accounts every night and before every release.
A collector reads a service's API and writes the values that controls are checked against. A wrong value rarely looks wrong. If an MFA coverage figure says 75% when it should say 66%, nothing on the page tells you.
This page explains how those values are tested. The tools it describes are in the epack SDK, so any collector can use them. The sandboxes are real accounts that Locktivity runs for the collectors it publishes.
Why ordinary tests are not enough
In an ordinary unit test, the same person writes the input and the expected answer, from the same understanding of the service. If that understanding is wrong, the test agrees with the bug. These four errors get past such tests, and each one has its own check:
| What goes wrong | For example | What catches it |
|---|---|---|
| The logic is wrong | A suspended account is counted as an active user. | Comparing with Derive |
| Right for one account, wrong for another | The collector handles each setting on its own, but not a combination it was never tested with. | Variations and rules |
| Missing data looks like a real value | A field the API didn't return is read as 0 or false, so a percentage looks better than it is. | Field faults |
| The API differs from its documentation | A documented field always comes back empty. | Sandboxes |
Two loops
The checks run in two loops. The fast loop runs on every change to a collector, in seconds, against a simulated service. The slow loop runs every night and before every release, against a real account.
1. A roster describes a pretend company
A roster is a JSON file that lists the people, roles and settings of a test account. It names everything in the service's own words, so a simulator can answer as the service would. Its terms block maps each of those words to a generic meaning, and the roster is refused if it uses a word the block doesn't map.
This roster has four people. Dan's account is suspended, and Ben's admin role can only read settings:
{
"version": 1,
"vendor": "example-idp",
"accounts": {
"ana": {"kind": "Person", "enabled": true,
"roles": ["Org Owner"], "mfa": "SecurityKey"},
"ben": {"kind": "Person", "enabled": true,
"roles": ["Read-Only Admin"], "mfa": "AuthenticatorApp"},
"cara": {"kind": "Person", "enabled": true},
"dan": {"kind": "Person", "enabled": false, "mfa": "AuthenticatorApp"}
},
"terms": {
"account_kinds": {"Person": "member"},
"roles": {"Org Owner": "super_admin", "Read-Only Admin": "none"},
"mfa_methods": {"SecurityKey": "phishing_resistant",
"AuthenticatorApp": "mfa"}
}
}
The roster says nothing about the service's API or the collector's code. It describes the company, not how to read it.
2. Derive works out the right values
Derive is a function in the epack SDK. It reads a roster's generic meanings and computes the value each normalized field should have, following the definitions in the normalized schemas. It never looks at a collector's code.
For the roster above:
- Users: 3. A suspended account is not a user, so Dan is left out.
- MFA coverage: 66%. Ana and Ben have MFA, Cara doesn't. Two of three is 66.7%, rounded down so it never looks better than the data.
- Privileged users: 1. Ana's role maps to
super_admin. Ben's maps tonone, because an admin who can only read can't change anyone's access.
Each of those rules is written in the field's definition. The Normalized Fields reference lists every field with its definition and a link to the line of Derive that computes it.
3. The simulator answers like the service
Each collector has a simulator: a stand-in for the service's API that answers for the people and settings in a roster. Its answers are copies of real answers recorded from a sandbox, changed to match the roster. The simulator fails when it is asked to give an answer the recordings don't hold, unless it lists that answer with a reason. That keeps it from drifting into a version of the API that doesn't exist.
4. Compare
The collector runs with its real code against the simulator, and each normalized value it writes is compared with the value Derive computed. Suppose the collector counted Dan:
| Value | Derive | Collector that counts Dan |
|---|---|---|
| Users | 3 | 4 |
| MFA coverage | 66% | 75% |
| Privileged users | 1 | 1 |
Every difference is one of three things:
- A collector bug. The collector is fixed.
- A definition nobody had decided. The decision is written into the field's definition and into Derive together.
- A value the service doesn't provide. The collector leaves it out and records a gap that says why.
5. Variations and rules
One company is one test. The test kit changes the roster one thing at a time, then two things at once, then builds random companies, and Derive computes the right values for each one. That finds the combinations nobody thought to write a test for.
Some checks need no exact answer. Rules such as "giving another person MFA never lowers MFA coverage" run over every variation.
6. Field faults
The last fast check removes data on purpose. It takes good answers and deletes one field at a time. After each deletion, every value the collector writes must either stay the same or be left out with a gap. A value that quietly changes, such as a percentage that rises because a missing field was read as "no", fails the check. From epack v0.12.3 the check runs in every collector's suite. Turning it off takes a waiver with a reason and an expiry, and the pack's build file reports the waiver, so a reader can see what a collector's tests leave out and until when.
Sandboxes
The fast loop is only as good as the understanding behind it. The simulator copies real answers, but the roster and the definitions are still written by people. A sandbox checks that understanding against the service itself.
A sandbox is a real account at the service, owned by Locktivity and used only for testing. It is set up to cover the cases that matter, such as an admin without MFA or a suspended account, and some of its settings are weak on purpose.
- Built from code. Terraform creates its people and settings, and a nightly check reports any change made by hand.
- Described by its own roster. Its expected values come from that roster and the definitions, never from the collector's output, so a wrong value fails instead of becoming the expected one.
- Checked every night. The current release runs against it with read-only access, and a failure alerts the team.
- A gate for each release. A new collector version is published only after it matches its sandbox. When a release changes a value on purpose, the expectation records the version it changed in, so each version is held to its own value.
- Recorded. Its answers are recorded with names and IDs scrubbed and committed to the collector's repository. The simulator copies them.
For a collector with a sandbox, its page on registry.epack.dev lists the values checked, why the test account has each one, and whether it matched.
What this does not show
- A sandbox holds the cases it was built with. A customer's account can have a setting or a size no sandbox has. The field-fault check and gaps are what keep an unexpected answer from becoming a wrong value.
- A service can change its API between nightly runs. The next run catches the change, but a pack collected before it does not.
- A definition is a decision, such as whether a read-only admin is privileged. These checks show that a collector follows its definitions. Whether a definition suits a control is for the reviewer to judge, and the Normalized Fields reference states each one.
- Derive covers the normalized fields, not the fields of a collector's own file in the service's terms.
Use it in your collector
The roster format, Derive, the simulator kit and the field-fault check are in the epack SDK under componentsdk/collectortest. Build Components shows how to set them up.