Package: tricot
tricottricotis atrivial command testerthat allows to test scripts, executables and commands for
expected behavior. Tests are configured within ofYAMLfiles and simply contain the command definitions
to execute along with a set of desired validators. This approach makestricota simple solution
for end to end testing of command line applications.https://user-images.githubusercontent.com/49147108/183279190-d4148edb-ce40-443c-93c9-03c9b632e780.mp4Installationtricotcan be build and installed as apip package. The following command installstricotfor your current user profile:$pip3installtricotYou can also buildtricotfrom source by running the following commands:$gitclonehttps://github.com/qtc-de/tricot$cdtricot$python3setup.pysdist$pip3installdist/*tricotalso supports autocompletion forbash. To take advantage of autocompletion, you need to have thecompletion-helpersproject installed. If setup correctly, just
copying thecompletion scriptto your~/.bash_completion.dfolder enables
autocompletion.$cpresources/bash_completion.d/tricot~/bash_completion.d/Usagetricottests are defined within ofYAMLfiles that can contain the following components:Testers: Eachtricot YAMLfile is required to define exactly oneTester. TheTesterbasically describes the context of the currentYAMLfile and sets attributes like it'stitleorerror_mode. Furthermore,tricot YAMLfiles can contain references to otherTesters,
which allows nestingTesters.Tests:tricot YAMLfiles can contain an arbitrary number ofTests. EachTestcontains
the command you want to test and a set of validators that should be used to validate the commands
output.Validators: As mentioned above,Validatorsare used withinTeststo validate the result
of a test command.Validatorsusually apply to the command output, but they can validate side
effects as well. E.g. you can also useValidatorsto check whether a command created a specific
file on the file system.Plugins: Plugins are mainly used to setup requirements for tests or to perform cleanup actions.
They run before the actualTestsstart and perform cleanup actions after theTestsfinished.
Plugins can e.g. be used to create files and directories required for the test, to run an operating
system command before the test or to spawn aHTTP listenerthat is available during the test.Containers: When testing commands that interact with other systems, you probably want to run
your tests against a docker container.Containerdefinitions within oftricot YAMLfiles can
be used to start containers before your tests run. A container defined in aYAMLfile runs as
long as theTestsfrom the correspondingYAMLfile are executed. After all tests have finished,
the container is stopped.Variables:tricot YAMLfiles can contain variable definitions. These can be used to prevent
repetitions within ofTestdefinitions.Variablesare inherited when nestingTesters, which
allows the definition of global variables within the toplevelTester, that can be used by all
subTesters.Extractors: Extractors allow you to extract parts of the command output of previous tests and
bind it to variables that can be used later on. This is useful if a test depends on the command
output of another test. If a test depends on the outcome of another test, you should useConditionalsinstead.Sounds too complicated? Let's look at some examples!ExamplesIn this section we list some examples on how to usetricot. The tests performed in these examples
do not really make sense and are only used for demonstration purposes. If you are interested in some
real word examples, you should check theProjects that use tricotsection.Example 1:Test definition:tester:title:Basic Usagedescription:|-Demonstrate the basic usage of tricotvariables:passwd:/etc/passwdtests:-title:Test passwd Filedescription:|-Test that our passwd file contains some expected user names.Make sure that david is not contained within our passwd file.command:-cat-${passwd}validators:-status:0-contains:ignore_case:Falsevalues:-root-bin-www-datainvert:-davidOutput:[qtc@kali example]$tricot-vexample1.yml[+] Starting test: Basic Usage[+][+]         1. Test passwd File... success.Example 2:Test definition:tester:title:Docker Integrationdescription:|-An example for tricots docker integrationcontainers:-name:'nginx'image:'nginx:latest'aliases:DOCKER-nginx-IP:DOCKER-IPtests:-title:Test curldescription:|-Test that our curl installation is workingcommand:-curl-${DOCKER-IP}validators:-status:0-contains:ignore_case:Falsevalues:-Welcome to nginx-Thank you for using nginx-title:Test wgetdescription:|-Test that our wget installation is workingcommand:-wget-${DOCKER-IP}validators:-status:0-file_contains:-file:./index.htmlcontains:-Welcome to nginx-Thank you for using nginx-file_exists:cleanup:Truefiles:-'./index.html'Output:[qtc@kali example]$tricot-vexample2.yml[+] Starting test: Docker Integration[+][+]     Starting container: nginx[+]         Image: nginx:latest[+]         Network Mode: default[+][+]     1. Test curl... success[+]     2. Test wget... success[+][+]     Stopping container: nginxExample 3:Test definition:example3.yml:tester:title:Nested Testersdescription:|-An example for nested testers and pluginserror_mode:breakplugins:-mkdir:cleanup:Trueforce:Truedirs:-./www-copy:from:-/etc/passwdto:-./www-http_listener:port:8000dir:./wwwtesters:-./example3/curl.yml-./example3/wget.ymlcurl.ymltester:title:curl Testerdescription:|-Test some curl commandstests:-title:Test passwd Filedescription:|-Test whether the passwd file can be obtained from thehttp_listener plugin.command:-curl-http://127.0.0.1:8000/passwdvalidators:-status:0-contains:values:-root-bin-www-datawget.yml:tester:title:wget Testerdescription:|-Test some wget commandsplugins:-cleanup:items:-./passwdtests:-title:Test passwd Filedescription:|-Test whether the passwd file can be obtained from thehttp_listener plugin.command:-wget-http://127.0.0.1:8000/passwdvalidators:-status:0-file_exists:files:-'./passwd'-file_contains:-file:./passwdcontains:-root-bin-nopeOutput:[qtc@kali example]$tricot-vexample3.yml[+] Starting test: Nested Testers[+][+]     Starting test: curl Tester[+][+]         1. Test passwd File... success[+][+]     Starting test: wget Tester[+][+]         1. Test passwd File... failed[-]             - Caught ValidationException raised by the file_contains validator.[-]               Configuration file: /opt/tricot/examples/example3/wget.yml[-][-]               Validator run failed because of the following reason:[-]               String 'nope' was not found in '/opt/tricot/examples/example3/passwd'.[-][-]               Command: ['wget', 'http://127.0.0.1:8000/passwd'][-]               Command exit code: 0[-]               Command stdout:[-]               Command stderr:[-]                 --2021-09-08 07:35:33--  http://127.0.0.1:8000/passwd[-]                 Connecting to 127.0.0.1:8000... connected.[-]                 HTTP request sent, awaiting response... 200 OK[-]                 Length: 3635 (3.5K) [application/octet-stream][-]                 Saving to: ‘passwd’[-][-]                      0K ...                                                   100%  636M=0s[-][-]                 2021-09-08 07:35:33 (636 MB/s) - ‘passwd’ saved [3635/3635][-][-][-]               Validator parameters:[-]                 [[-]                     {[-]                         "file": "./passwd",[-]                         "contains": [[-]                             "root",[-]                             "bin",[-]                             "nope"[-]                         ][-]                     }[-]                 ][-][-]     Caught ValidationException while error mode is set to break.[-]     Stopping test.Example 4:Test definition:tester:title:ExtractorsDescription:|-An example for tricots extractor featuretests:-title:Check Userdescription:|-Checks that user 1000:1000 exists and extracts the homedirectory and the assigned shell to a variable.command:-cat-/etc/passwdextractors:-regex:pattern:'1000:1000:[^:]+:([^:]+):(.+)$'variable:'home-shell'on_miss:'break'multiline:truevalidators:-contains:values:-1000:1000-title:Check Home and Shelldescription:|-Check that the home directory and assigned shell of user1000:1000 exist.command:-ls-${home-shell-0-1}-${home-shell-0-2}validators:-status:0Output:[qtc@kali example]$tricot-vexample4.yml[+] Starting test: Extractors[+][+]     1. Check User... success[+]     2. Check Home and Shell... successProjects that use tricotIn this section we list some projects that are usingtricotfor testing. Not because we are proud of,
but only to provide you some more examples on how to usetricotfor effective testing.beanshooterctfcredremote-method-guesserslipittricot