Suppress false positive PSScriptAnalyzer warnings in tests and build scripts (#25864)

This commit is contained in:
Patrick Meinecke
2025-08-19 11:51:38 +05:00
committed by GitHub
parent b90f382100
commit c5f2446e69
16 changed files with 127 additions and 103 deletions
@@ -1,5 +1,9 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '')]
param()
Import-Module (Join-Path -Path $PSScriptRoot 'certificateCommon.psm1') -Force
Describe "CmsMessage cmdlets and Get-PfxCertificate basic tests" -Tags "CI" {
@@ -1,5 +1,9 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '')]
param()
Describe "Get-Credential Test" -Tag "CI" {
BeforeAll {
$th = New-TestHost
@@ -5,56 +5,50 @@
# This cmdlet executes the user supplied script (i.e., the script is responsible for validating the desired state of the
# DSC managed node). The result of the script execution is in the form of a hashtable containing all the information
# gathered from the GetScript execution.
function Get-TargetResource
{
function Get-TargetResource {
[CmdletBinding()]
param
(
[parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[string]
$text
)
param(
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[string]
$Text
)
$result = @{
Text = "Hello from Get!";
}
$result;
Text = "Hello from Get!"
}
$result
}
# The Set-TargetResource cmdlet is used to Set the desired state of the DSC managed node through a powershell script.
# The method executes the user supplied script (i.e., the script is responsible for validating the desired state of the
# DSC managed node). If the DSC managed node requires a restart either during or after the execution of the SetScript,
# the SetScript notifies the PS Infrastructure by setting the variable $DSCMachineStatus.IsRestartRequired to $true.
function Set-TargetResource
{
function Set-TargetResource {
[CmdletBinding()]
param
(
[parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[string]
$text
)
$path = "$env:SystemDrive\dscTestPath\hello1.txt"
New-Item -Path $path -Type File -Force
Add-Content -Path $path -Value $text
param(
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[string]
$Text
)
$path = "$env:SystemDrive\dscTestPath\hello1.txt"
New-Item -Path $path -Type File -Force
Add-Content -Path $path -Value $text
}
# The Test-TargetResource cmdlet is used to validate the desired state of the DSC managed node through a powershell script.
# The method executes the user supplied script (i.e., the script is responsible for validating the desired state of the
# DSC managed node). The result of the script execution should be true if the DSC managed machine is in the desired state
# or else false should be returned.
function Test-TargetResource
{
function Test-TargetResource {
[CmdletBinding()]
param
(
[parameter(Mandatory = $true)]
param(
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[string]
$text
)
$false
$Text
)
$false
}
@@ -5,57 +5,51 @@
# This cmdlet executes the user supplied script (i.e., the script is responsible for validating the desired state of the
# DSC managed node). The result of the script execution is in the form of a hashtable containing all the information
# gathered from the GetScript execution.
function Get-TargetResource
{
function Get-TargetResource {
[CmdletBinding()]
param
(
[parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[string]
$text
)
param(
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[string]
$Text
)
$result = @{
Text = "Hello from Get!";
}
$result;
}
Text = "Hello from Get!"
}
$result
}
# The Set-TargetResource cmdlet is used to Set the desired state of the DSC managed node through a powershell script.
# The method executes the user supplied script (i.e., the script is responsible for validating the desired state of the
# DSC managed node). If the DSC managed node requires a restart either during or after the execution of the SetScript,
# the SetScript notifies the PS Infrastructure by setting the variable $DSCMachineStatus.IsRestartRequired to $true.
function Set-TargetResource
{
function Set-TargetResource {
[CmdletBinding()]
param
(
[parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[string]
$text
)
param(
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[string]
$Text
)
$path = "$env:SystemDrive\dscTestPath\hello2.txt"
New-Item -Path $path -Type File -Force
Add-Content -Path $path -Value $text
$path = "$env:SystemDrive\dscTestPath\hello2.txt"
New-Item -Path $path -Type File -Force
Add-Content -Path $path -Value $text
}
# The Test-TargetResource cmdlet is used to validate the desired state of the DSC managed node through a powershell script.
# The method executes the user supplied script (i.e., the script is responsible for validating the desired state of the
# DSC managed node). The result of the script execution should be true if the DSC managed machine is in the desired state
# or else false should be returned.
function Test-TargetResource
{
function Test-TargetResource {
[CmdletBinding()]
param
(
[parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[string]
$text
)
$false
param(
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[string]
$Text
)
$false
}
@@ -5,57 +5,51 @@
# This cmdlet executes the user supplied script (i.e., the script is responsible for validating the desired state of the
# DSC managed node). The result of the script execution is in the form of a hashtable containing all the information
# gathered from the GetScript execution.
function Get-TargetResource
{
function Get-TargetResource {
[CmdletBinding()]
param
(
[parameter(Mandatory = $true)]
param(
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[string]
$text
)
$Text
)
$result = @{
Text = "Hello from Get!";
}
$result;
}
Text = "Hello from Get!"
}
$result
}
# The Set-TargetResource cmdlet is used to Set the desired state of the DSC managed node through a powershell script.
# The method executes the user supplied script (i.e., the script is responsible for validating the desired state of the
# DSC managed node). If the DSC managed node requires a restart either during or after the execution of the SetScript,
# the SetScript notifies the PS Infrastructure by setting the variable $DSCMachineStatus.IsRestartRequired to $true.
function Set-TargetResource
{
function Set-TargetResource {
[CmdletBinding()]
param
(
[parameter(Mandatory = $true)]
param(
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[string]
$text
)
$Text
)
$path = "$env:SystemDrive\dscTestPath\hello3.txt"
New-Item -Path $path -Type File -Force
Add-Content -Path $path -Value $text
$path = "$env:SystemDrive\dscTestPath\hello3.txt"
New-Item -Path $path -Type File -Force
Add-Content -Path $path -Value $text
}
# The Test-TargetResource cmdlet is used to validate the desired state of the DSC managed node through a powershell script.
# The method executes the user supplied script (i.e., the script is responsible for validating the desired state of the
# DSC managed node). The result of the script execution should be true if the DSC managed machine is in the desired state
# or else false should be returned.
function Test-TargetResource
{
function Test-TargetResource {
[CmdletBinding()]
param
(
[parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[string]
$text
)
$false
param(
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[string]
$Text
)
$false
}
@@ -1,6 +1,9 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '')]
param()
Function New-GoodCertificate
{
<#