add: Output type to functions
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
function Assert-ModuleAvailability {
|
function Assert-ModuleAvailability {
|
||||||
|
[OutputType([void]) ]
|
||||||
param(
|
param(
|
||||||
[string]$ModuleName,
|
[string]$ModuleName,
|
||||||
[string]$RequiredVersion,
|
[string]$RequiredVersion,
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
function Connect-M365Suite {
|
function Connect-M365Suite {
|
||||||
|
[OutputType([void])]
|
||||||
[CmdletBinding()]
|
[CmdletBinding()]
|
||||||
param (
|
param (
|
||||||
[Parameter(Mandatory=$false)]
|
[Parameter(Mandatory=$false)]
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
function Disconnect-M365Suite {
|
function Disconnect-M365Suite {
|
||||||
|
[OutputType([void])]
|
||||||
param (
|
param (
|
||||||
[Parameter(Mandatory)]
|
[Parameter(Mandatory)]
|
||||||
[string[]]$RequiredConnections
|
[string[]]$RequiredConnections
|
||||||
|
@@ -1,5 +1,9 @@
|
|||||||
function Format-MissingAction {
|
function Format-MissingAction {
|
||||||
param ([array]$missingActions)
|
[CmdletBinding()]
|
||||||
|
[OutputType([hashtable])]
|
||||||
|
param (
|
||||||
|
[array]$missingActions
|
||||||
|
)
|
||||||
|
|
||||||
$actionGroups = @{
|
$actionGroups = @{
|
||||||
"Admin" = @()
|
"Admin" = @()
|
||||||
@@ -22,4 +26,4 @@ function Format-MissingAction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return $formattedResults
|
return $formattedResults
|
||||||
}
|
}
|
||||||
|
19
source/Private/Format-RequiredModuleList.ps1
Normal file
19
source/Private/Format-RequiredModuleList.ps1
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
function Format-RequiredModuleList {
|
||||||
|
[CmdletBinding()]
|
||||||
|
[OutputType([string])]
|
||||||
|
param (
|
||||||
|
[Parameter(Mandatory = $true)]
|
||||||
|
[System.Object[]]$RequiredModules
|
||||||
|
)
|
||||||
|
|
||||||
|
$requiredModulesFormatted = ""
|
||||||
|
foreach ($module in $RequiredModules) {
|
||||||
|
if ($module.SubModules -and $module.SubModules.Count -gt 0) {
|
||||||
|
$subModulesFormatted = $module.SubModules -join ', '
|
||||||
|
$requiredModulesFormatted += "$($module.ModuleName) (SubModules: $subModulesFormatted), "
|
||||||
|
} else {
|
||||||
|
$requiredModulesFormatted += "$($module.ModuleName), "
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $requiredModulesFormatted.TrimEnd(", ")
|
||||||
|
}
|
@@ -1,4 +1,6 @@
|
|||||||
function Get-MostCommonWord {
|
function Get-MostCommonWord {
|
||||||
|
[CmdletBinding()]
|
||||||
|
[OutputType([string])]
|
||||||
param (
|
param (
|
||||||
[Parameter(Mandatory = $true)]
|
[Parameter(Mandatory = $true)]
|
||||||
[string[]]$InputStrings
|
[string[]]$InputStrings
|
||||||
@@ -19,4 +21,4 @@ function Get-MostCommonWord {
|
|||||||
} else {
|
} else {
|
||||||
return $null
|
return $null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,4 +1,6 @@
|
|||||||
function Get-TestDefinitionsObject {
|
function Get-TestDefinitionsObject {
|
||||||
|
[CmdletBinding()]
|
||||||
|
[OutputType([object[]])]
|
||||||
param (
|
param (
|
||||||
[Parameter(Mandatory = $true)]
|
[Parameter(Mandatory = $true)]
|
||||||
[object[]]$TestDefinitions,
|
[object[]]$TestDefinitions,
|
||||||
@@ -60,4 +62,4 @@ function Get-TestDefinitionsObject {
|
|||||||
|
|
||||||
Write-Verbose "Filtered test definitions count: $($TestDefinitions.Count)"
|
Write-Verbose "Filtered test definitions count: $($TestDefinitions.Count)"
|
||||||
return $TestDefinitions
|
return $TestDefinitions
|
||||||
}
|
}
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
function Initialize-CISAuditResult {
|
function Initialize-CISAuditResult {
|
||||||
[CmdletBinding()]
|
[CmdletBinding()]
|
||||||
|
[OutputType([CISAuditResult])]
|
||||||
param (
|
param (
|
||||||
[Parameter(Mandatory = $true)]
|
[Parameter(Mandatory = $true)]
|
||||||
[string]$Rec,
|
[string]$Rec,
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
function Invoke-TestFunction {
|
function Invoke-TestFunction {
|
||||||
|
[OutputType([CISAuditResult[]])]
|
||||||
param (
|
param (
|
||||||
[Parameter(Mandatory = $true)]
|
[Parameter(Mandatory = $true)]
|
||||||
[PSObject]$FunctionFile,
|
[PSObject]$FunctionFile,
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
function Measure-AuditResult {
|
function Measure-AuditResult {
|
||||||
|
[OutputType([void])]
|
||||||
param (
|
param (
|
||||||
[Parameter(Mandatory = $true)]
|
[Parameter(Mandatory = $true)]
|
||||||
[System.Collections.ArrayList]$AllAuditResults,
|
[System.Collections.ArrayList]$AllAuditResults,
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
function Merge-CISExcelAndCsvData {
|
function Merge-CISExcelAndCsvData {
|
||||||
[CmdletBinding(DefaultParameterSetName = 'CsvInput')]
|
[CmdletBinding(DefaultParameterSetName = 'CsvInput')]
|
||||||
|
[OutputType([PSCustomObject[]])]
|
||||||
param (
|
param (
|
||||||
[Parameter(Mandatory = $true)]
|
[Parameter(Mandatory = $true)]
|
||||||
[string]$ExcelPath,
|
[string]$ExcelPath,
|
||||||
|
@@ -1,4 +1,6 @@
|
|||||||
function New-MergedObject {
|
function New-MergedObject {
|
||||||
|
[CmdletBinding()]
|
||||||
|
[OutputType([PSCustomObject])]
|
||||||
param (
|
param (
|
||||||
[Parameter(Mandatory = $true)]
|
[Parameter(Mandatory = $true)]
|
||||||
[psobject]$ExcelItem,
|
[psobject]$ExcelItem,
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
function Update-CISExcelWorksheet {
|
function Update-CISExcelWorksheet {
|
||||||
|
[OutputType([void])]
|
||||||
[CmdletBinding()]
|
[CmdletBinding()]
|
||||||
param (
|
param (
|
||||||
[Parameter(Mandatory = $true)]
|
[Parameter(Mandatory = $true)]
|
||||||
|
@@ -1,28 +1,29 @@
|
|||||||
function Update-WorksheetCell {
|
function Update-WorksheetCell {
|
||||||
param (
|
[OutputType([void])]
|
||||||
$Worksheet,
|
param (
|
||||||
$Data,
|
$Worksheet,
|
||||||
$StartingRowIndex
|
$Data,
|
||||||
)
|
$StartingRowIndex
|
||||||
|
)
|
||||||
|
|
||||||
# Check and set headers
|
# Check and set headers
|
||||||
$firstItem = $Data[0]
|
$firstItem = $Data[0]
|
||||||
$colIndex = 1
|
$colIndex = 1
|
||||||
foreach ($property in $firstItem.PSObject.Properties) {
|
foreach ($property in $firstItem.PSObject.Properties) {
|
||||||
if ($StartingRowIndex -eq 2 -and $Worksheet.Cells[1, $colIndex].Value -eq $null) {
|
if ($StartingRowIndex -eq 2 -and $Worksheet.Cells[1, $colIndex].Value -eq $null) {
|
||||||
$Worksheet.Cells[1, $colIndex].Value = $property.Name
|
$Worksheet.Cells[1, $colIndex].Value = $property.Name
|
||||||
}
|
|
||||||
$colIndex++
|
|
||||||
}
|
|
||||||
|
|
||||||
# Iterate over each row in the data and update cells
|
|
||||||
$rowIndex = $StartingRowIndex
|
|
||||||
foreach ($item in $Data) {
|
|
||||||
$colIndex = 1
|
|
||||||
foreach ($property in $item.PSObject.Properties) {
|
|
||||||
$Worksheet.Cells[$rowIndex, $colIndex].Value = $property.Value
|
|
||||||
$colIndex++
|
|
||||||
}
|
|
||||||
$rowIndex++
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
$colIndex++
|
||||||
|
}
|
||||||
|
|
||||||
|
# Iterate over each row in the data and update cells
|
||||||
|
$rowIndex = $StartingRowIndex
|
||||||
|
foreach ($item in $Data) {
|
||||||
|
$colIndex = 1
|
||||||
|
foreach ($property in $item.PSObject.Properties) {
|
||||||
|
$Worksheet.Cells[$rowIndex, $colIndex].Value = $property.Value
|
||||||
|
$colIndex++
|
||||||
|
}
|
||||||
|
$rowIndex++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@@ -183,18 +183,11 @@ function Invoke-M365SecurityAudit {
|
|||||||
}
|
}
|
||||||
# Ensure required modules are installed
|
# Ensure required modules are installed
|
||||||
$requiredModules = Get-RequiredModule -AuditFunction
|
$requiredModules = Get-RequiredModule -AuditFunction
|
||||||
$requiredModulesFormatted = ""
|
|
||||||
foreach ($module in $requiredModules) {
|
|
||||||
if ($module.SubModules -and $module.SubModules.Count -gt 0) {
|
|
||||||
$subModulesFormatted = $module.SubModules -join ', '
|
|
||||||
$requiredModulesFormatted += "$($module.ModuleName) (SubModules: $subModulesFormatted), "
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$requiredModulesFormatted += "$($module.ModuleName), "
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$requiredModulesFormatted = $requiredModulesFormatted.TrimEnd(", ")
|
|
||||||
|
|
||||||
|
# Format the required modules list
|
||||||
|
$requiredModulesFormatted = Format-RequiredModuleList -RequiredModules $requiredModules
|
||||||
|
|
||||||
|
# Check and install required modules if necessary
|
||||||
if (!($NoModuleCheck) -and $PSCmdlet.ShouldProcess("Check for required modules: $requiredModulesFormatted", "Check")) {
|
if (!($NoModuleCheck) -and $PSCmdlet.ShouldProcess("Check for required modules: $requiredModulesFormatted", "Check")) {
|
||||||
foreach ($module in $requiredModules) {
|
foreach ($module in $requiredModules) {
|
||||||
Assert-ModuleAvailability -ModuleName $module.ModuleName -RequiredVersion $module.RequiredVersion -SubModules $module.SubModules
|
Assert-ModuleAvailability -ModuleName $module.ModuleName -RequiredVersion $module.RequiredVersion -SubModules $module.SubModules
|
||||||
@@ -254,7 +247,7 @@ function Invoke-M365SecurityAudit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Write-Information "A total of $($totalTests) tests were selected to run..." -InformationAction Continue
|
||||||
# Import the test functions
|
# Import the test functions
|
||||||
$testFiles | ForEach-Object {
|
$testFiles | ForEach-Object {
|
||||||
$currentTestIndex++
|
$currentTestIndex++
|
||||||
|
@@ -44,6 +44,7 @@ If the SkipUpdate switch is used, the function returns an array of custom object
|
|||||||
https://criticalsolutionsnetwork.github.io/M365FoundationsCISReport/#Sync-CISExcelAndCsvData
|
https://criticalsolutionsnetwork.github.io/M365FoundationsCISReport/#Sync-CISExcelAndCsvData
|
||||||
#>
|
#>
|
||||||
function Sync-CISExcelAndCsvData {
|
function Sync-CISExcelAndCsvData {
|
||||||
|
[OutputType([void], [PSCustomObject[]])]
|
||||||
[CmdletBinding(DefaultParameterSetName = 'CsvInput')]
|
[CmdletBinding(DefaultParameterSetName = 'CsvInput')]
|
||||||
param (
|
param (
|
||||||
[Parameter(Mandatory = $true)]
|
[Parameter(Mandatory = $true)]
|
||||||
|
27
tests/Unit/Private/Format-RequiredModuleList.tests.ps1
Normal file
27
tests/Unit/Private/Format-RequiredModuleList.tests.ps1
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
$ProjectPath = "$PSScriptRoot\..\..\.." | Convert-Path
|
||||||
|
$ProjectName = ((Get-ChildItem -Path $ProjectPath\*\*.psd1).Where{
|
||||||
|
($_.Directory.Name -match 'source|src' -or $_.Directory.Name -eq $_.BaseName) -and
|
||||||
|
$(try { Test-ModuleManifest $_.FullName -ErrorAction Stop } catch { $false } )
|
||||||
|
}).BaseName
|
||||||
|
|
||||||
|
|
||||||
|
Import-Module $ProjectName
|
||||||
|
|
||||||
|
InModuleScope $ProjectName {
|
||||||
|
Describe Get-PrivateFunction {
|
||||||
|
Context 'Default' {
|
||||||
|
BeforeEach {
|
||||||
|
$return = Get-PrivateFunction -PrivateData 'string'
|
||||||
|
}
|
||||||
|
|
||||||
|
It 'Returns a single object' {
|
||||||
|
($return | Measure-Object).Count | Should -Be 1
|
||||||
|
}
|
||||||
|
|
||||||
|
It 'Returns a string based on the parameter PrivateData' {
|
||||||
|
$return | Should -Be 'string'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Reference in New Issue
Block a user