This repository hosts the software tool used to test each configuration hosted in the hub or in its repository. More precisely, each configuration item consists of a yaml configuration file used to describe crowdsec behaviour. The format of the configuration item depends the type of configuration item. There're two types of configuration item:
- parsers (for parsers and postoverflows)
- scenarios
Each changes in the hub repository, in the hub-tests repository or in the crowdsec repository fires a continuous integration test.
The results of those tests on master branch are carelessly pushed on our github pages
To create such a test you'll need the the configuration item and follow the steps:
- Clone the hub repository.
- Put the configuration in the right place
<type>/<stage>/<provider name>/<configuration item>.yaml
- Run
./tests.sh -i
to init the tool and./tests.sh -g <type>/<stage>/<provider name>/<configuration item>.yaml
to create a skeleton test. - The precedent step created a
config.yaml
file in a directory<item type>/<stage name>/<provider name>/.tests/<configuration name>
. You have to store logs in this directory to trigger the tested configuration item. The easiest way to do so is to craft aparser_input.yaml
marshaled file representing a list of events (types.Events). (if you are creating a test for a postoverflow, the file would be po_input.yaml, and if you are creating a scenario the file is bucket_input.yaml)) Have a look at existing tests to get inspiration. - Check the
config.yaml
file (defaults should be ok) - Run
./tests.sh --single <item type>/<stage name>/<provider name>/.tests/<configuration name>
. When run the first time, this will create a result file that will be used as a reference for future runs. If you're happy with it, you can now create a pull request to merge the configuration item alonside with all the files needed to test it.
Each config.yaml
in the hub repository subdirectories triggers a
test. It's meant to be stored in under a directory: <item type>/<stage name if applicable>/<provider name>/.tests/<configuration name>/config.yaml
Example:
The first written test was for crowdsecurity/sshd-logs
: the configuration being tested is ./parsers/s01-parse/crowdsecurity/sshd-logs.yaml
, thus the test should takes place in the directory ./parsers/s01-parse/crowdsecurity/.tests/sshd-logs
, with the tests configuration file being ./parsers/s01-parse/crowdsecurity/.tests/sshd-logs/config.yaml`
parser_input: parser_input.yaml
parser_results: parser_results.yaml
bucket_input: bucket_input.yaml
bucket_results: bucket_result.json
postoverflow_input: postoverflow_input.yaml
postoverflow_results: postoverflow_results.yaml
reprocess: true
#configuration
index: "./config/hub/.index.json"
configurations:
parsers:
- crowdsecurity/sshd-logs
- crowdsecurity/syslog-logs
The paths of these of files are defined from the same directory as the config.yaml
parser_input.yaml
: file holding serialized events fed to the parser engine. If this configuration field is empty or missing, hub-tests will look for anacquis.yaml
in the test directory, and will follow its directive.parser_results.yaml
: file holding parser result. The test results will be compared to this file, and fail if it differs. If the file doesn't exist, it is automatically generated (this is useful to create a new test).bucket_input.yaml
: file holding serialized bucket input. It's automatically generated from parsing. This is a serialized list of events.bucket_results.jdon
: same as parser_result.json, this file holds the bucket output.postoverflow_input.yaml
: same as bucket input, this file holds the serialized output of the scenarios. This is a serialized list of events.postoverflow_results.json
: same as parser result, this file holds the postoverflow result.reprocess
: make it true if you expect some reprocess to happen. Useful only for buckets test. If scenarios are enabled, it enforces postoverflows to pass even if no postoverflow is configured, to be able to repour it in the buckets.
index
: where to find the.index.json
from the root directory of the hub repositoryconfigurations
: This is dict of lists of configurations we want to load. Valid keys for the dict areparsers
,scenarios
andpostoverflows
.
For now a config directory is still needed with:
simulation.yaml
this file can be empty- patterns directory with all parsers/groks patterns
config/hub/.index.json
I suspect a small bug in pkg/cwversion that makes this requirement happen.
In the root of hub repository there's a tests.sh
provided as a tool to help write some tests.
./tests.sh 16:56
Usage:
./tests.sh -h|--help Display this help message.
./tests.sh -i Init tests : prepare env tests
./tests.sh -g <CONFIG_PATH/name.yaml> Generate new test by specifying target config (parser|scenario|postoverflow)
./tests.sh --all Run all tests
./tests.sh --single <MYPATH/config.yaml> Run single test
To write a new test on a pristine repository:
./tests.sh -i
./tests.sh -g <path to the item configuration yaml>
It'll create the needed .tests directory.