Test a configuration
Suppose your configuration should send requests for ops to an SSH target.
After authentication returns account alice, a rule should map her name to
mapped-alice. A request for guest should match no flow.
This guide turns those expectations into tests. You need a Bifröst binary and a directory where you can create files. You do not need an SSH server, a running Bifröst service or an actual Alice account.
What you are testing
You provide the rules and an invented situation; Bifröst calculates the result:
| Part | In this example |
|---|---|
| Configuration | Only ops matches flow primary; prefix the authenticated name with mapped-. |
| Account facts | Account alice exists for the test. |
| Input | Request ops; assume flow primary authenticated Alice. |
| Calculated result | Select primary and target user mapped-alice. |
| Assertions | Check that the returned decision, flow and names match. |
Authentication is assumed, not performed. A selected result means the
supported selection rules succeeded, not that a login or session succeeded.
The scope reference
describes exactly which rules are evaluated.
1. Choose the configuration
Test the same YAML file you intend to use when running Bifröst. You select it
when invoking bifroest test, rather than copying it into the tests directory
or fixing its path in a suite.
For this walkthrough, save the following example as configuration.yaml in
your project directory. When adapting the guide to an existing configuration,
use that file and adjust the test cases to its flows and rules instead.
| configuration.yaml | |
|---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 | |
The principal template adds mapped- to the authenticated name. The user
template then uses that mapped principal as the SSH target user. These are
Bifröst's normal YAML templates, not Lua expressions.
Offline example, not a deployment configuration
No connection to work.example.org is made. acceptAllHostKeys avoids
requiring trust material in this fixture; do not copy that setting into
a production gateway without proper target trust.
2. Describe the situation
Create a tests directory beside configuration.yaml and save
tests/access_bftest.lua. Bifröst recognizes the _bftest.lua suffix.
This file declares a suite called access with one test; it does not select a
configuration file.
A few Lua conventions explain the example:
suite { ... }callssuitewith a table. It is equivalent tosuite({ ... }).object { ... }supplies named data;list { ... }supplies ordered items.verify = function(t, actual) ... endis called with the test contexttand Bifröst's calculated resultactual.t:IsEqualrecords a comparison.
The account below uses Linux/macOS facts. On Windows, apply the changes in Windows account facts before running it.
| tests/access_bftest.lua | |
|---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | |
Here, authentication.primary refers to the YAML flow named primary.
It does not refer to the suite name or the requested username. allow tells
the test to assume that flow authenticated alice; it does not supply the
expected final decision.
suite.environment describes the users available to the test.
actual.environment describes the resulting SSH target. Despite the shared
property name, those objects have different roles.
UID 1001 is invented test data, not an account to look up on your computer.
Windows account facts
Change platform to { os = { "windows" } } and replace the account object with:
1 | |
The SID is also invented. No account needs to be created on Windows. This example selects an SSH target; the additional shell settings for a local Windows target are explained in Environment facts.
3. Run the test
From the directory containing configuration.yaml and tests, run:
1 | |
--configuration selects the YAML file to test. Its path is relative to your
shell's working directory, not the suite directory. The suite contains only
the test situations and assertions, so it can test the same file you later use
for Bifröst without maintaining a separate configuration copy.
The command exits with status 0 and ends with:
1 | |
Use bifroest test tests --configuration configuration.yaml --verbose to see
the suite and case name as well.
An assertion mismatch returns 1; invalid input, an empty selection or a test
execution/report error returns 2. See the command reference
for flags and the full exit-code rules.
The CLI path is a fallback: an explicit suite.configuration takes precedence.
Leave that property out when testing the configuration selected by the command.
Dedicated, self-contained fixtures can still use it; see
configuration selection.
4. Add an expected denial
Place this local variable before suite { ... } in the same file:
| Denied test | |
|---|---|
1 2 3 4 5 6 7 8 9 10 | |
Add deniedRequest, at the start of the suite's tests array, immediately
before the existing { name = "ops-selects-target", ... } test table.
The guest request does not match ^ops$, so no flow attempts authentication.
It needs no assumed authentication outcome. A denial is the expected result:
the test passes because Bifröst denied the request.
Run again; the summary now shows two passes. To select only the first scenario:
1 | |
5. See a failure and save CI results
Change the expected principal in the first test from mapped-alice to
wrong-user. Its assertion now fails with a source line, expected/actual
values and exit status 1. Restore the correct expectation afterward.
Save both machine-readable reports with:
1 | |
Let the exit status fail your CI step. Upload reports even after a failed step and use your CI's JUnit viewer for case names and failure details. Parent directories are created and existing regular reports can be replaced; see report files for protections and write-failure behavior. Use synthetic values: assertion details may appear in reports.
Run in a container
The same command is available in the normal Bifröst image. See the restricted container example for read-only inputs, non-root execution and report mounts.
Troubleshooting
| Problem | What to check |
|---|---|
| No tests selected | Filename suffix, filters and the binary's platform. |
| A required account or field is unknown | Supply it in the test facts; omission does not mean absence. |
| The configuration cannot be loaded | Check --configuration relative to your invocation directory; see configuration selection. |
| A template is unsupported | Check the supported template subset. |
| Assertions pass, but exit status is 2 | Check report paths and the filesystem cause on stderr. |
Next steps
- Look up Lua functions, Suites, Tests or result fields.
- Model HTTP requests or OIDC data.
- Browse the complete runnable examples.