Running Tests for Security Dashboard

Running Tests for Security Dashboard

Running Tests Through GitHub Actions

  1. Open GitHub Repo https://github.com/openmrs/openmrs-contrib-cvss-scanning

  2. Click Actions on the top panel

  3. In the Actions tab, on the left panel under Actions click Security Tests

  4. Under the Security Tests header, on the right side, click Run Workflow

  5. Below Use workflow from select Branch: main and select the branch to run the tests on

    1. To test the main branch, leave as Branch: main

  6. Select Run Workflow

  7. Wait for tests to complete

  8. If running the action on main, the results should be visible at https://security-dashboard.openmrs.org. In-depth Pytest results can be found at the following: https://security-dashboard.openmrs.org/detailed-report.html

  9. If running the action on a branch other than main, follow these steps to view the results

    1. Under Artifacts download security-dashboard and security-test-report-html

    2. Unzip each to find the security dashboard page and in-depth Pytest report page respectively.

Local Development

Prerequisites

  1. Download and install Docker Desktop

    1. https://docs.docker.com/desktop/setup/install/windows-install/

    2. First install will reboot your computer

  2. Download and install Python

  3. Execute the following commands in terminal or PowerShell

    1. py -m pip install pytest-html pytest-json-report pytest-playwright python-dotenv pytest pytest_bdd playwright mysql-connector-python requests

    2. playwright install

Run Tests Locally

  1. Open Docker Desktop

  2. In the terminal: docker compose up -d

  3. To run a test (or test category), execute this command

    1. py -m pytest tests/ -v -s --headed

    2. Add the flag --tb=no to hide the details of the errors

    3. -v will show each test

    4. -s shows the print statements

    5. --headed runs the tests showing the browser

    6. Add -k “<text>” to run certain tests that have the matching text in their names.

  4. To run all tests with reports, use the following command

    1. py -m pytest tests/ --html=report.html --self-contained-html --json-report --json-report-file=report.json -v -s 2>&1 | tee test_output.log

To turn off docker: docker compose down or stop them in the Docker Desktop app.

Generate the Dashboard Locally

  1. py -m pytest tests/ --html=report.html --self-contained-html --json-report --json-report-file=report.json -v -s 2>&1 | tee test_output.log

  2. py scripts/generate_security_dashboard.py

  3. Open the generated report.html to see the dashboard.

    1. It is recommended to opening this in Live Server Extension in VS Code to update the page whenever the generate script is run.