Guest User

Untitled

a guest
Sep 30th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. #requires -Modules @{ ModuleName="AzSK"; ModuleVersion="3.6.1" }
  2. #requires -Modules @{ ModuleName="Pester"; ModuleVersion="4.3.0" }
  3. <#
  4. .SYNOPSIS
  5. Pester test for validating ARM template meets best-practices
  6.  
  7. .DESCRIPTION
  8. This Pester test will validate one or more ARM templates in the specified
  9. file path to validate that they meet the best practices.
  10.  
  11. .PARAMETER TemplatePath
  12. The full path to the ARM template to check. This may be a path with
  13. wild cards to check multiple files.
  14.  
  15. .PARAMETER Severity
  16. An array of severity values that will count as failed tests. Any violation
  17. found in the ARM template that matches a severity in this list will cause
  18. the Pester test to count as failed. Defaults to 'High' and 'Medium'.
  19.  
  20. .PARAMETER SkipControlsFromFile
  21. The path to a controls file that can be use to suppress rules.
  22. #>
  23. [CmdletBinding()]
  24. param (
  25. [Parameter(Mandatory = $true)]
  26. [System.String]
  27. $TemplatePath,
  28.  
  29. [Parameter()]
  30. [System.String[]]
  31. $Severity = @('High','Medium'),
  32.  
  33. [Parameter()]
  34. [System.String]
  35. $SkipControlsFromFile
  36. )
  37.  
  38. Describe 'ARM template best practices' -Tag 'AzSK' {
  39. Context 'When AzSK module is installed and run on all files in the Templates folder' {
  40. $resultPath = Get-AzSKARMTemplateSecurityStatus `
  41. -ARMTemplatePath $TemplatePath `
  42. -Preview:$true `
  43. -DoNotOpenOutputFolder `
  44. -SkipControlsFromFile $SkipControlsFromFile `
  45. -Recurse
  46. $resultFile = (Get-ChildItem -Path $resultPath -Filter 'ARMCheckerResults_*.csv')[0].FullName
  47.  
  48. It 'Should produce a valid CSV results file ' {
  49. $resultFile | Should -Not -BeNullOrEmpty
  50. Test-Path -Path $resultFile | Should -Be $true
  51. $script:resultsContent = Get-Content -Path $resultFile | ConvertFrom-Csv
  52. }
  53.  
  54. $groupedResults = $script:resultsContent | Where-Object -Property Status -EQ 'Failed' | Group-Object -Property Severity
  55.  
  56. $testCases = $Severity.Foreach({@{Severity = $_}})
  57.  
  58. It 'Should have 0 failed Severity:<Severity> results' -TestCases $testCases {
  59. param ( [System.String] $Severity )
  60. $failedCount = $groupedResults.Where({ $_.Name -eq $Severity })[0].Count
  61. $failedCount | Should -Be 0
  62. }
  63. }
  64. }
Add Comment
Please, Sign In to add comment