Since the Testing Framework was written in Python, the use of this structure consists of creating scripts which have a concise pattern based on execution and printing result. Therefore every plugin should implement two mandatory methods that are called by the main function of our system. Moreover, given the need to parametrize the test, it is also possible to catch a file in JSON or YAML format which will be instantiated as a dict or a list in Python code.
The test execution is made by:
foo@bar:~/hapi/test$ python3 main.py -<plugin_name> <config_file>
The following image shows how the execution flow of a test works with its plugin.
Some steps of the flow requires attention:
- In this point, it is checked if the plugin will receive a parametrization
or not. When the plugin does not demand a configuration, so the
"None". Else the
Testsuperclass will read the JSON/YAML file making the data available.
run()method is responsible to call the system and execute the tools previously developed by the HAPI team. All response messages are taken when the calls are running.
- Once the messages are stored, now the plugin should manipulate the messages and print them.
This is a plugin previously added in our structure. The main functionality is to check whether an YAML file containing policy rules is according to the Cyral schema. To do that the plugin uses [PAJV] validator which, given a mount schema, checks if an JSON/YAML follow the schema specification. This script test requires a configuration file as shown below:
schema: ../datamap/schemas/policy.json policies: - policy-1.yaml - policy-2.yaml
It is good o remember that all file paths in the configuration file are
relative to the
Using the workflow to explain this script, we have
run calling the PAJV for
each policy file with the same schema.
In each iteration the response is stored in a class attribute and at the end
result method formats and prints the response message in the standard
[Here] is shown how to execute this test.
: https://github.com/json-schema-everywhere/pajv/ : http://cuda.dcc.ufmg.br/hapidoc/testing/examples.html#yaml-lint