cisagov / ScubaGear

Automation to assess the state of your M365 tenant against CISA's baselines
https://www.cisa.gov/resources-tools/services/secure-cloud-business-applications-scuba-project
Creative Commons Zero v1.0 Universal
1.65k stars 221 forks source link

Defender Pester Tests results in license warnings #576

Open schrolla opened 1 year ago

schrolla commented 1 year ago

🐛 Summary

The ScubaGear testing framework includes Pester PowerShell unit tests for the Defender provider. When these tests are run, they pass, but produce license warnings with the cmdlet Get-Command returns false since it is not connected to any tenant and the reference command is only available after connecting to a licensed tenant. To resolve and ensure maximum tests coverage, Get-Command should be mocked in the Pester tests.

Note that the issue does not cause the test to fail, but it indicates that the test is not properly mocking one of the commands which may limit the tests value.

To reproduce

Steps to reproduce the behavior:

  1. Go to Testing\Unit\PowerShell\Providers\DefenderProvider folder.
  2. Run Invoke-Pester Export-DefenderProvider.Tests.ps1.
  3. Note the WARNINGs generated by the test that say: WARNING: Defender for Office 365 license not available in tenant. Omitting the following commands: Get-AtpPolicyForO365, Get-ATPProtectionPolicyRule.

Expected behavior

The expectation is that the tests run without generating the WARNING, thereby exercising the longest and broadest test path.

Current Test Output

Screenshot 2023-10-06 at 12 34 34 PM

tkol2022 commented 10 months ago

Reviewed 12/14

This bug is still valid.