Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MSFT_xDSCWebService.psm1: Applied fix for issue #460 #507

Merged
merged 15 commits into from
Feb 25, 2019
Merged

MSFT_xDSCWebService.psm1: Applied fix for issue #460 #507

merged 15 commits into from
Feb 25, 2019

Conversation

tmeckel
Copy link
Contributor

@tmeckel tmeckel commented Jan 27, 2019

Pull Request (PR) description

This Pull Request (PR) implements a fix for issue #460

This Pull Request (PR) fixes the following issues

-Fixes #460

Task list

  • Added an entry under the Unreleased section of the change log in the README.md.
    Entry should say what was changed, and how that affects users (if applicable).
  • Resource documentation added/updated in README.md.
  • Resource parameter descriptions added/updated in README.md, schema.mof
    and comment-based help.
  • Comment-based help added/updated.
  • Localization strings added/updated in all localization files as appropriate.
  • Examples appropriately added/updated.
  • Unit tests added/updated. See DSC Resource Testing Guidelines.
  • Integration tests added/updated (where possible). See DSC Resource Testing Guidelines.
  • New/changed code adheres to DSC Resource Style Guidelines and Best Practices.

This change is Reviewable

@mhendric mhendric changed the title Applied fix for issue #460 MSFT_xDSCWebService.psm1: Applied fix for issue #460 Jan 27, 2019
@codecov-io
Copy link

codecov-io commented Jan 28, 2019

Codecov Report

Merging #507 into dev will decrease coverage by <1%.
The diff coverage is 74%.

Impacted file tree graph

@@         Coverage Diff         @@
##            dev   #507   +/-   ##
===================================
- Coverage    74%    74%   -1%     
===================================
  Files        27     27           
  Lines      4030   4074   +44     
  Branches      4      4           
===================================
+ Hits       3009   3032   +23     
- Misses     1017   1038   +21     
  Partials      4      4

@mhendric
Copy link
Contributor

@tmeckel , it look like this change does in fact introduce new issues in the corresponding Unit tests. Those will need to be fixed before this can be merged. Let us know if you need help troubleshooting those tests.

[00:31:01]   Describing MSFT_xDSCWebService\Set-TargetResource
[00:31:01] 
[00:31:01]     Context DSC Service is not installed and Ensure is Absent
[00:31:01]       [+] Should call expected mocks 196ms
[00:31:01] 
[00:31:01]     Context DSC Service is installed and Ensure is Absent
[00:31:02]       [+] Should call expected mocks 229ms
[00:31:02] 
[00:31:02]     Context Ensure is Present
[00:31:03]       [-] Should call expected mocks 550ms
[00:31:03]         RuntimeException: Mock test failed.
[00:31:03]         at Set-TargetResource, C:\projects\xpsdesiredstateconfiguration\DSCResources\MSFT_xDSCWebService\MSFT_xDSCWebService.psm1: line 451
[00:31:03]         at <ScriptBlock>, C:\projects\xpsdesiredstateconfiguration\Tests\Unit\MSFT_xDSCWebService.Tests.ps1: line 505
[00:31:03]       [-] Should create the DatabasePath directory 586ms
[00:31:03]         RuntimeException: Mock test failed.
[00:31:03]         at Set-TargetResource, C:\projects\xpsdesiredstateconfiguration\DSCResources\MSFT_xDSCWebService\MSFT_xDSCWebService.psm1: line 451
[00:31:03]         at <ScriptBlock>, C:\projects\xpsdesiredstateconfiguration\Tests\Unit\MSFT_xDSCWebService.Tests.ps1: line 533
[00:31:04]       [-] Should create the RegistrationKeyPath directory 560ms
[00:31:04]         RuntimeException: Mock test failed.
[00:31:04]         at Set-TargetResource, C:\projects\xpsdesiredstateconfiguration\DSCResources\MSFT_xDSCWebService\MSFT_xDSCWebService.psm1: line 451
[00:31:04]         at <ScriptBlock>, C:\projects\xpsdesiredstateconfiguration\Tests\Unit\MSFT_xDSCWebService.Tests.ps1: line 533
[00:31:05]       [-] Should create the ModulePath directory 563ms
[00:31:05]         RuntimeException: Mock test failed.
[00:31:05]         at Set-TargetResource, C:\projects\xpsdesiredstateconfiguration\DSCResources\MSFT_xDSCWebService\MSFT_xDSCWebService.psm1: line 451
[00:31:05]         at <ScriptBlock>, C:\projects\xpsdesiredstateconfiguration\Tests\Unit\MSFT_xDSCWebService.Tests.ps1: line 533
[00:31:05]       [-] Should create the ConfigurationPath directory 542ms
[00:31:05]         RuntimeException: Mock test failed.
[00:31:05]         at Set-TargetResource, C:\projects\xpsdesiredstateconfiguration\DSCResources\MSFT_xDSCWebService\MSFT_xDSCWebService.psm1: line 451
[00:31:05]         at <ScriptBlock>, C:\projects\xpsdesiredstateconfiguration\Tests\Unit\MSFT_xDSCWebService.Tests.ps1: line 533
[00:31:05] 
[00:31:05]     Context Ensure is Present - isDownLevelOfBlue
[00:31:06]       [-] Should call expected mocks 580ms
[00:31:06]         RuntimeException: Mock test failed.
[00:31:06]         at Set-TargetResource, C:\projects\xpsdesiredstateconfiguration\DSCResources\MSFT_xDSCWebService\MSFT_xDSCWebService.psm1: line 451
[00:31:06]         at <ScriptBlock>, C:\projects\xpsdesiredstateconfiguration\Tests\Unit\MSFT_xDSCWebService.Tests.ps1: line 553
[00:31:06] 
[00:31:06]     Context Ensure is Present - isUpLevelOfBlue
[00:31:07]       [-] Should call expected mocks 742ms
[00:31:07]         RuntimeException: Mock test failed.
[00:31:07]         at Set-TargetResource, C:\projects\xpsdesiredstateconfiguration\DSCResources\MSFT_xDSCWebService\MSFT_xDSCWebService.psm1: line 451
[00:31:07]         at <ScriptBlock>, C:\projects\xpsdesiredstateconfiguration\Tests\Unit\MSFT_xDSCWebService.Tests.ps1: line 582
[00:31:07] 
[00:31:07]     Context Ensure is Present - Enable32BitAppOnWin64
[00:31:08]       [-] Should call expected mocks 562ms
[00:31:08]         RuntimeException: Mock test failed.
[00:31:08]         at Set-TargetResource, C:\projects\xpsdesiredstateconfiguration\DSCResources\MSFT_xDSCWebService\MSFT_xDSCWebService.psm1: line 451
[00:31:08]         at <ScriptBlock>, C:\projects\xpsdesiredstateconfiguration\Tests\Unit\MSFT_xDSCWebService.Tests.ps1: line 606
[00:31:08] 
[00:31:08]     Context Ensure is Present - AcceptSelfSignedCertificates is $false
[00:31:10]       [+] Should call expected mocks 1.34s
[00:31:10] 
[00:31:10]     Context Ensure is Present - UseSecurityBestPractices is $true
[00:31:10]       [+] Should throw an error because no certificate specified 34ms
[00:31:10] 
[00:31:10]     Context Ensure is Present - CertificateSubject
[00:31:11]       [-] Should call expected mocks 618ms
[00:31:11]         RuntimeException: Mock test failed.
[00:31:11]         at Set-TargetResource, C:\projects\xpsdesiredstateconfiguration\DSCResources\MSFT_xDSCWebService\MSFT_xDSCWebService.psm1: line 451
[00:31:11]         at <ScriptBlock>, C:\projects\xpsdesiredstateconfiguration\Tests\Unit\MSFT_xDSCWebService.Tests.ps1: line 678
[00:31:11] 
[00:31:11]     Context Ensure is Present - CertificateThumbprint and UseSecurityBestPractices is $true
[00:31:12]       [-] Should not throw an error 582ms
[00:31:12]         Expected no exception to be thrown, but an exception "Mock test failed." was thrown from line:1 char:59
[00:31:12]             + ... s -notcontains $MyInvocation.Line.Trim()) {throw 'Mock test failed.'}
[00:31:12]             +                                                ~~~~~~~~~~~~~~~~~~~~~~~~~.
[00:31:12]         701:                     {Set-TargetResource @altTestParameters @setTargetPaths -Ensure Present} | Should -Not -throw
[00:31:12]         at <ScriptBlock>, C:\projects\xpsdesiredstateconfiguration\Tests\Unit\MSFT_xDSCWebService.Tests.ps1: line 701
[00:31:12]       [-] Should call expected mocks 42ms
[00:31:12]         Expected Set-UseSecurityBestPractices in module MSFT_xDSCWebService to be called 1 times exactly but was called 0 times
[00:31:12]         706:                     Assert-MockCalled -Exactly -Times 1 -CommandName Set-UseSecurityBestPractices
[00:31:12]         at <ScriptBlock>, C:\projects\xpsdesiredstateconfiguration\Tests\Unit\MSFT_xDSCWebService.Tests.ps1: line 706
[00:31:12] 
[00:31:12]     Context Function parameters contain invalid data
[00:31:13]       [+] Should throw if CertificateThumbprint and CertificateSubject are not specifed 27ms

Also, it looks like the encoding was changed in README.md (Notepad often does this). You can try the helper function to fix that if you like, although sometimes it gets me in more trouble than I was already in. Another option is to just revert the file to its original state, then make the change using an editor like Notepad++ which won't alter the encoding or special characters.

[00:02:11]     Context When repository contains markdown files
[00:02:12]       [+] Markdown file 'HighQualityResourceModulePlan.md' should not have Byte Order Mark (BOM) 32ms
[00:02:12] README.md contain Byte Order Mark (BOM). Use fixer function 'ConvertTo-ASCII'.
[00:02:12]       [-] Markdown file 'README.md' should not have Byte Order Mark (BOM) 96ms
[00:02:12]         Expected $false, but got $true.
[00:02:12]         236:                 $markdownFileHasBom | Should -Be $false
[00:02:12]         at <ScriptBlock>, C:\projects\xpsdesiredstateconfiguration\DscResource.Tests\Meta.Tests.ps1: line 236

@tmeckel
Copy link
Contributor Author

tmeckel commented Jan 28, 2019

@mhendric Seems this fix is getting a real pest now LOL

Anyway ... removing the BOM from the Readme.md is an easy task. I'll correct the encoding an commit the change on the PR. And yes I used notepad to add the required lines to Readme.md and I wasn't aware of the fact that notepad changed the encoding. I only know that behavior from PowershellISE.

With the failing unit tests I'm definitely a bit baffled, because the only thing what's in the PR is a check if the IISSelfSignedCertModule IIS module is already configured on the web application. I'll look at this ... If I can't figure out what's going on I'd like to take your offer and ask for help :-)

Okay a quick analysis showed that the tests always fail at the new added if-test

if (-not ((& $script:appCmd list config -section:system.webServer/globalModules) -match 'IISSelfSignedCertModule'))

I know that Unit tests must be able to run on systems even without an IIS installation. Should I encapsultate the installation of the IISSelfSignedCertModule IIS module into a mockable function then? Or could that test failure being fixed by other means? The $script:appCmd is executed at two lines in the ''old' code starting at https://github.com/PowerShell/xPSDesiredStateConfiguration/blob/ecaa8ac48307f55c0272edaccdf612d16000b442/DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1#L455 so I'm wondering why the Unit tests doesn't fail with those.

@mhendric
Copy link
Contributor

Hey @tmeckel . This is a weird one. I've found a fix, although I'm not sure I fully understand yet why the tests were implemented this way. Essentially, in Tests\Unit\MSFT_xDSCWebService.Tests.ps1, you need to change the $allowedArgs variable from:

        Describe -Name "$dscResourceName\Set-TargetResource" -Fixture {

            function Get-Website {}
            function Get-WebBinding {}

            #region Mocks
            $testArguments = 'if ($allowedArgs -notcontains $MyInvocation.Line.Trim()) {throw ''Mock test failed.''}'

            $allowedArgs = @(
                '& $script:appCmd install module /name:$iisSelfSignedModuleName /image:$destinationFilePath /add:false /lock:false'
                '& $script:appCmd add module /name:$iisSelfSignedModuleName  /app.name:"PSDSCPullServer/" $preConditionBitnessArgumentFor32BitInstall'
            )

to

            $allowedArgs = @(
                '& $script:appCmd install module /name:$iisSelfSignedModuleName /image:$destinationFilePath /add:false /lock:false'
                '& $script:appCmd add module /name:$iisSelfSignedModuleName  /app.name:"PSDSCPullServer/" $preConditionBitnessArgumentFor32BitInstall'
                "if (-not ((& `$script:appCmd list config -section:system.webServer/globalModules) -match 'IISSelfSignedCertModule'))"
            )

@mhendric mhendric added the waiting for code fix A review left open comments, and the pull request is waiting for changes to be pushed by the author. label Jan 28, 2019
@tmeckel
Copy link
Contributor Author

tmeckel commented Jan 29, 2019

@mhendric Nice catch .. I wasn't aware of this feature in Pester 👍 Learned something! But I would call this fix the 'Get the stuff running syndrome' LOL because this wouldn't improve the testability and the robustness of the tests. The fix only allows us to complete the PR. But if we would act often like that we would put additional technical debts in here and I'm pretty sure there're enough of them right now.

This said my proposal would be to write three additional functions: Test-IISSelfSignedModule, Add-IISSelfSignedModule, Remove-IISSelfSignedModule. Test-IISSelfSignedModule will encapsulate the currently offending if-statement and the Add and Remove functions will enable and disable the IIS module (calling Test-IISSelfSignedModule internally). The new functions will be mock-, trace and assertable in Pester.

If you think I'm overstating here, please say so. Then, of course, we can apply the cheap fix.

@mhendric
Copy link
Contributor

@tmeckel , I totally agree! I'd much rather have a highly functional, easier to understand, well written fix, then a cheap fix. If you're willing to take that on, then by all means, go for it!

Copy link
Contributor

@mhendric mhendric left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 0 of 2 files reviewed, 24 unresolved discussions (waiting on @tmeckel)

a discussion (no related file):
Hey @tmeckel. Awesome work here so far. I only reviewed about half your changes, but have some general observations that will need to be addressed throughout:

Lots of new functions need comment based help.
Lots of calls to Write-Verbose or Write-Error need -Message parameter, and non parenthesis
Lots of new function parameter blocks needs to be updated to follow: https://github.com/PowerShell/DscResources/blob/master/StyleGuidelines.md#parameter-block-at-top-of-function
A lot of the new strings should probably be created as localized strings instead.
There seems to be lots of similar code that joins similar paths together. Can any of this be consolidated into a helper function to avoid duplicate code?



DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 445 at r1 (raw file):

        Write-Verbose ('Accepting self signed certificates from incoming hosts')

Needs a -Message parameter on Write-Verbose. The parenthesis are not required.


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 745 at r1 (raw file):

                Write-Verbose ("AcceptSelfSignedCertificates is enabled. Checking if module Selfsigned IIS module is configured for web site at [$webConfigFullPath].")

Needs a -Message parameter on Write-Verbose. The parenthesis are not required.


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 750 at r1 (raw file):

                        Write-Verbose ("Module not enabled in web site. Current configuration does not match the desired state.")

Needs a -Message parameter on Write-Verbose. The parenthesis are not required. Needs single quotes.


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 755 at r1 (raw file):

                        Write-Verbose ("Module present in web site. Current configuration match the desired state.")

Needs a -Message parameter on Write-Verbose. The parenthesis are not required. Needs single quotes.


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 760 at r1 (raw file):

                    Write-Verbose ("Selfsigned module not installed in IIS. Current configuration does not match the desired state.")

Needs a -Message parameter on Write-Verbose. The parenthesis are not required. Needs single quotes.


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 784 at r1 (raw file):

function Get-OSVersion

New function needs comment based help.


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 795 at r1 (raw file):

function Get-WebConfigModulesSetting

New function needs comment based help.


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 827 at r1 (raw file):

# Allow this Website to enable/disable specific Auth Schemes by adding <location> tag in applicationhost.config
function Update-LocationTagInApplicationHostConfigForAuthentication

New function needs comment based help.


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 838 at r1 (raw file):

        [ValidateSet('anonymous', 'basic', 'windows')]

Not positive, but should the first letter of each of these be capitalized?


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 853 at r1 (raw file):

function Get-IISServerManager

New function needs comment based help.


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 873 at r1 (raw file):

# Helper function to Test the specified Web.Config Modules Setting
function Test-WebConfigModulesSetting
{

New function needs comment based help.


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 876 at r1 (raw file):

    param

Function should have an output type of System.Boolean


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 904 at r1 (raw file):

    Write-Verbose ("Test-WebConfigModulesSetting: web.config file not found at [$WebConfigFullPath]")

Needs a -Message parameter on Write-Verbose. The parenthesis are not required.


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 1015 at r1 (raw file):

Quoted 6 lines of code…
function Get-IISAppCmd {
    Push-Location -Path "$env:windir\system32\inetsrv"
    $appCmd = Get-Command -Name '.\appcmd.exe' -CommandType 'Application' -ErrorAction:Stop
    Pop-Location
    $appCmd
}

Function needs comment based help. Also needs cmdletbinding and param statements.


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 1022 at r1 (raw file):

function Test-IISSelfSignedModuleInstalled
 
 

Function needs comment based help.


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 1024 at r1 (raw file):

    [OutputType([bool])]
    param (
        [switch]$Enable32BitAppOnWin64

OutputType should be Boolean or System.Boolean. param style should follow https://github.com/PowerShell/DscResources/blob/master/StyleGuidelines.md#parameter-block-at-top-of-function


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 1033 at r1 (raw file):

function Install-IISSelfSignedModule
 

Needs comment based help.


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 1036 at r1 (raw file):

Quoted 8 lines of code…
    param (
        [switch]$Enable32BitAppOnWin64
 
 
 
 
 
 

Param style should follow https://github.com/PowerShell/DscResources/blob/master/StyleGuidelines.md#parameter-block-at-top-of-function


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 1042 at r1 (raw file):

        Write-Verbose ("Install-IISSelfSignedModule: Providing $iisSelfSignedModuleAssemblyName to run in a 32 bit process")

DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 1042 at r1 (raw file):

    if ($Enable32BitAppOnWin64)
    {
        Write-Verbose ("Install-IISSelfSignedModule: Providing $iisSelfSignedModuleAssemblyName to run in a 32 bit process")

Needs -Message and no parens.


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 1050 at r1 (raw file):

        Write-Verbose ("Install-IISSelfSignedModule: module $iisSelfSignedModuleName already installed")

Needs -Message and no parens.


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 1054 at r1 (raw file):

Write-Verbose ("Install-IISSelfSignedModule: Installing module $iisSelfSignedModuleName")

Needs -Message and no parens.


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 1118 at r1 (raw file):

        Write-Error ("Website [$EndpointName] not found")

Needs -Message and no parens.

@tmeckel
Copy link
Contributor Author

tmeckel commented Feb 11, 2019

Hi @mhendric thanks for starting reviewing my PR. Actually I think it's not in a reviewable state. I admit I should've added a comment respectively or worked on another branch which doesn't push here. As you noticed I started moving code into separate functions, especially for handling of the IIS self signed module. I already moved those functions to separate (helper) modules like PSWSIISEndpoint.psm1 but I had numerous issues with the current Pester Unit tests, e.g. I wasn't abel to get the mock Get-Websiteworking in a (new) PSM1 module which only contained the functions for the IIS module. So I decided to rollback this "cleanup" and only tried to get the Unit tests succeed with minimal changes and the new functions, which are unfortunately clutter up the main module MSFT_xDSCWebService.psm1. This definitely has to be sorted!

To be honest, while I was working on this resource, I discovered so many parts which are implemented inconsistently. The methods for the IIS module are a good example for this. Partly they use appcmd.exe to test or modify the settings. At other edges methods from the WebAdministration modules are (implicitly) used or own support functions are written. Because of this to me it was hard to find a way through all this cleaning up the code in the *-TargetResource methods without breaking the Unit Tests or even the functionality. That's why all those 'Write-Verbose' messages, which I don't actually plan to leave inside the module.

Copy link
Contributor Author

@tmeckel tmeckel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 0 of 2 files reviewed, 24 unresolved discussions (waiting on @mhendric)

a discussion (no related file):

Previously, mhendric (Mike Hendrickson) wrote…

Hey @tmeckel. Awesome work here so far. I only reviewed about half your changes, but have some general observations that will need to be addressed throughout:

Lots of new functions need comment based help.
Lots of calls to Write-Verbose or Write-Error need -Message parameter, and non parenthesis
Lots of new function parameter blocks needs to be updated to follow: https://github.com/PowerShell/DscResources/blob/master/StyleGuidelines.md#parameter-block-at-top-of-function
A lot of the new strings should probably be created as localized strings instead.
There seems to be lots of similar code that joins similar paths together. Can any of this be consolidated into a helper function to avoid duplicate code?

To me cleaning up the code could/should be done, when all required (wrapper/mockable) functions has been created and the existing Unit tests are still successfully passed.



DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 445 at r1 (raw file):

Previously, mhendric (Mike Hendrickson) wrote…
        Write-Verbose ('Accepting self signed certificates from incoming hosts')

Needs a -Message parameter on Write-Verbose. The parenthesis are not required.

Done.


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 745 at r1 (raw file):

Previously, mhendric (Mike Hendrickson) wrote…
                Write-Verbose ("AcceptSelfSignedCertificates is enabled. Checking if module Selfsigned IIS module is configured for web site at [$webConfigFullPath].")

Needs a -Message parameter on Write-Verbose. The parenthesis are not required.

Done.


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 750 at r1 (raw file):

Previously, mhendric (Mike Hendrickson) wrote…
                        Write-Verbose ("Module not enabled in web site. Current configuration does not match the desired state.")

Needs a -Message parameter on Write-Verbose. The parenthesis are not required. Needs single quotes.

Done.


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 755 at r1 (raw file):

Previously, mhendric (Mike Hendrickson) wrote…
                        Write-Verbose ("Module present in web site. Current configuration match the desired state.")

Needs a -Message parameter on Write-Verbose. The parenthesis are not required. Needs single quotes.

Done.


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 760 at r1 (raw file):

Previously, mhendric (Mike Hendrickson) wrote…
                    Write-Verbose ("Selfsigned module not installed in IIS. Current configuration does not match the desired state.")

Needs a -Message parameter on Write-Verbose. The parenthesis are not required. Needs single quotes.

Done.


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 784 at r1 (raw file):

Previously, mhendric (Mike Hendrickson) wrote…
function Get-OSVersion

New function needs comment based help.

Done.


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 795 at r1 (raw file):

Previously, mhendric (Mike Hendrickson) wrote…
function Get-WebConfigModulesSetting

New function needs comment based help.

Done.


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 827 at r1 (raw file):

Previously, mhendric (Mike Hendrickson) wrote…
# Allow this Website to enable/disable specific Auth Schemes by adding <location> tag in applicationhost.config
function Update-LocationTagInApplicationHostConfigForAuthentication

New function needs comment based help.

Done.


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 838 at r1 (raw file):

Previously, mhendric (Mike Hendrickson) wrote…
        [ValidateSet('anonymous', 'basic', 'windows')]

Not positive, but should the first letter of each of these be capitalized?

No... It's the name of the IIS authentocation module. And the names are lowercase


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 853 at r1 (raw file):

Previously, mhendric (Mike Hendrickson) wrote…
function Get-IISServerManager

New function needs comment based help.

Done.


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 873 at r1 (raw file):

Previously, mhendric (Mike Hendrickson) wrote…
# Helper function to Test the specified Web.Config Modules Setting
function Test-WebConfigModulesSetting
{

New function needs comment based help.

Done.


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 876 at r1 (raw file):

Previously, mhendric (Mike Hendrickson) wrote…
    param

Function should have an output type of System.Boolean

Done.


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 904 at r1 (raw file):

Previously, mhendric (Mike Hendrickson) wrote…
    Write-Verbose ("Test-WebConfigModulesSetting: web.config file not found at [$WebConfigFullPath]")

Needs a -Message parameter on Write-Verbose. The parenthesis are not required.

Done.


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 1015 at r1 (raw file):

Previously, mhendric (Mike Hendrickson) wrote…
function Get-IISAppCmd {
    Push-Location -Path "$env:windir\system32\inetsrv"
    $appCmd = Get-Command -Name '.\appcmd.exe' -CommandType 'Application' -ErrorAction:Stop
    Pop-Location
    $appCmd
}

Function needs comment based help. Also needs cmdletbinding and param statements.

Done.


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 1022 at r1 (raw file):

Previously, mhendric (Mike Hendrickson) wrote…
function Test-IISSelfSignedModuleInstalled
 
 

Function needs comment based help.

Done.


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 1024 at r1 (raw file):

Previously, mhendric (Mike Hendrickson) wrote…
    [OutputType([bool])]
    param (
        [switch]$Enable32BitAppOnWin64

OutputType should be Boolean or System.Boolean. param style should follow https://github.com/PowerShell/DscResources/blob/master/StyleGuidelines.md#parameter-block-at-top-of-function

Done.


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 1033 at r1 (raw file):

Previously, mhendric (Mike Hendrickson) wrote…
function Install-IISSelfSignedModule
 

Needs comment based help.

Done.


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 1036 at r1 (raw file):

Previously, mhendric (Mike Hendrickson) wrote…
    param (
        [switch]$Enable32BitAppOnWin64
 
 
 
 
 
 

Param style should follow https://github.com/PowerShell/DscResources/blob/master/StyleGuidelines.md#parameter-block-at-top-of-function

Done.


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 1042 at r1 (raw file):

Previously, mhendric (Mike Hendrickson) wrote…
        Write-Verbose ("Install-IISSelfSignedModule: Providing $iisSelfSignedModuleAssemblyName to run in a 32 bit process")

Done.


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 1042 at r1 (raw file):

Previously, mhendric (Mike Hendrickson) wrote…

Needs -Message and no parens.

Done.


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 1050 at r1 (raw file):

Previously, mhendric (Mike Hendrickson) wrote…
        Write-Verbose ("Install-IISSelfSignedModule: module $iisSelfSignedModuleName already installed")

Needs -Message and no parens.

Done.


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 1054 at r1 (raw file):

Previously, mhendric (Mike Hendrickson) wrote…
Write-Verbose ("Install-IISSelfSignedModule: Installing module $iisSelfSignedModuleName")

Needs -Message and no parens.

Done.


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 1118 at r1 (raw file):

Previously, mhendric (Mike Hendrickson) wrote…
        Write-Error ("Website [$EndpointName] not found")

Needs -Message and no parens.

Done.

@mhendric
Copy link
Contributor

Hey @tmeckel , just checking if you're ready for another code review on this or not. Let me know.

Also, that's totally fine if you want to leave code cleanup for the module until later or a different PR (although newly added code, or modified code, should still follow style guidelines).

Copy link
Contributor Author

@tmeckel tmeckel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @mhendric... just adjusted the code according to your first review. Lemme do some tests tomorrow in one the customers tests enviroments if the code works properly. If so the PR is ready for another review. About the code cleanup: as I said I already had a version for which I moved all helper functions into separate modules. But that broke the Unit tests because I could get the mock for 'Get-Website' running inside all new submodules. I'm still the opinion that this is the correct strategy, I mean movin helper code to sub-modules. But perhaps I need so help from you someone else to get that damn mock running :-D

Reviewable status: 0 of 2 files reviewed, 24 unresolved discussions (waiting on @mhendric)

@tmeckel
Copy link
Contributor Author

tmeckel commented Feb 15, 2019

Hey @mhendric ready for an additional review. As you can see I fixed another issue that prevents the successfull configuration of a PullServer when the IIS SelfSigned module has been already loaded by IIS and is thus locked in the filesystem.

Well there is remaining risk that the configuration will fail, when the loaded module DLL differs from the one which is located in the IIS and the PullServer directory in $env:windir\System32\WindowsPowerShell\v1.0\Modules\PSDesiredStateConfiguration\PullServer but this could only happen if a system update (patch install) is done. Nevertheless the situation with this DLL is really unsatisfying. I would prefer to NOT copy the module to different directory than the installation location $env:windir... because this would save numbers of lines of code and more importantly the issue that I described with a patch installation won't happen anymore because wusa.exe (TiWorker) will detect that the DLL is locked and require a reboot of the server.

Secondly, because I was working on the code sequence anyway, I (hopefully) fixed issue #528 :-D

Copy link
Contributor

@mhendric mhendric left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @tmeckel. Excellent work here. Still some work to be done, but this is getting a lot better.

Reviewable status: 0 of 2 files reviewed, 35 unresolved discussions (waiting on @mhendric and @tmeckel)


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 445 at r1 (raw file):

Previously, tmeckel (Thomas Meckel) wrote…

Done.

Looks like this still needs to be done.


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 784 at r1 (raw file):

Previously, tmeckel (Thomas Meckel) wrote…

Done.

Comment based help should look like the good examples in the DSC style guidelines. Specifically, headers should be indented by 4 chars, and the text underneath should be indented by 8. Also, we don't need a blank line between the header and the text (although we should have a blank line between header sections)

https://github.com/PowerShell/DscResources/blob/master/StyleGuidelines.md#functions-have-comment-based-help


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 795 at r1 (raw file):

Previously, tmeckel (Thomas Meckel) wrote…

Done.

Comment based help should look like the good examples in the DSC style guidelines. Specifically, headers should be indented by 4 chars, and the text underneath should be indented by 8. Also, we don't need a blank line between the header and the text (although we should have a blank line between header sections)

https://github.com/PowerShell/DscResources/blob/master/StyleGuidelines.md#functions-have-comment-based-help


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 827 at r1 (raw file):

Previously, tmeckel (Thomas Meckel) wrote…

Done.

Comment based help should look like the good examples in the DSC style guidelines. Specifically, headers should be indented by 4 chars, and the text underneath should be indented by 8. Also, we don't need a blank line between the header and the text (although we should have a blank line between header sections)

https://github.com/PowerShell/DscResources/blob/master/StyleGuidelines.md#functions-have-comment-based-help


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 853 at r1 (raw file):

Previously, tmeckel (Thomas Meckel) wrote…

Done.

Comment based help should look like the good examples in the DSC style guidelines. Specifically, headers should be indented by 4 chars, and the text underneath should be indented by 8. Also, we don't need a blank line between the header and the text (although we should have a blank line between header sections)

https://github.com/PowerShell/DscResources/blob/master/StyleGuidelines.md#functions-have-comment-based-help


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 873 at r1 (raw file):

Previously, tmeckel (Thomas Meckel) wrote…

Done.

Comment based help should look like the good examples in the DSC style guidelines. Specifically, headers should be indented by 4 chars, and the text underneath should be indented by 8. Also, we don't need a blank line between the header and the text (although we should have a blank line between header sections)

https://github.com/PowerShell/DscResources/blob/master/StyleGuidelines.md#functions-have-comment-based-help


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 1015 at r1 (raw file):

Previously, tmeckel (Thomas Meckel) wrote…

Done.

Can you move the function open bracket to the new line?

Also Comment based help should look like the good examples in the DSC style guidelines. Specifically, headers should be indented by 4 chars, and the text underneath should be indented by 8. Also, we don't need a blank line between the header and the text (although we should have a blank line between header sections)

https://github.com/PowerShell/DscResources/blob/master/StyleGuidelines.md#functions-have-comment-based-help


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 1022 at r1 (raw file):

Previously, tmeckel (Thomas Meckel) wrote…

Done.

Comment based help should look like the good examples in the DSC style guidelines. Specifically, headers should be indented by 4 chars, and the text underneath should be indented by 8. Also, we don't need a blank line between the header and the text (although we should have a blank line between header sections)

https://github.com/PowerShell/DscResources/blob/master/StyleGuidelines.md#functions-have-comment-based-help


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 1033 at r1 (raw file):

Previously, tmeckel (Thomas Meckel) wrote…

Done.

Comment based help should look like the good examples in the DSC style guidelines. Specifically, headers should be indented by 4 chars, and the text underneath should be indented by 8. Also, we don't need a blank line between the header and the text (although we should have a blank line between header sections)

https://github.com/PowerShell/DscResources/blob/master/StyleGuidelines.md#functions-have-comment-based-help


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 1036 at r1 (raw file):

Previously, tmeckel (Thomas Meckel) wrote…

Done.

This one still needs a bit of an update. Can you change the type to 'Switch' (uppercase) or 'System.Management.Automation.SwitchParameter'? Also, the type and the variable name should be on separate lines.


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 907 at r3 (raw file):

# Name of the WebSite

Don't need this with comment based help


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 912 at r3 (raw file):

# Authentication Type

Don't need this with comment based help


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 944 at r3 (raw file):

Quoted 12 lines of code…
    $iisInstallPath = (Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\INetStp' -Name InstallPath).InstallPath
    if (-not $iisInstallPath)
    {
        throw ($LocalizedData.IISInstallationPathNotFound)
    }
    $assyPath = Join-Path -Path $iisInstallPath -ChildPath 'Microsoft.Web.Administration.dll' -Resolve -ErrorAction:SilentlyContinue
    if (-not $assyPath)
    {
        throw ($LocalizedData.IISWebAdministrationAssemblyNotFound)
    }
    $assy = [System.Reflection.Assembly]::LoadFrom($assyPath)
    return [System.Activator]::CreateInstance($assy.FullName, 'Microsoft.Web.Administration.ServerManager').Unwrap()

Can you add some line breaks in here between the variable assignments and the if blocks to make this easier to read?


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 1022 at r3 (raw file):

Quoted 16 lines of code…
.SYNOPSIS
 
Tests if a the currently configured path for a website is equal to a given path
 
.PARAMETER EndpointName
 
The endpoint name (website name) to test
 
.PARAMETER PhysicalPath
 
The full physical path to check
 
.OUTPUTS
 
System.Boolean. true if the current installation status is equal to the expected installation status
 

Comment based help should look like the good examples in the DSC style guidelines. Specifically, headers should be indented by 4 chars, and the text underneath should be indented by 8. Also, we don't need a blank line between the header and the text (although we should have a blank line between header sections)

https://github.com/PowerShell/DscResources/blob/master/StyleGuidelines.md#functions-have-comment-based-help


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 1063 at r3 (raw file):

Quoted 21 lines of code…
.SYNOPSIS
 
Test if a currently configured app setting is equal to a given value
 
.PARAMETER WebConfigFullPath
 
The full path to the web.config
 
 
.PARAMETER AppSettingName
 
The app setting name to check
 
.PARAMETER ExpectedAppSettingValue
 
The expected value
 
.OUTPUTS
 
System.Boolean. true if the current value is equal to the expected value
 

Comment based help should look like the good examples in the DSC style guidelines. Specifically, headers should be indented by 4 chars, and the text underneath should be indented by 8. Also, we don't need a blank line between the header and the text (although we should have a blank line between header sections)

https://github.com/PowerShell/DscResources/blob/master/StyleGuidelines.md#functions-have-comment-based-help


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 1130 at r3 (raw file):

Quoted 17 lines of code…
.SYNOPSIS
 
Helper function to Get the specified Web.Config App Setting
 
.PARAMETER WebConfigFullPath
 
The full path to the web.config
 
 
.PARAMETER AppSettingName
 
The app settings name to get the value for
 
.OUTPUTS
 
System.String. the current app settings value
 

Comment based help should look like the good examples in the DSC style guidelines. Specifically, headers should be indented by 4 chars, and the text underneath should be indented by 8. Also, we don't need a blank line between the header and the text (although we should have a blank line between header sections)

https://github.com/PowerShell/DscResources/blob/master/StyleGuidelines.md#functions-have-comment-based-help


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 1184 at r3 (raw file):

IIS Selfsegned Certficate Module

Need to fix the misspelling of Self Signed


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 1212 at r3 (raw file):

Quoted 16 lines of code…
.SYNOPSIS
 
Tests if two files differ
 
.PARAMETER SourceFilePath
 
Path to the source file
 
.PARAMETER DestinationFilePath
 
Path to the destination file
 
.OUTPUTS
 
System.Boolean. true if the two files differ
 

Comment based help should look like the good examples in the DSC style guidelines. Specifically, headers should be indented by 4 chars, and the text underneath should be indented by 8. Also, we don't need a blank line between the header and the text (although we should have a blank line between header sections)

https://github.com/PowerShell/DscResources/blob/master/StyleGuidelines.md#functions-have-comment-based-help


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 1314 at r3 (raw file):

Quoted 13 lines of code…
        $destinationFolderPath = "$env:windir\System32\inetsrv"
        $destinationFilePath = Join-Path -Path $destinationFolderPath -ChildPath $iisSelfSignedModuleAssemblyName
        if (Test-FilesDiffer -SourceFilePath $sourceFilePath -DestinationFilePath $destinationFilePath)
        {
            # Might fail if the DLL has already been loaded by the IIS from a former PullServer Deployment
            Copy-Item -Path $sourceFilePath -Destination $destinationFolderPath -Force
        }
        else
        {
            Write-Verbose -Message "Install-IISSelfSignedModule: module $iisSelfSignedModuleName already installed at $destinationFilePath with the correct version"
        }
        Write-Verbose -Message "Install-IISSelfSignedModule: globally activating module $iisSelfSignedModuleName"
        & (Get-IISAppCmd) install module /name:$iisSelfSignedModuleName /image:$destinationFilePath /add:false /lock:false

Could use some line breaks in here between the if/else blocks and everything else to make this more readable.


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 1331 at r3 (raw file):

Quoted 12 lines of code…
.SYNOPSIS
 
Enable the IISSelfSignedModule module for a specific website (endpoint)
 
.PARAMETER EndpointName
 
The endpoint (website) for which the module should be enabled
 
.PARAMETER Enable32BitAppOnWin64
 
If set enable the module as a 32bit module
 

Comment based help should look like the good examples in the DSC style guidelines. Specifically, headers should be indented by 4 chars, and the text underneath should be indented by 8. Also, we don't need a blank line between the header and the text (although we should have a blank line between header sections)

https://github.com/PowerShell/DscResources/blob/master/StyleGuidelines.md#functions-have-comment-based-help


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 1346 at r3 (raw file):

Quoted 5 lines of code…
    param (
        [Parameter(Mandatory)]
        [ValidateNotNullOrEmpty()]
        [string]$EndpointName,
        [switch]$Enable32BitAppOnWin64

Open parens for param should be on new line. [String] and [Switch] should be capitalized. Variable names should be on their own line. $Enable32BitAppOnWin64 needs a [Parameter()] block. Parameter should be : [Parameter(Mandatory = $true)]


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 1365 at r3 (raw file):

Quoted 8 lines of code…
.SYNOPSIS
 
Disable the IISSelfSignedModule module for a specific website (endpoint)
 
.PARAMETER EndpointName
 
The endpoint (website) for which the module should be disabled
 

Comment based help should look like the good examples in the DSC style guidelines. Specifically, headers should be indented by 4 chars, and the text underneath should be indented by 8. Also, we don't need a blank line between the header and the text (although we should have a blank line between header sections)

https://github.com/PowerShell/DscResources/blob/master/StyleGuidelines.md#functions-have-comment-based-help


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 1379 at r3 (raw file):

Quoted 4 lines of code…
    param (
        [Parameter(Mandatory)]
        [ValidateNotNullOrEmpty()]
        [string]$EndpointName

Open parens for param should be on new line. [String] should be capitalized. Variable names should be on their own line. Parameter should be : [Parameter(Mandatory = $true)]


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 1387 at r3 (raw file):

Quoted 28 lines of code…
.SYNOPSIS
 
 
 
 
 
 
 
 
 
 
 
 
 
Tests if the IISSelfSignedModule module is enabled for a website (endpoint)
 
.PARAMETER EndpointName
 
The endpoint (website) for which the status should be checked
 
.OUTPUTS
 
System.Boolean. true if the module is enabled
 
 
 
 
 

Comment based help should look like the good examples in the DSC style guidelines. Specifically, headers should be indented by 4 chars, and the text underneath should be indented by 8. Also, we don't need a blank line between the header and the text (although we should have a blank line between header sections)

https://github.com/PowerShell/DscResources/blob/master/StyleGuidelines.md#functions-have-comment-based-help


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 1405 at r3 (raw file):

        [Parameter(Mandatory)]
        [ValidateNotNullOrEmpty()]
        [string]$EndpointName

Open parens for param should be on new line. [String] should be capitalized. Variable names should be on their own line.

Parameter should be : [Parameter(Mandatory = $true)]


Tests/Unit/MSFT_xDSCWebService.Tests.ps1, line 182 at r3 (raw file):

Quoted 6 lines of code…
            Mock -CommandName Test-WebConfigModulesSetting `
                -ParameterFilter {$ModuleName -eq 'IISSelfSignedCertModule(32bit)'}  `
                -MockWith { param ($ExpectedInstallationStatus)
                    Write-Verbose -Message 'Test-WebConfigAppSetting - IISSelfSignedCertModule';
                    $acceptSelfSignedCertificates -eq $ExpectedInstallationStatus
                }

If this code isn't necessary it should be removed.


Tests/Unit/MSFT_xDSCWebService.Tests.ps1, line 472 at r3 (raw file):

            $testArguments = 'if ($allowedArgs -notcontains $MyInvocation.Line.Trim()) {throw ''Mock test failed.''}'

I don't see $allowedArgs defined anywhere anymore. Will this actually do anything?


Tests/Unit/MSFT_xDSCWebService.Tests.ps1, line 484 at r3 (raw file):

##FIXME: Assert-MockCalled -Exactly -Times 1 -CommandName Get-Command

Fix me :)


Tests/Unit/MSFT_xDSCWebService.Tests.ps1, line 498 at r3 (raw file):

##FIXME: Assert-MockCalled -Exactly -Times 1 -CommandName Get-Command

Fix me :)


Tests/Unit/MSFT_xDSCWebService.Tests.ps1, line 578 at r3 (raw file):

##FIXME: Assert-MockCalled -Exactly -Times 1 -CommandName Get-Command

Fix me :)


Tests/Unit/MSFT_xDSCWebService.Tests.ps1, line 637 at r3 (raw file):

##FIXME: Assert-MockCalled -Exactly -Times 1 -CommandName Get-Command

Fix me :)


Tests/Unit/MSFT_xDSCWebService.Tests.ps1, line 665 at r3 (raw file):

##FIXME: Assert-MockCalled -Exactly -Times 1 -CommandName Get-Command

Fix me :)


Tests/Unit/MSFT_xDSCWebService.Tests.ps1, line 754 at r3 (raw file):

            $testArguments = 'if ($allowedArgs -notcontains $MyInvocation.Line.Trim()) {throw ''Mock test failed.''}'

I don't see $allowedArgs defined anywhere anymore. Will this actually do anything?

Copy link
Contributor Author

@tmeckel tmeckel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 0 of 2 files reviewed, 35 unresolved discussions (waiting on @mhendric and @tmeckel)


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 445 at r1 (raw file):

Accepting self signed certificates from incoming hosts
Missed that damn thingy :-D


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 784 at r1 (raw file):

Previously, mhendric (Mike Hendrickson) wrote…

Comment based help should look like the good examples in the DSC style guidelines. Specifically, headers should be indented by 4 chars, and the text underneath should be indented by 8. Also, we don't need a blank line between the header and the text (although we should have a blank line between header sections)

https://github.com/PowerShell/DscResources/blob/master/StyleGuidelines.md#functions-have-comment-based-help

Done according to style guides


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 795 at r1 (raw file):

Previously, mhendric (Mike Hendrickson) wrote…

Comment based help should look like the good examples in the DSC style guidelines. Specifically, headers should be indented by 4 chars, and the text underneath should be indented by 8. Also, we don't need a blank line between the header and the text (although we should have a blank line between header sections)

https://github.com/PowerShell/DscResources/blob/master/StyleGuidelines.md#functions-have-comment-based-help

Done according to style guides.


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 827 at r1 (raw file):

Previously, mhendric (Mike Hendrickson) wrote…

Comment based help should look like the good examples in the DSC style guidelines. Specifically, headers should be indented by 4 chars, and the text underneath should be indented by 8. Also, we don't need a blank line between the header and the text (although we should have a blank line between header sections)

https://github.com/PowerShell/DscResources/blob/master/StyleGuidelines.md#functions-have-comment-based-help

Done according to style guides.


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 853 at r1 (raw file):

Previously, mhendric (Mike Hendrickson) wrote…

Comment based help should look like the good examples in the DSC style guidelines. Specifically, headers should be indented by 4 chars, and the text underneath should be indented by 8. Also, we don't need a blank line between the header and the text (although we should have a blank line between header sections)

https://github.com/PowerShell/DscResources/blob/master/StyleGuidelines.md#functions-have-comment-based-help

Done according to style guides


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 873 at r1 (raw file):

Previously, mhendric (Mike Hendrickson) wrote…

Comment based help should look like the good examples in the DSC style guidelines. Specifically, headers should be indented by 4 chars, and the text underneath should be indented by 8. Also, we don't need a blank line between the header and the text (although we should have a blank line between header sections)

https://github.com/PowerShell/DscResources/blob/master/StyleGuidelines.md#functions-have-comment-based-help

Done according to style guides


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 1015 at r1 (raw file):

Previously, mhendric (Mike Hendrickson) wrote…

Can you move the function open bracket to the new line?

Also Comment based help should look like the good examples in the DSC style guidelines. Specifically, headers should be indented by 4 chars, and the text underneath should be indented by 8. Also, we don't need a blank line between the header and the text (although we should have a blank line between header sections)

https://github.com/PowerShell/DscResources/blob/master/StyleGuidelines.md#functions-have-comment-based-help

Done


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 1022 at r1 (raw file):

Previously, mhendric (Mike Hendrickson) wrote…

Comment based help should look like the good examples in the DSC style guidelines. Specifically, headers should be indented by 4 chars, and the text underneath should be indented by 8. Also, we don't need a blank line between the header and the text (although we should have a blank line between header sections)

https://github.com/PowerShell/DscResources/blob/master/StyleGuidelines.md#functions-have-comment-based-help

Done


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 1033 at r1 (raw file):

Previously, mhendric (Mike Hendrickson) wrote…

Comment based help should look like the good examples in the DSC style guidelines. Specifically, headers should be indented by 4 chars, and the text underneath should be indented by 8. Also, we don't need a blank line between the header and the text (although we should have a blank line between header sections)

https://github.com/PowerShell/DscResources/blob/master/StyleGuidelines.md#functions-have-comment-based-help

Done


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 1036 at r1 (raw file):

Previously, mhendric (Mike Hendrickson) wrote…

This one still needs a bit of an update. Can you change the type to 'Switch' (uppercase) or 'System.Management.Automation.SwitchParameter'? Also, the type and the variable name should be on separate lines.

Done


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 907 at r3 (raw file):

Previously, mhendric (Mike Hendrickson) wrote…
# Name of the WebSite

Don't need this with comment based help

Removed


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 912 at r3 (raw file):

Previously, mhendric (Mike Hendrickson) wrote…
# Authentication Type

Don't need this with comment based help

Removed


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 944 at r3 (raw file):

Previously, mhendric (Mike Hendrickson) wrote…
    $iisInstallPath = (Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\INetStp' -Name InstallPath).InstallPath
    if (-not $iisInstallPath)
    {
        throw ($LocalizedData.IISInstallationPathNotFound)
    }
    $assyPath = Join-Path -Path $iisInstallPath -ChildPath 'Microsoft.Web.Administration.dll' -Resolve -ErrorAction:SilentlyContinue
    if (-not $assyPath)
    {
        throw ($LocalizedData.IISWebAdministrationAssemblyNotFound)
    }
    $assy = [System.Reflection.Assembly]::LoadFrom($assyPath)
    return [System.Activator]::CreateInstance($assy.FullName, 'Microsoft.Web.Administration.ServerManager').Unwrap()

Can you add some line breaks in here between the variable assignments and the if blocks to make this easier to read?

Added some line breaks


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 1022 at r3 (raw file):

Previously, mhendric (Mike Hendrickson) wrote…
.SYNOPSIS
 
Tests if a the currently configured path for a website is equal to a given path
 
.PARAMETER EndpointName
 
The endpoint name (website name) to test
 
.PARAMETER PhysicalPath
 
The full physical path to check
 
.OUTPUTS
 
System.Boolean. true if the current installation status is equal to the expected installation status
 

Comment based help should look like the good examples in the DSC style guidelines. Specifically, headers should be indented by 4 chars, and the text underneath should be indented by 8. Also, we don't need a blank line between the header and the text (although we should have a blank line between header sections)

https://github.com/PowerShell/DscResources/blob/master/StyleGuidelines.md#functions-have-comment-based-help

Done according to style guides


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 1063 at r3 (raw file):

Previously, mhendric (Mike Hendrickson) wrote…
.SYNOPSIS
 
Test if a currently configured app setting is equal to a given value
 
.PARAMETER WebConfigFullPath
 
The full path to the web.config
 
 
.PARAMETER AppSettingName
 
The app setting name to check
 
.PARAMETER ExpectedAppSettingValue
 
The expected value
 
.OUTPUTS
 
System.Boolean. true if the current value is equal to the expected value
 

Comment based help should look like the good examples in the DSC style guidelines. Specifically, headers should be indented by 4 chars, and the text underneath should be indented by 8. Also, we don't need a blank line between the header and the text (although we should have a blank line between header sections)

https://github.com/PowerShell/DscResources/blob/master/StyleGuidelines.md#functions-have-comment-based-help

Done


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 1130 at r3 (raw file):

Previously, mhendric (Mike Hendrickson) wrote…
.SYNOPSIS
 
Helper function to Get the specified Web.Config App Setting
 
.PARAMETER WebConfigFullPath
 
The full path to the web.config
 
 
.PARAMETER AppSettingName
 
The app settings name to get the value for
 
.OUTPUTS
 
System.String. the current app settings value
 

Comment based help should look like the good examples in the DSC style guidelines. Specifically, headers should be indented by 4 chars, and the text underneath should be indented by 8. Also, we don't need a blank line between the header and the text (although we should have a blank line between header sections)

https://github.com/PowerShell/DscResources/blob/master/StyleGuidelines.md#functions-have-comment-based-help

Done


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 1184 at r3 (raw file):

Previously, mhendric (Mike Hendrickson) wrote…
IIS Selfsegned Certficate Module

Need to fix the misspelling of Self Signed

Corrected


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 1212 at r3 (raw file):

Previously, mhendric (Mike Hendrickson) wrote…
.SYNOPSIS
 
Tests if two files differ
 
.PARAMETER SourceFilePath
 
Path to the source file
 
.PARAMETER DestinationFilePath
 
Path to the destination file
 
.OUTPUTS
 
System.Boolean. true if the two files differ
 

Comment based help should look like the good examples in the DSC style guidelines. Specifically, headers should be indented by 4 chars, and the text underneath should be indented by 8. Also, we don't need a blank line between the header and the text (although we should have a blank line between header sections)

https://github.com/PowerShell/DscResources/blob/master/StyleGuidelines.md#functions-have-comment-based-help

Done


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 1314 at r3 (raw file):

Previously, mhendric (Mike Hendrickson) wrote…
        $destinationFolderPath = "$env:windir\System32\inetsrv"
        $destinationFilePath = Join-Path -Path $destinationFolderPath -ChildPath $iisSelfSignedModuleAssemblyName
        if (Test-FilesDiffer -SourceFilePath $sourceFilePath -DestinationFilePath $destinationFilePath)
        {
            # Might fail if the DLL has already been loaded by the IIS from a former PullServer Deployment
            Copy-Item -Path $sourceFilePath -Destination $destinationFolderPath -Force
        }
        else
        {
            Write-Verbose -Message "Install-IISSelfSignedModule: module $iisSelfSignedModuleName already installed at $destinationFilePath with the correct version"
        }
        Write-Verbose -Message "Install-IISSelfSignedModule: globally activating module $iisSelfSignedModuleName"
        & (Get-IISAppCmd) install module /name:$iisSelfSignedModuleName /image:$destinationFilePath /add:false /lock:false

Could use some line breaks in here between the if/else blocks and everything else to make this more readable.

I added some line breaks here. Hope it's more readable now.


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 1331 at r3 (raw file):

Previously, mhendric (Mike Hendrickson) wrote…
.SYNOPSIS
 
Enable the IISSelfSignedModule module for a specific website (endpoint)
 
.PARAMETER EndpointName
 
The endpoint (website) for which the module should be enabled
 
.PARAMETER Enable32BitAppOnWin64
 
If set enable the module as a 32bit module
 

Comment based help should look like the good examples in the DSC style guidelines. Specifically, headers should be indented by 4 chars, and the text underneath should be indented by 8. Also, we don't need a blank line between the header and the text (although we should have a blank line between header sections)

https://github.com/PowerShell/DscResources/blob/master/StyleGuidelines.md#functions-have-comment-based-help

Done.


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 1346 at r3 (raw file):

Previously, mhendric (Mike Hendrickson) wrote…
    param (
        [Parameter(Mandatory)]
        [ValidateNotNullOrEmpty()]
        [string]$EndpointName,
        [switch]$Enable32BitAppOnWin64

Open parens for param should be on new line. [String] and [Switch] should be capitalized. Variable names should be on their own line. $Enable32BitAppOnWin64 needs a [Parameter()] block. Parameter should be : [Parameter(Mandatory = $true)]

Done.


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 1365 at r3 (raw file):

Previously, mhendric (Mike Hendrickson) wrote…
.SYNOPSIS
 
Disable the IISSelfSignedModule module for a specific website (endpoint)
 
.PARAMETER EndpointName
 
The endpoint (website) for which the module should be disabled
 

Comment based help should look like the good examples in the DSC style guidelines. Specifically, headers should be indented by 4 chars, and the text underneath should be indented by 8. Also, we don't need a blank line between the header and the text (although we should have a blank line between header sections)

https://github.com/PowerShell/DscResources/blob/master/StyleGuidelines.md#functions-have-comment-based-help

Done.


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 1379 at r3 (raw file):

Previously, mhendric (Mike Hendrickson) wrote…
    param (
        [Parameter(Mandatory)]
        [ValidateNotNullOrEmpty()]
        [string]$EndpointName

Open parens for param should be on new line. [String] should be capitalized. Variable names should be on their own line. Parameter should be : [Parameter(Mandatory = $true)]

Done.


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 1387 at r3 (raw file):

Previously, mhendric (Mike Hendrickson) wrote…
.SYNOPSIS
 
 
 
 
 
 
 
 
 
 
 
 
 
Tests if the IISSelfSignedModule module is enabled for a website (endpoint)
 
.PARAMETER EndpointName
 
The endpoint (website) for which the status should be checked
 
.OUTPUTS
 
System.Boolean. true if the module is enabled
 
 
 
 
 

Comment based help should look like the good examples in the DSC style guidelines. Specifically, headers should be indented by 4 chars, and the text underneath should be indented by 8. Also, we don't need a blank line between the header and the text (although we should have a blank line between header sections)

https://github.com/PowerShell/DscResources/blob/master/StyleGuidelines.md#functions-have-comment-based-help

Done.


DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 1405 at r3 (raw file):

Previously, mhendric (Mike Hendrickson) wrote…
        [Parameter(Mandatory)]
        [ValidateNotNullOrEmpty()]
        [string]$EndpointName

Open parens for param should be on new line. [String] should be capitalized. Variable names should be on their own line.

Parameter should be : [Parameter(Mandatory = $true)]

Done.

Copy link
Contributor

@mhendric mhendric left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 of 2 files at r5.
Reviewable status: 1 of 2 files reviewed, 10 unresolved discussions (waiting on @mhendric and @tmeckel)


Tests/Unit/MSFT_xDSCWebService.Tests.ps1, line 519 at r5 (raw file):

##FIXME: Assert-MockCalled -Exactly -Times 1 -CommandName Get-Command

Needs to be fixed.


Tests/Unit/MSFT_xDSCWebService.Tests.ps1, line 602 at r5 (raw file):

##FIXME: Assert-MockCalled -Exactly -Times 1 -CommandName Get-Command

Needs to be fixed.

Copy link
Contributor Author

@tmeckel tmeckel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 1 of 2 files reviewed, 10 unresolved discussions (waiting on @mhendric)


Tests/Unit/MSFT_xDSCWebService.Tests.ps1, line 182 at r3 (raw file):

Previously, mhendric (Mike Hendrickson) wrote…
            Mock -CommandName Test-WebConfigModulesSetting `
                -ParameterFilter {$ModuleName -eq 'IISSelfSignedCertModule(32bit)'}  `
                -MockWith { param ($ExpectedInstallationStatus)
                    Write-Verbose -Message 'Test-WebConfigAppSetting - IISSelfSignedCertModule';
                    $acceptSelfSignedCertificates -eq $ExpectedInstallationStatus
                }

If this code isn't necessary it should be removed.

Removed the Mock … Tests are still passed


Tests/Unit/MSFT_xDSCWebService.Tests.ps1, line 472 at r3 (raw file):

$allowedArgs
Re-inserted $allowedArgs because it has been inadvertently removed. Wondering why the tests still passed though!


Tests/Unit/MSFT_xDSCWebService.Tests.ps1, line 484 at r3 (raw file):

Previously, mhendric (Mike Hendrickson) wrote…
##FIXME: Assert-MockCalled -Exactly -Times 1 -CommandName Get-Command

Fix me :)

Replaced with the correct new mock function Get-IISAppCmd


Tests/Unit/MSFT_xDSCWebService.Tests.ps1, line 498 at r3 (raw file):

Previously, mhendric (Mike Hendrickson) wrote…
##FIXME: Assert-MockCalled -Exactly -Times 1 -CommandName Get-Command

Fix me :)

Corrected with new mock function


Tests/Unit/MSFT_xDSCWebService.Tests.ps1, line 578 at r3 (raw file):

Previously, mhendric (Mike Hendrickson) wrote…
##FIXME: Assert-MockCalled -Exactly -Times 1 -CommandName Get-Command

Fix me :)

Corrected with mock Get-IISAppCmd


Tests/Unit/MSFT_xDSCWebService.Tests.ps1, line 637 at r3 (raw file):

Previously, mhendric (Mike Hendrickson) wrote…
##FIXME: Assert-MockCalled -Exactly -Times 1 -CommandName Get-Command

Fix me :)

Corrected with new mock function


Tests/Unit/MSFT_xDSCWebService.Tests.ps1, line 665 at r3 (raw file):

Previously, mhendric (Mike Hendrickson) wrote…
##FIXME: Assert-MockCalled -Exactly -Times 1 -CommandName Get-Command

Fix me :)

Corrected with new mock function


Tests/Unit/MSFT_xDSCWebService.Tests.ps1, line 754 at r3 (raw file):

Previously, mhendric (Mike Hendrickson) wrote…
            $testArguments = 'if ($allowedArgs -notcontains $MyInvocation.Line.Trim()) {throw ''Mock test failed.''}'

I don't see $allowedArgs defined anywhere anymore. Will this actually do anything?

Re-inserted $allowedArgs again because it has been deleted inadvertently


Tests/Unit/MSFT_xDSCWebService.Tests.ps1, line 519 at r5 (raw file):

Previously, mhendric (Mike Hendrickson) wrote…
##FIXME: Assert-MockCalled -Exactly -Times 1 -CommandName Get-Command

Needs to be fixed.

Corrected


Tests/Unit/MSFT_xDSCWebService.Tests.ps1, line 602 at r5 (raw file):

Previously, mhendric (Mike Hendrickson) wrote…
##FIXME: Assert-MockCalled -Exactly -Times 1 -CommandName Get-Command

Needs to be fixed.

Corrected with new mock Get-IISAppCmd

@tmeckel
Copy link
Contributor Author

tmeckel commented Feb 17, 2019

Hey @mhendric … ready for the next review :-D in addition I found and corrected an issue how the module detects the FQDN of a host. The old code relied on environment variables. I adopted the code from the uni tests which uses [System.Net.NetworkInformation.IPGlobalProperties]::GetIPGlobalProperties() what is much more reliable!

Copy link
Contributor

@mhendric mhendric left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 of 2 files at r6.
Reviewable status: 1 of 2 files reviewed, 2 unresolved discussions (waiting on @mhendric and @tmeckel)


Tests/Unit/MSFT_xDSCWebService.Tests.ps1, line 472 at r3 (raw file):

Previously, tmeckel (Thomas Meckel) wrote…

$allowedArgs
Re-inserted $allowedArgs because it has been inadvertently removed. Wondering why the tests still passed though!

To be honest, I'm still a bit confused as to what the $testArguments script block was trying to accomplish in the first place. Having spent a lot of time looking at this code, do you think this particular MockWith buys us much? The $allowedArgs variable triggers the PSUseDeclaredVarsMoreThanAssignments script analyzer rule since it's not actually used until RunTime. If these two vars aren't actually doing much (other than confusing us), maybe they shouldn't be here...

@mhendric
Copy link
Contributor

Hey @tmeckel , I just noticed that this fixes all but one of the script analyzer errors in the Meta tests. Up to you if you want to fix that here or not, but if not, we'll need another PR for it at some point.

[00:01:09] Context MSFT_xDSCWebService.psm1
[00:01:09] [+] Should pass all error-level PS Script Analyzer rules 67ms
[00:01:13] [+] Should pass all required PS Script Analyzer rules 3.87s
[00:01:14] Flagged PSSA rule(s) did not pass.
[00:01:14] The following PSScriptAnalyzer rule 'PSDSCUseVerboseMessageInDSCResource' errors need to be fixed:
[00:01:14] MSFT_xDSCWebService.psm1 (Line 23): There is no call to Write-Verbose in DSC function 'Get-TargetResource'. If you are using Write-Verbose in a helper function, suppress this rule application.
[00:01:14] For instructions on how to run PSScriptAnalyzer on your own machine, please go to https://github.com/powershell/PSScriptAnalyzer
[00:01:14] Common Tests - Flagged Script Analyzer Rules will not fail unless you opt-in.
[00:01:14] To opt-in, create a '.MetaTestOptIn.json' at the root
[00:01:14] of the repo in the following format:
[00:01:14] [
[00:01:14] "Common Tests - Flagged Script Analyzer Rules"
[00:01:14] ]
[00:01:14] [+] Should pass all flagged PS Script Analyzer rules 858ms
[00:01:14] [+] Should pass any recently-added, error-level PS Script Analyzer rules 52ms
[00:01:14] [+] Should not suppress any required PS Script Analyzer rules 41ms
[00:01:15] [+] Should pass all custom DSC Resource Kit PSSA rules 803ms

@mhendric
Copy link
Contributor

mhendric commented Feb 17, 2019

FYI, I opened #565 to track the PSSA issue above. Somehow I missed that file when I creates Issues for the rest of the problem files.

@mhendric
Copy link
Contributor

@PlagueHO or @johlju , would one of you be able to give this one a code review too? This one is big enough that it probably needs another sets of eyes on it. Thanks.

Copy link
Contributor Author

@tmeckel tmeckel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 1 of 2 files reviewed, 2 unresolved discussions (waiting on @mhendric)


Tests/Unit/MSFT_xDSCWebService.Tests.ps1, line 472 at r3 (raw file):

Previously, mhendric (Mike Hendrickson) wrote…

To be honest, I'm still a bit confused as to what the $testArguments script block was trying to accomplish in the first place. Having spent a lot of time looking at this code, do you think this particular MockWith buys us much? The $allowedArgs variable triggers the PSUseDeclaredVarsMoreThanAssignments script analyzer rule since it's not actually used until RunTime. If these two vars aren't actually doing much (other than confusing us), maybe they shouldn't be here...

After I changed the mocking and the assertions for it inside the unit tests I discovered that the method Get-IISAppCmdis never called in the currently implemented (unit) tests. You'll find Assert-MockCalled -Exactly -Times 0 -CommandName Get-IISAppCmd at every Itstatement. So I started to analyze the calling hierarchy inside *-TargetResource manually and after that I was very sure that the Get-IISAppCmdmust be called during the execution of the unit tests. So as you I'm a bit baffled now. And secondly, because Get-IISAppCmd is calling Get-Command internally I can revert back the changes to unit tests where I replaced the Get-Command mocking in favor of Get-IISAppCmd.

Although the implementation of MSFT_xDSCWebService is very robust even in the craziest machine setups (I even deployed and retracted a PullServer successfully on a machine where VisualStudio, IIS Express, SQLServer and SharePoint are installed simultaneously!) I would prefer to analyse this strange behavior with Get-IISAppCmd before we merge the PR.

@tmeckel
Copy link
Contributor Author

tmeckel commented Feb 18, 2019

Hey @tmeckel , I just noticed that this fixes all but one of the script analyzer errors in the Meta tests. Up to you if you want to fix that here or not, but if not, we'll need another PR for it at some point.

[00:01:09] Context MSFT_xDSCWebService.psm1
[00:01:09] [+] Should pass all error-level PS Script Analyzer rules 67ms
[00:01:13] [+] Should pass all required PS Script Analyzer rules 3.87s
[00:01:14] Flagged PSSA rule(s) did not pass.
[00:01:14] The following PSScriptAnalyzer rule 'PSDSCUseVerboseMessageInDSCResource' errors need to be fixed:
[00:01:14] MSFT_xDSCWebService.psm1 (Line 23): There is no call to Write-Verbose in DSC function 'Get-TargetResource'. If you are using Write-Verbose in a helper function, suppress this rule application.
[00:01:14] For instructions on how to run PSScriptAnalyzer on your own machine, please go to https://github.com/powershell/PSScriptAnalyzer
[00:01:14] Common Tests - Flagged Script Analyzer Rules will not fail unless you opt-in.
[00:01:14] To opt-in, create a '.MetaTestOptIn.json' at the root
[00:01:14] of the repo in the following format:
[00:01:14] [
[00:01:14] "Common Tests - Flagged Script Analyzer Rules"
[00:01:14] ]
[00:01:14] [+] Should pass all flagged PS Script Analyzer rules 858ms
[00:01:14] [+] Should pass any recently-added, error-level PS Script Analyzer rules 52ms
[00:01:14] [+] Should not suppress any required PS Script Analyzer rules 41ms
[00:01:15] [+] Should pass all custom DSC Resource Kit PSSA rules 803ms

Hey @mhendric I'll fix those issues on the current PR.

@tmeckel
Copy link
Contributor Author

tmeckel commented Feb 18, 2019

Hey @mhendric I changed the implementation of the unit tests. Now this looks much more reasonable, although the syntax (implementation) of the mock for Get-Command looks weird! But now I'm confident that the tests really do their job!

@tmeckel
Copy link
Contributor Author

tmeckel commented Feb 19, 2019

@mhendric I rebased the PR to the current origin/dev branch but still a hint about existing conflicts is displayed. If I should do another rebase lemme know. Secondly I fixed the PSSA issue #565. Hopefully we're finally on the finishing line for this PR! Oh .. do I have to adjust the CHANGELOG.md again because I fixed #565 and #528 as well in this PR?

Copy link
Contributor Author

@tmeckel tmeckel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 0 of 2 files reviewed, 2 unresolved discussions (waiting on @mhendric)


Tests/Unit/MSFT_xDSCWebService.Tests.ps1, line 472 at r3 (raw file):

Previously, mhendric (Mike Hendrickson) wrote…

Looking better! I'm still wondering what this code is trying to guard against though. It seems that it was trying to prevent the calling of AppCmd using non-pre-approved strings. Is that really a meaningful test though, and is it a scenario we really need to guard against? I feel like I'm missing something, but it just seems to me to be an arbitrary test that isn't actually useful.

If we do figure out the reason why this code is helpful, I think we should clearly document it using comments. Also, rather than having the MockWith create a ScriptBlock from the $testArguments string, I think we may be better off just putting this and $allowedArgs directly in the MockWith block, and not bother converting from string to script block. But again, if we can't figure out what purpose this code is serving, maybe we should just get rid of it.

Done.

Copy link
Contributor

@mhendric mhendric left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @tmeckel, sorry for the late response, been traveling all week. It probably would be good to update the CHANGELOG if you are now fixing other issues too. And your comments on Get-Command sound good. I've added one more comment on that below. Let me know what you think.

Reviewed 1 of 2 files at r7.
Reviewable status: 1 of 2 files reviewed, 2 unresolved discussions (waiting on @mhendric and @tmeckel)


Tests/Unit/MSFT_xDSCWebService.Tests.ps1, line 472 at r3 (raw file):

Previously, tmeckel (Thomas Meckel) wrote…

Done.

Sorry, I think I was a bit unclear with that last paragraph. So instead of generating a script block from strings which are super hard to read and which throw off the Script Analyzer, I was suggesting just moving this code directly into the MockWith like this. Making the $allowedArgs more readable would be a bonus too. Same for the other Mock later in the code. What do you think?

Mock -CommandName Get-Command -ParameterFilter {$Name -eq '.\appcmd.exe'} -MockWith {
    $allowedCallers = @(
        ([ScriptBlock]{('' -ne ((& (Get-IISAppCmd) list config -section:system.webServer/globalModules) -like "*$iisSelfSignedModuleName*"))}).ToString()
        ([ScriptBlock]{& (Get-IISAppCmd) install module /name:$iisSelfSignedModuleName /image:$destinationFilePath /add:false /lock:false}).ToString()
        ([ScriptBlock]{& (Get-IISAppCmd) add module /name:$iisSelfSignedModuleName /app.name:"$EndpointName/" $preConditionBitnessArgumentFor32BitInstall}).ToString()
        ([ScriptBlock]{& (Get-IISAppCmd) delete module /name:$iisSelfSignedModuleName  /app.name:"$EndpointName/"}).ToString()
    )

    if ($allowedCallers -notcontains ($MyInvocation.Line.Trim() -replace '\s+', ' ')) {
        throw "Mock test failed. Unexpected caller of Get-Command and appcmd.exe. [$line]"
    }
}

@mhendric
Copy link
Contributor

@tmeckel , also note that after you rebase, your change log entry is going to be under the 8.5.0.0 section, and will need to be moved to the Unreleased section. Thanks.

@tmeckel
Copy link
Contributor Author

tmeckel commented Feb 23, 2019

Hey @mhendric your proposal on restructuring the mock code for Get-Commandsounds good and yes I didn't understand what you wanted at first place. So I gonna rebase the PR over the weekend move the comments into the Unreleased section and add two comments that this PR also resolves two other issues. I'll get back to you as soon as I've done that.

Thomas Meckel added 15 commits February 23, 2019 22:53
…b module in MSFT_xDSCWebService. Changed the unit tests accordingly
…CWebService because of issues with Pester Mocking

* Updated Unit tests for  MSFT_xDSCWebService
…e is still used instead of Test-IISSelfSignedModuleInstalled
destination folder although the module is locked (loaded) by IIS already
* fixed issue 528
relied on environemnt variables
* changed Unit tests according to review
* added verbose messages to Get-TargetResource to satisfy PSSA rules
@tmeckel
Copy link
Contributor Author

tmeckel commented Feb 24, 2019

Hey @mhendric I changed the Get-Commandmock implementation as you proposed. I added a comment though into the code because a script block must be returned which will be executed from the calling code outof the DSC Resource. I had some strange errors when I directly copied your proposal which I had to anaylze and understood :-D ... Anyway I hope we can merge this PR finally into the dev branch. When this is done I can work on the other open issues related to xDSCWebService. Oh and I added comments to CHANGELOG.md in the unreleased section as required.

Copy link
Contributor

@mhendric mhendric left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Thanks for all the work here @tmeckel! Great job!

Reviewed 2 of 2 files at r8.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @mhendric and @tmeckel)


Tests/Unit/MSFT_xDSCWebService.Tests.ps1, line 472 at r3 (raw file):

Previously, mhendric (Mike Hendrickson) wrote…

Sorry, I think I was a bit unclear with that last paragraph. So instead of generating a script block from strings which are super hard to read and which throw off the Script Analyzer, I was suggesting just moving this code directly into the MockWith like this. Making the $allowedArgs more readable would be a bonus too. Same for the other Mock later in the code. What do you think?

Mock -CommandName Get-Command -ParameterFilter {$Name -eq '.\appcmd.exe'} -MockWith {
    $allowedCallers = @(
        ([ScriptBlock]{('' -ne ((& (Get-IISAppCmd) list config -section:system.webServer/globalModules) -like "*$iisSelfSignedModuleName*"))}).ToString()
        ([ScriptBlock]{& (Get-IISAppCmd) install module /name:$iisSelfSignedModuleName /image:$destinationFilePath /add:false /lock:false}).ToString()
        ([ScriptBlock]{& (Get-IISAppCmd) add module /name:$iisSelfSignedModuleName /app.name:"$EndpointName/" $preConditionBitnessArgumentFor32BitInstall}).ToString()
        ([ScriptBlock]{& (Get-IISAppCmd) delete module /name:$iisSelfSignedModuleName  /app.name:"$EndpointName/"}).ToString()
    )

    if ($allowedCallers -notcontains ($MyInvocation.Line.Trim() -replace '\s+', ' ')) {
        throw "Mock test failed. Unexpected caller of Get-Command and appcmd.exe. [$line]"
    }
}

Awesome. Thanks for adding detailed additional comments too!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting for code fix A review left open comments, and the pull request is waiting for changes to be pushed by the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

xDscWebService: Redeploy DSC Pull Server fails with error
3 participants