mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
[release/v7.4] Suppress false positive PSScriptAnalyzer warnings in tests and build scripts (#26058)
This commit is contained in:
+3
-1
@@ -4,6 +4,9 @@
|
||||
# Module removed due to #4272
|
||||
# disabling tests
|
||||
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '')]
|
||||
param()
|
||||
|
||||
return
|
||||
|
||||
Set-Variable dateInFuture -Option Constant -Value "12/12/2036 09:00"
|
||||
@@ -1557,4 +1560,3 @@ try {
|
||||
finally {
|
||||
$global:PSDefaultParameterValues = $originalDefaultParameterValues
|
||||
}
|
||||
|
||||
|
||||
@@ -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 '..\Microsoft.PowerShell.Security\certificateCommon.psm1')
|
||||
|
||||
Describe "Set/New/Remove-Service cmdlet tests" -Tags "Feature", "RequireAdminOnWindows" {
|
||||
|
||||
@@ -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
|
||||
|
||||
+27
-33
@@ -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
|
||||
}
|
||||
|
||||
|
||||
+30
-36
@@ -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
|
||||
}
|
||||
|
||||
|
||||
+26
-32
@@ -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
|
||||
{
|
||||
<#
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# Licensed under the MIT License.
|
||||
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '')]
|
||||
param()
|
||||
|
||||
Describe "ConvertTo--SecureString" -Tags "CI" {
|
||||
|
||||
Context "Checking return types of ConvertTo--SecureString" {
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# Licensed under the MIT License.
|
||||
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '')]
|
||||
param()
|
||||
|
||||
Describe "WSMan Config Provider" -Tag Feature,RequireAdminOnWindows {
|
||||
BeforeAll {
|
||||
#skip all tests on non-windows platform
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# Licensed under the MIT License.
|
||||
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '')]
|
||||
param()
|
||||
|
||||
Describe "Serialization Tests" -tags "CI" {
|
||||
BeforeAll {
|
||||
$testfileName="SerializationTest.txt"
|
||||
@@ -99,4 +103,3 @@ Describe "Serialization Tests" -tags "CI" {
|
||||
SerializeAndDeserialize($versionObject).TestScriptProperty | Should -Be $versionObject.TestScriptProperty
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,9 @@
|
||||
# PSSession tests for non-Windows platforms
|
||||
#
|
||||
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '')]
|
||||
param()
|
||||
|
||||
function GetRandomString()
|
||||
{
|
||||
return [System.IO.Path]::GetFileNameWithoutExtension([System.IO.Path]::GetRandomFileName())
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# Licensed under the MIT License.
|
||||
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '')]
|
||||
param()
|
||||
|
||||
Import-Module HelpersCommon
|
||||
|
||||
function GetRandomString()
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# Licensed under the MIT License.
|
||||
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '')]
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingPlainTextForPassword', '')]
|
||||
param()
|
||||
|
||||
Class WebListener
|
||||
{
|
||||
[int]$HttpPort
|
||||
|
||||
@@ -15,6 +15,8 @@ function New-LocalUser
|
||||
.OUTPUTS
|
||||
.NOTES
|
||||
#>
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingUsernameAndPasswordParams', '')]
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingPlainTextForPassword', '')]
|
||||
param(
|
||||
[Parameter(Mandatory=$true)]
|
||||
[string] $username,
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# Licensed under the MIT License.
|
||||
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '')]
|
||||
param()
|
||||
|
||||
Set-StrictMode -Version 3.0
|
||||
|
||||
$ErrorActionPreference = 'continue'
|
||||
|
||||
Reference in New Issue
Block a user