Prowler Academy

Module D06: Unit Testing Checks and Services

Track: D2 · Checks · Effort: 2.5 h · Prowler: 5.48

Scenario

Your s3_bucket_owner_tag_present branch (feat/s3-owner-tag) has a three-test MagicMock file from Module D03, metadata from Module D04 and a configurable tag key from Module D05. A Prowler maintainer reviewing a draft asks for more before approval: tests that run the real S3 service through moto, edge cases such as an empty Owner value and a custom tag key, and a test that records what happens when Cloudsmiths' scanning role cannot read bucket tags. The Azure team also wants coverage for a storage check they rely on. In this module you learn how Prowler tests are laid out, how each provider is mocked, and what CI runs when you push.

Learning objectives

  1. Place check and service tests in the folder that mirrors the source tree and follow the file, class and function naming rules.
  2. Write AWS check tests with @mock_aws, set_mocked_aws_provider and the two mock.patch calls every check test needs.
  3. Choose between pure moto, moto plus a patched _make_api_call, and MagicMock, based on moto's API coverage.
  4. Test Azure, GCP and other non-AWS checks by patching the <service>_client with a MagicMock that holds real resource models.
  5. Cover the required scenarios (no resources, PASS, FAIL, and MANUAL where it applies) and run a single file, folder or provider locally.
  6. Explain how CI picks which tests to run: the AWS service dependency table and test impact analysis.

Regístrate para leer el módulo completo

El temario y el resumen de cada módulo son públicos. Crea una cuenta gratuita para desbloquear las lecciones completas, los laboratorios, las comprobaciones de conocimientos y el examen final, y para seguir tu progreso.