diff --git a/DSCResources/MSFT_xWebsite/MSFT_xWebsite.psm1 b/DSCResources/MSFT_xWebsite/MSFT_xWebsite.psm1 index 051960fda..e07ece514 100644 --- a/DSCResources/MSFT_xWebsite/MSFT_xWebsite.psm1 +++ b/DSCResources/MSFT_xWebsite/MSFT_xWebsite.psm1 @@ -62,7 +62,7 @@ data LocalizedData VerboseTestTargetFalseAuthenticationInfo = AuthenticationInfo for website "{0}" is not in the desired state. VerboseTestTargetFalseIISAutoStartProvider = AutoStartProvider for IIS is not in the desired state VerboseTestTargetFalseWebsiteAutoStartProvider = AutoStartProvider for website "{0}" is not in the desired state - VerboseTestTargetFalseLogPath = LogPath does match desired state on Website "{0}". + VerboseTestTargetFalseLogPath = LogPath does not match desired state on Website "{0}". VerboseTestTargetFalseLogFlags = LogFlags does not match desired state on Website "{0}". VerboseTestTargetFalseLogPeriod = LogPeriod does not match desired state on Website "{0}". VerboseTestTargetFalseLogTruncateSize = LogTruncateSize does not match desired state on Website "{0}". @@ -445,9 +445,8 @@ function Set-TargetResource # Update LogPath if required if ($PSBoundParameters.ContainsKey('LogPath') -and ` - ($LogPath -ne $website.logfile.LogPath)) + ($LogPath -ne $website.logfile.directory)) { - Write-Verbose -Message ($LocalizedData.VerboseSetTargetUpdateLogPath ` -f $Name) Set-ItemProperty -Path "IIS:\Sites\$Name" ` @@ -683,7 +682,7 @@ function Set-TargetResource # Update LogPath if required if ($PSBoundParameters.ContainsKey('LogPath') -and ` - ($LogPath -ne $website.logfile.LogPath)) + ($LogPath -ne $website.logfile.directory)) { Write-Verbose -Message ($LocalizedData.VerboseSetTargetUpdateLogPath ` @@ -995,7 +994,7 @@ function Test-TargetResource # Check LogPath if ($PSBoundParameters.ContainsKey('LogPath') -and ` - ($LogPath -ne $website.logfile.LogPath)) + ($LogPath -ne $website.logfile.directory)) { Write-Verbose -Message ($LocalizedData.VerboseTestTargetFalseLogPath ` -f $Name) diff --git a/README.md b/README.md index 42366f55a..cb6b526ae 100644 --- a/README.md +++ b/README.md @@ -216,6 +216,8 @@ Currently, only FastCgiModule is supported. ### Unreleased +* Log directory configuration on **xWebsite** used the logPath attribute instead of the directory attribute. Bugfix for #256. + ### 1.15.0.0 * Corrected name of AuthenticationInfo parameter in Readme.md. diff --git a/Tests/Unit/MSFT_xWebsite.Tests.ps1 b/Tests/Unit/MSFT_xWebsite.Tests.ps1 index 35d9d496e..9babe41f9 100644 --- a/Tests/Unit/MSFT_xWebsite.Tests.ps1 +++ b/Tests/Unit/MSFT_xWebsite.Tests.ps1 @@ -494,39 +494,52 @@ try } Context 'Check AutoStartProvider is different' { - Mock -CommandName Get-Website -MockWith {return $MockWebsite} + Mock -CommandName Get-Website -MockWith { return $MockWebsite } - $Result = Test-TargetResource -Ensure $MockParameters.Ensure ` + $result = Test-TargetResource -Ensure $MockParameters.Ensure ` -Name $MockParameters.Name ` -PhysicalPath $MockParameters.PhysicalPath ` -ServiceAutoStartProvider 'MockAutoStartProviderDifferent' ` -ApplicationType 'MockApplicationTypeDifferent' ` -Verbose:$VerbosePreference - It 'should return False' { - $Result | Should Be $false + It 'Should return False' { + $result | Should Be $false + } + } + + Context 'Check LogPath is equal' { + $MockLogOutput.directory = $MockParameters.LogPath + + Mock -CommandName Test-Path -MockWith { return $true } + + Mock -CommandName Get-Website -MockWith { return $MockWebsite } + + Mock -CommandName Get-WebConfigurationProperty ` + -MockWith { return $MockLogOutput.logExtFileFlags } + + $result = Test-TargetResource -Ensure $MockParameters.Ensure ` + -Name $MockParameters.Name ` + -PhysicalPath $MockParameters.PhysicalPath ` + -LogPath $MockParameters.LogPath ` + -Verbose:$VerbosePreference + + It 'Should return true' { + $result | Should be $true } } Context 'Check LogPath is different' { - $MockLogOutput = - @{ - directory = '%SystemDrive%\inetpub\logs\LogFiles' - logExtFileFlags = $MockParameters.LogFlags - logFormat = $MockParameters.LogFormat - period = $MockParameters.LogPeriod - truncateSize = $MockParameters.LogTruncateSize - localTimeRollover = $MockParameters.LoglocalTimeRollover - } + $MockLogOutput.directory = $MockParameters.LogPath - Mock -CommandName Test-Path -MockWith {Return $true} + Mock -CommandName Test-Path -MockWith { return $true } - Mock -CommandName Get-Website -MockWith {return $MockWebsite} + Mock -CommandName Get-Website -MockWith { return $MockWebsite } Mock -CommandName Get-WebConfigurationProperty ` - -MockWith {return $MockLogOutput.logExtFileFlags } + -MockWith { return $MockLogOutput.logExtFileFlags } - $Result = Test-TargetResource -Ensure $MockParameters.Ensure ` + $result = Test-TargetResource -Ensure $MockParameters.Ensure ` -Name $MockParameters.Name ` -PhysicalPath $MockParameters.PhysicalPath ` -LogPath 'C:\MockLogPath2' ` @@ -547,14 +560,14 @@ try localTimeRollover = $MockParameters.LoglocalTimeRollover } - Mock -CommandName Test-Path -MockWith {Return $true} + Mock -CommandName Test-Path -MockWith { return $true } - Mock -CommandName Get-Website -MockWith {return $MockWebsite} + Mock -CommandName Get-Website -MockWith { return $MockWebsite } Mock -CommandName Get-WebConfigurationProperty ` - -MockWith {return $MockLogOutput.logExtFileFlags } + -MockWith { return $MockLogOutput.logExtFileFlags } - $Result = Test-TargetResource -Ensure $MockParameters.Ensure ` + $result = Test-TargetResource -Ensure $MockParameters.Ensure ` -Name $MockParameters.Name ` -PhysicalPath $MockParameters.PhysicalPath ` -LogFlags 'Date','Time','ClientIP','UserName','ServerIP' ` @@ -997,6 +1010,146 @@ try } } + Context 'Website has unchanged logging directory' { + $MockWebsite = @{ + Name = 'MockName' + PhysicalPath = 'C:\NonExistent' + State = 'Started' + ApplicationPool = 'MockPool' + Bindings = @{Collection = @($MockWebBinding)} + EnabledProtocols = 'http' + ApplicationDefaults = $MockPreloadAndAutostartProviders + Count = 1 + LogFile = @{ + directory = 'C:\MockLogLocation' + logExtFileFlags = 'Date','Time','ClientIP','UserName','ServerIP','Method','UriStem','UriQuery','HttpStatus','Win32Status','TimeTaken','ServerPort','UserAgent','Referer','HttpSubStatus' + logFormat = $MockParameters.LogFormat + period = 'Daily' + truncateSize = '1048576' + localTimeRollover = 'False' + } + } + + Mock -CommandName Get-Website -MockWith { return $MockWebsite } + + Mock -CommandName Get-Command -MockWith { + return @{ + Parameters = @{ + Name = 'MockName' + } + } + } + + Mock -CommandName Test-WebsiteBinding -MockWith { return $false } + + Mock -CommandName Update-WebsiteBinding + + Mock -CommandName Set-ItemProperty + + Mock -CommandName Add-WebConfiguration + + Mock -CommandName Update-DefaultPage + + Mock -CommandName Confirm-UniqueServiceAutoStartProviders -MockWith { return $false } + + Mock -CommandName Set-Authentication + + Mock -CommandName Test-AuthenticationEnabled { return $true } ` + -ParameterFilter { ($Type -eq 'Anonymous') } + + Mock -CommandName Test-AuthenticationEnabled { return $false } ` + -ParameterFilter { ($Type -eq 'Basic') } + + Mock -CommandName Test-AuthenticationEnabled { return $false } ` + -ParameterFilter { ($Type -eq 'Digest') } + + Mock -CommandName Test-AuthenticationEnabled { return $false } ` + -ParameterFilter { ($Type -eq 'Windows') } + + $result = Set-TargetResource @MockParameters + + It 'Should call all the mocks' { + Assert-MockCalled -CommandName Test-WebsiteBinding -Exactly 1 + Assert-MockCalled -CommandName Update-WebsiteBinding -Exactly 1 + Assert-MockCalled -CommandName Set-ItemProperty -Exactly 8 + Assert-MockCalled -CommandName Set-ItemProperty -ParameterFilter { $Name -eq 'LogFile.directory' } -Exactly 0 + Assert-MockCalled -CommandName Add-WebConfiguration -Exactly 1 + Assert-MockCalled -CommandName Update-DefaultPage -Exactly 1 + Assert-MockCalled -CommandName Confirm-UniqueServiceAutoStartProviders -Exactly 1 + Assert-MockCalled -CommandName Set-Authentication -Exactly 4 + } + } + + Context 'Website has changed logging directory' { + $MockWebsite = @{ + Name = 'MockName' + PhysicalPath = 'C:\NonExistent' + State = 'Started' + ApplicationPool = 'MockPool' + Bindings = @{Collection = @($MockWebBinding)} + EnabledProtocols = 'http' + ApplicationDefaults = $MockPreloadAndAutostartProviders + Count = 1 + LogFile = @{ + directory = 'C:\Logs\MockLogLocation' + logExtFileFlags = 'Date','Time','ClientIP','UserName','ServerIP','Method','UriStem','UriQuery','HttpStatus','Win32Status','TimeTaken','ServerPort','UserAgent','Referer','HttpSubStatus' + logFormat = $MockParameters.LogFormat + period = 'Daily' + truncateSize = '1048576' + localTimeRollover = 'False' + } + } + + Mock -CommandName Get-Website -MockWith { return $MockWebsite } + + Mock -CommandName Get-Command -MockWith { + return @{ + Parameters = @{ + Name = 'MockName' + } + } + } + + Mock -CommandName Test-WebsiteBinding -MockWith { return $false } + + Mock -CommandName Update-WebsiteBinding + + Mock -CommandName Set-ItemProperty + + Mock -CommandName Add-WebConfiguration + + Mock -CommandName Update-DefaultPage + + Mock -CommandName Confirm-UniqueServiceAutoStartProviders -MockWith { return $false } + + Mock -CommandName Set-Authentication + + Mock -CommandName Test-AuthenticationEnabled { return $true } ` + -ParameterFilter { ($Type -eq 'Anonymous') } + + Mock -CommandName Test-AuthenticationEnabled { return $false } ` + -ParameterFilter { ($Type -eq 'Basic') } + + Mock -CommandName Test-AuthenticationEnabled { return $false } ` + -ParameterFilter { ($Type -eq 'Digest') } + + Mock -CommandName Test-AuthenticationEnabled { return $false } ` + -ParameterFilter { ($Type -eq 'Windows') } + + $result = Set-TargetResource @MockParameters + + It 'Should call all the mocks' { + Assert-MockCalled -CommandName Test-WebsiteBinding -Exactly 1 + Assert-MockCalled -CommandName Update-WebsiteBinding -Exactly 1 + Assert-MockCalled -CommandName Set-ItemProperty -Exactly 9 + Assert-MockCalled -CommandName Set-ItemProperty -ParameterFilter { $Name -eq 'LogFile.directory' } -Exactly 1 + Assert-MockCalled -CommandName Add-WebConfiguration -Exactly 1 + Assert-MockCalled -CommandName Update-DefaultPage -Exactly 1 + Assert-MockCalled -CommandName Confirm-UniqueServiceAutoStartProviders -Exactly 1 + Assert-MockCalled -CommandName Set-Authentication -Exactly 4 + } + } + Context 'New website cannot be started due to a binding conflict' { $MockWebsite = @{ Name = 'MockName'