-
Notifications
You must be signed in to change notification settings - Fork 249
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enhance csv version of output (#1281)
* Remove old csv functionality. * Add new csv functionality * Add Format-PlainText function * Remove missing symbols from url regex * Added unit test for Format-PlainText * Add test cases for ConvertTo-ResultsCsv * Remove old TestResults.csv from test cases * Update reports.md with details about the merge json flag * Remove csv from OutRegoFileName description * Adusted ConvertTo-ResultsCsv to function both with and without MergeJson parameter * Clarify description of the CSV output * Update parameters to include OutCsvFileName description * Update OutCsvFileName description in Orchestrator * Correct copy/paste error in test case * Add new columns for documenting failures * Update reports.md with description of new csv columns
- Loading branch information
Showing
8 changed files
with
343 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
PowerShell/ScubaGear/Testing/Unit/PowerShell/Orchestrator/ConvertTo-ResultsCsv.Tests.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
$OrchestratorPath = '../../../../Modules/Orchestrator.psm1' | ||
Import-Module (Join-Path -Path $PSScriptRoot -ChildPath $OrchestratorPath) -Function ConvertTo-ResultsCsv -Force | ||
|
||
InModuleScope Orchestrator { | ||
Describe -Tag 'Orchestrator' -Name 'ConvertTo-ResultsCsv' { | ||
BeforeAll { | ||
Mock -CommandName Join-Path { "." } | ||
Mock -CommandName Test-Path { $true } | ||
Mock -CommandName Out-File {} | ||
Mock -CommandName Set-Content {} | ||
Mock -CommandName Remove-Item {} | ||
Mock -CommandName Get-Content { "" } | ||
Mock -CommandName Format-PlainText { "" } | ||
Mock -CommandName Add-Member {} | ||
Mock -CommandName Get-FileEncoding | ||
Mock -CommandName ConvertTo-Csv { "" } | ||
Mock -CommandName Write-Warning {} | ||
} | ||
|
||
It 'Handles multiple products, control groups, and controls' { | ||
# Test to validate that the 3-way nested for loop properly finds all controls | ||
Mock -CommandName ConvertFrom-Json { @{ | ||
"Results"=[PSCustomObject]@{ | ||
"EXO"=@( | ||
@{ | ||
"Controls"=@( | ||
@{ | ||
"Requirement"="123"; | ||
"Details"="123"; | ||
}, | ||
@{ | ||
"Requirement"="123"; | ||
"Details"="123"; | ||
} | ||
) | ||
}, | ||
@{ | ||
"Controls"=@( | ||
@{ | ||
"Requirement"="123"; | ||
"Details"="123"; | ||
} | ||
) | ||
} | ||
); | ||
"AAD"=@( | ||
@{ | ||
"Controls"=@( | ||
@{ | ||
"Requirement"="123"; | ||
"Details"="123"; | ||
} | ||
) | ||
} | ||
); | ||
}} | ||
} | ||
$CsvParameters = @{ | ||
ProductNames = @("exo", "aad"); | ||
OutFolderPath = "."; | ||
OutJsonFileName = "ScubaResults"; | ||
OutCsvFileName = "ScubaResults" | ||
} | ||
{ ConvertTo-ResultsCsv @CsvParameters} | Should -Not -Throw | ||
Should -Invoke -CommandName ConvertFrom-Json -Exactly -Times 1 | ||
Should -Invoke -CommandName Write-Warning -Exactly -Times 0 | ||
# Each control contributes two calls, EXO has 3 controls, AAD has 1 = 3*2 + 1*2 = 8 | ||
Should -Invoke -CommandName Format-PlainText -Exactly -Times 8 | ||
} | ||
|
||
It 'Handles file not found errors' { | ||
# Test to validate that a warning is printed if there is an error opening the ScubaResults file | ||
Mock -CommandName ConvertFrom-Json {} | ||
Mock -CommandName Get-Content { throw "File not found" } | ||
$CsvParameters = @{ | ||
ProductNames = @("exo", "aad"); | ||
OutFolderPath = "."; | ||
OutJsonFileName = "ScubaResults"; | ||
OutCsvFileName = "ScubaResults" | ||
} | ||
{ ConvertTo-ResultsCsv @CsvParameters} | Should -Not -Throw | ||
Should -Invoke -CommandName Format-PlainText -Exactly -Times 0 | ||
Should -Invoke -CommandName Write-Warning -Exactly -Times 1 | ||
} | ||
} | ||
} | ||
|
||
AfterAll { | ||
Remove-Module Orchestrator -ErrorAction SilentlyContinue | ||
} |
Oops, something went wrong.