-
Notifications
You must be signed in to change notification settings - Fork 49
Remove PS5.0 requirement in Meta.Tests to run PSScriptAnalyzer test #32
Comments
Agreeable! Ideally we'd be testing on both v4 and v5?
|
That would be ideal, but I have to admit I usually only test on v5. I think all the repos are set to test on WMF5 AppVeyor boxes too. I haven't played with it much but I think AppVeyor can support dual environments - so possibly all resources could be validated in V4 and V5 environments. But I guess that is a bit off topic 😄 |
Currently only few repos test on WMF 5. |
Sure thing @KarolKaczmarek - I'll pull all Community repos onto my dev box and them a bulk test with the new version once completed. |
thanks! |
Just batch running these tests now with the new version of DscResouce.Tests against all submodule of DSCResources (which is taking a long time). I thought I'd post the script I used to batch run tests against all community DSC Resources in case it is useful to someone else (e.g. Issue #31, Issue #28): Set-Location -Path $PSScriptRoot
git.exe submodule init
git.exe submodule update
$ResourcePath = "$PSScriptRoot\xDscResources"
$Resources = Get-ChildItem -Path $ResourcePath
foreach ($Resource in $Resources)
{
# Pull the DSCResource.Tests repo to each Resource Module
Set-Location -Path $($Resource.FullName)
git.exe clone https://github.com/PowerShell/DscResource.Tests.git
Write-Verbose -Verbose "Invoking tests on $($Resource.Name)"
Invoke-Pester -TestName 'PowerShell DSC resource modules' -Script "$($Resource.Fullname)\DscResource.Tests\Meta.Tests.ps1" -Verbose
} Put the above script into the DSCResources Repo root and run it - although in my case I was cloning my fork of the DscResource.Tests repo (not the PowerShell Org version). |
Unfortunately some of the existing resources are failing the PSSA tests: So far It seems to be the PSAvoidUsingUserNameAndPassWordParams error only. I'd actually suggest that this error is not actually valid for DSC resources anyway (well not valid for the *-TargetResource functions) and should be disabled - @iainbrighton, @KarolKaczmarek ? This error could still be valid for "helper" functions however. But the rule is either applied to all functions or none at all. So, were this change to go in as it is some of the modules would need to be changed. Otherwise the PSAvoidUsingUserNameAndPassWordParams rule would need to be disabled. |
@PlagueHO I think the PSAvoidUsingNameAndPasswordParams rule will be/was tweaked in the next/a recent release of the PSSA?! This update was due for release in Feb by the looks of it. If it has been introduced and is still tripping the PSSA, someone needs to log a bug there /cc @KarolKaczmarek My understanding is that if a parameter is named |
@raghushantha Do you know what's the current state of PSAvoidUsingNameAndPasswordParams rule? @PlagueHO As a temporary solution, feel free to disable this rule. We should get some basic set of rules passing for all resources and expand from there (that's why we don't report occurences of warnings currently) |
@iainbrighton - I'll check on which version that was running and confirm what the situation is with that one. @KarolKaczmarek - once I have confirmed that I was running using the latest version I'll disable the rule (if still a problem). I have created a list of proposed warnings to ignore in issue #28. |
@KarolKaczmarek, @iainbrighton - I've had some time to do some more work on this one. The most common PSSA rule that is being violated by resources is:
In 90% of the cases with this violation are in Samples code in the samples folder. However, there are some violations in the Modules themselves (for example https://github.com/PowerShell/xWebAdministration/blob/dev/DSCResources/MSFT_xWebAppPool/MSFT_xWebAppPool.psm1#L95). There are several ways to fix this:
$Password = New-Object -Type SecureString
[char[]] 'MyPassword' | % { $Password.AppendChar( $_ ) } Or if the password is irrelevant/not actually used (e.g. as is the case in some unit tests): $Password = New-Object -Type SecureString
A summary of the repos where rules are violated:
Other notes:
I also note that some of these repos (xWebAdministration for example) are already failing AppVeyor builds because of these issues. Any thoughts? |
@PlagueHO I can't find any SecureString references in the xDnsServer module? When running the latest version of PSSA, this is what I'm seeing: [10] C:\.....\Resources\xDnsServer [dev]\> Invoke-ScriptAnalyzer -Path .\ -Verbose
VERBOSE: Analyzing file: C:\Users\Iain\Dropbox\PowerShell\DSC\Resources\xDnsServer\xDnsServer.psd1
VERBOSE: Running PSAvoidUsingCmdletAliases rule.
VERBOSE: Running PSAvoidDefaultValueSwitchParameter rule.
VERBOSE: Running PSAvoidGlobalVars rule.
VERBOSE: Running PSAvoidUsingEmptyCatchBlock rule.
VERBOSE: Running PSAvoidInvokingEmptyMembers rule.
VERBOSE: Running PSAvoidNullOrEmptyHelpMessageAttribute rule.
VERBOSE: Running PSAvoidUsingPositionalParameters rule.
VERBOSE: Running PSAvoidShouldContinueWithoutForce rule.
VERBOSE: Running PSReservedCmdletChar rule.
VERBOSE: Running PSAvoidDefaultValueForMandatoryParameter rule.
VERBOSE: Running PSReservedParams rule.
VERBOSE: Running PSAvoidUsingComputerNameHardcoded rule.
VERBOSE: Running PSAvoidUsingUserNameAndPassWordParams rule.
VERBOSE: Running PSAvoidUsingInvokeExpression rule.
VERBOSE: Running PSAvoidUsingPlainTextForPassword rule.
VERBOSE: Running PSAvoidUsingWriteHost rule.
VERBOSE: Running PSAvoidUsingConvertToSecureStringWithPlainText rule.
VERBOSE: Running PSAvoidUsingWMICmdlet rule.
VERBOSE: Running PSMisleadingBacktick rule.
VERBOSE: Running PSUseOutputTypeCorrectly rule.
VERBOSE: Running PSUseBOMForUnicodeEncodedFile rule.
VERBOSE: Running PSPossibleIncorrectComparisonWithNull rule.
VERBOSE: Running PSProvideCommentHelp rule.
VERBOSE: Running PSUseApprovedVerbs rule.
VERBOSE: Running PSUseCmdletCorrectly rule.
VERBOSE: Running PSUseDeclaredVarsMoreThanAssigments rule.
VERBOSE: Running PSUsePSCredentialType rule.
VERBOSE: Running PSShouldProcess rule.
VERBOSE: Running PSUseShouldProcessForStateChangingFunctions rule.
VERBOSE: Running PSUseUTF8EncodingForHelpFile rule.
VERBOSE: Running PSUseSingularNouns rule.
VERBOSE: Running PSAvoidUsingDeprecatedManifestFields rule.
VERBOSE: Running PSMissingModuleManifestField rule.
VERBOSE: Running PSUseToExportFieldsInManifest rule.
RuleName Severity FileName Line Message
-------- -------- -------- ---- -------
PSUseToExportFieldsInManifest Warning xDnsServer 27 Do not use wildcard or $null in this field. Explicitly
.psd1 specify a list for FunctionsToExport.
PSUseToExportFieldsInManifest Warning xDnsServer 30 Do not use wildcard or $null in this field. Explicitly
.psd1 specify a list for CmdletsToExport. No mention of the PSAvoidUsingConvertToSecureStringWithPlainText rule?! |
@iainbrighton - Sorry, you're completely right. I was manually going through the errors on resources from Z to A and so xDNSServer was one of the last ones so I think I was getting a little bit cross-eyed near the end. There errors are these: C:\Users\Daniel\Source\GitHub\xDnsServer [dev]> Invoke-ScriptAnalyzer -path . -Recurse -Severity Error
RuleName Severity FileName Line Message
-------- -------- -------- ---- -------
PSAvoidUsingComputerNameHardcoded Error MSFT_xDnsA 68 The ComputerName parameter of cmdlet
Record.psm 'Add-DnsServerResourceRecordA' is hardcoded. This will
1 expose sensitive information about the system if the script
is shared.
PSAvoidUsingComputerNameHardcoded Error MSFT_xDnsA 72 The ComputerName parameter of cmdlet
Record.psm 'Remove-DnsServerResourceRecord' is hardcoded. This will
1 expose sensitive information about the system if the script
is shared. Also, I am using PSSA 1.5.0.0. I'm also using the script I mentioned earlier to perform a bulk validation on all the modules using the actual Pester tests. I wasn't running PSSA directly (except for the text I pasted above). |
Is there no way to exclude a directory from PSSA scanning? Should this be added as an issue? As a workaround can we not enumerate the files we want checking with Get-Item and exclude the \Examples folder rather than scanning the whole directory structure? |
For the specific xDNSServer it is actually easy enough to fix as it isn't in samples like I first though (been a long day) - get rid of the -ComputerName "Localhost" from these lines: I'm fairly certain they are not required anyway. @iainbrighton, I agree, we could prevent scanning of the Samples and Examples folders. That would eliminate a large number of these issues. It would be easy enough to enumerate the core folders/files and then call PSSA on each folder individually. Definitely no problem there! @KarolKaczmarek - would this be an acceptable solution to this? We could then see what was left over after that (which should be under 20 issues). |
We want examples to be as high quality as possible, so we would like to keep scanning those as well. |
@KarolKaczmarek - Nice! Thanks! |
I seem to have problems with example DSC configurations that use the Import-DscResource with external resources. These raise errors when the example DSC resources aren't available.
|
@iainbrighton - is that rule Warning level or Error level? I get e-mailed those from PSGallery for my submitted modules and from memory they were Warning level (might be wrong though). |
I've attached the full output from the PSSA run on all modules for easy reference (rather than relying on my summary). Sorry about the formatting. |
Yes - the PS Gallery and presumably the MS DSC resources suffer the same fate too? They look like errors to me: Parse error in file ...\Documents\WindowsPowerShell\Modules\Lability\0.9.8\DSCResources\xHyper-V\Examples\Sample_xVhdFileExamples.ps1: The DSC engine could not load the module 'xHyper-V'. It was not found on the system at line 27 column 9 I'm not sure that this needs to logged here though. Where do PS Gallery issues needed to be logged?! User voice? |
@iainbrighton - Yes, those are the ones I get too. PITA, but I guess with good intention. All my sample DSC configs throw so I get pages of them on every release. There needs to be a method to acknowledge and override some PSSA rules in PSGallery for specific projects. Good question about where to log enhancements - MSFT should release the PSGallery source on GitHub so we can have at it 😉 |
Yeah it's a PITA until they block publishing when there are any errors; then it's a problem! I'll ask the product team where this needs to be logged.. |
Thanks @iainbrighton ! We discussed this exact issue last week and there were different opinions on how this should be handled, so this is definitely a valuable feedback. |
Awesome @iainbrighton - have upvoted! |
@PlagueHO What's the status of this issue? Still a problem? |
@johlju - I think we can close this one - pretty sure it is resolved. |
WMF 5.0 no longer a requirement of PSSA. v1.4.0 supports WMF 3.0 and above.
I'll submit a PR if agreeable?
The text was updated successfully, but these errors were encountered: