How does it work?

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.

Workflow

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. Exemplo_1

Some steps of the flow requires attention:

  1. 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 <config_file> should be "None". Else the Test superclass will read the JSON/YAML file making the data available.
  2. The 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.
  3. Once the messages are stored, now the plugin should manipulate the messages and print them.

YAML Lint

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][1] 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 <config_file>. 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 the result method formats and prints the response message in the standard output. [Here][2] is shown how to execute this test.

[1]: https://github.com/json-schema-everywhere/pajv/ [2]: http://cuda.dcc.ufmg.br/hapidoc/testing/examples.html#yaml-lint