Skip to content

Commit

Permalink
Merge pull request #517 from weyCC81/wey-Tags&Prerelease
Browse files Browse the repository at this point in the history
Improve Tag handling and Prerelease & Telemetry in actions
  • Loading branch information
merill authored Dec 8, 2024
2 parents 9b9fd94 + d2296a7 commit 30f6ddf
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 7 deletions.
25 changes: 22 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ inputs:
required: false
default: "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
include_tags:
description: "A list of tags to include in the test run. Please separate multiple tags with a comma."
description: "A list of tags to include in the test run. Please separate multiple tags with a comma (without space)."
required: false
default: ""
exclude_tags:
description: "A list of tags to exclude from the test run. Please separate multiple tags with a comma."
description: "A list of tags to exclude from the test run. Please separate multiple tags with a comma (without space)."
required: false
default: ""
pester_verbosity:
Expand All @@ -48,6 +48,16 @@ inputs:
description: "Define whether the results are uploaded as Artifacts."
required: false
default: true
install_prerelease:
type: boolean
description: "Installs the preview version, allowing access to new cmdlets."
required: false
default: false
disable_telemetry:
type: boolean
description: "If set, telemetry information will not be logged."
required: false
default: false

runs:
using: "composite"
Expand Down Expand Up @@ -87,7 +97,11 @@ runs:
Connect-MgGraph -AccessToken $accessToken -NoWelcome
# Install Maester
Install-Module Maester -Force
if ( [string]::IsNullOrWhiteSpace( '${{ inputs.install_prerelease}}' ) -eq $true ){
Install-Module Maester -AllowPrerelease -Force
} else {
Install-Module Maester -Force
}
# Configure test results
$PesterConfiguration = New-PesterConfiguration
Expand Down Expand Up @@ -130,6 +144,11 @@ runs:
}
}
# Check if disable telemetry is provided
if (( [string]::IsNullOrWhiteSpace( '${{ inputs.disable_telemetry}}' ) -eq $true ){
$MaesterParameters.Add( 'DisableTelemetry', $true )
}
# Run Maester tests
$results = Invoke-Maester @MaesterParameters
Expand Down
2 changes: 1 addition & 1 deletion powershell/internal/ConvertTo-MtMaesterResults.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function ConvertTo-MtMaesterResult {
$mtTestInfo = [PSCustomObject]@{
Name = $name
HelpUrl = $helpUrl
Tag = $test.Block.Tag
Tag = ($test.Block.Tag + $test.Tag | Select-Object -Unique)
Result = $test.Result
ScriptBlock = $test.ScriptBlock.ToString()
ScriptBlockFile = $test.ScriptBlock.File
Expand Down
11 changes: 10 additions & 1 deletion tests/Maester/Entra/Test-ConditionalAccessBaseline.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
It "MT.1038: Conditional Access policies should not include or exclude deleted groups. See https://maester.dev/docs/tests/MT.1038" -Tag "MT.1038", "Warning" {
Test-MtCaReferencedGroupsExist | Should -Be $true -Because "there are one or more policies relying on deleted groups."
}
Context "License utilization" {
Context "License utilization" -Tag "LicenseUtilization" {
It "MT.1022: All users utilizing a P1 license should be licensed. See https://maester.dev/docs/tests/MT.1022" -Tag "MT.1022" {
$LicenseReport = Test-MtCaLicenseUtilization -License "P1"
$LicenseReport.TotalLicensesUtilized | Should -BeLessOrEqual $LicenseReport.EntitledLicenseCount -Because "this is the maximium number of user that can utilize a P1 license"
Expand All @@ -84,6 +84,15 @@ Describe "Security Defaults" -Tag "CA", "Security", "All" {
Add-MtTestResultDetail -SkippedBecause LicensedEntraIDPremium
} else {
$SecurityDefaults = Invoke-MtGraphRequest -RelativeUri "policies/identitySecurityDefaultsEnforcementPolicy" -ApiVersion beta | Select-Object -ExpandProperty isEnabled

if ($SecurityDefaults -eq $true) {
$testResultMarkdown = "Well done. SecurityDefaults are On `n`n"
} else {
$testResultMarkdown = "SecurityDefaults are Off '$($SecurityDefaults)' `n`n"
}
$testDetailsMarkdown = "You should enable SecurityDefaults or configure Conditional Access."
Add-MtTestResultDetail -Description $testDetailsMarkdown -Result $testResultMarkdown

$SecurityDefaults | Should -Be $true -Because "Security Defaults are not enabled"
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Maester/Entra/Test-EntraRecommendations.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ BeforeDiscovery {
}

Describe "Entra Recommendations" -Tag "Maester", "Entra", "Security", "All", "Recommendation" -ForEach $EntraRecommendations {
It "MT.1024: Entra Recommendation - <displayName>. See https://maester.dev/docs/tests/MT.1024" -Tag "MT.1024" {
It "MT.1024: Entra Recommendation - <displayName>. See https://maester.dev/docs/tests/MT.1024" -Tag "MT.1024", $recommendationType {
$EntraIDPlan = Get-MtLicenseInformation -Product "EntraID"
$EntraPremiumRecommendations = @(
"insiderRiskPolicy",
Expand Down Expand Up @@ -36,7 +36,7 @@ Describe "Entra Recommendations" -Tag "Maester", "Entra", "Security", "All", "Re
$impactedResourcesList += "| $($resourceResult) | [$($resource.displayName)]($($resource.portalUrl)) | $($resource.addedDateTime) | `n"
}
}
$ResultMarkdown = $insights + $impactedResourcesList + "`n`n#### Remediation actions:`n`n" + $ActionSteps
$ResultMarkdown = $insights + $impactedResourcesList + "`n`n#### Remediation actions:`n`n" + $ActionSteps + "`n`n ExcludeTag: $($recommendationType)"
Add-MtTestResultDetail -Description $benefits -Result $ResultMarkdown
#endregion
# Actual test
Expand Down
15 changes: 15 additions & 0 deletions website/docs/commands/Invoke-Maester.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,21 @@ Invoke-Maester -PesterConfiguration $configuration
```

### EXAMPLE 12

```powershell
$exclude_tags1 = @('CA', 'App') # System.Array
$exclude_tags2 = @('MT.1028', 'MT.1024') # System.Array
$exclude_tags_combined = $exclude_tags1 + $exclude_tags2
#Invoke-Maester -ExcludeTag $exclude_tags_combined -Verbose
Invoke-Maester -ExcludeTag $exclude_tags_combined
```

This combines two arrays of exclusion tags and runs the tests, excluding any tests with those tags.


## PARAMETERS

### -Path
Expand Down

0 comments on commit 30f6ddf

Please sign in to comment.