Skip to content

Commit

Permalink
Merge pull request #257 from remcoeissing/issue_256_logging
Browse files Browse the repository at this point in the history
Changed xWebsite LogPath to directory attribute. Fixes #256
  • Loading branch information
mbreakey3 authored Nov 15, 2016
2 parents c3c1293 + e08772c commit cf9b195
Show file tree
Hide file tree
Showing 3 changed files with 180 additions and 26 deletions.
9 changes: 4 additions & 5 deletions DSCResources/MSFT_xWebsite/MSFT_xWebsite.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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}".
Expand Down Expand Up @@ -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" `
Expand Down Expand Up @@ -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 `
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
195 changes: 174 additions & 21 deletions Tests/Unit/MSFT_xWebsite.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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' `
Expand All @@ -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' `
Expand Down Expand Up @@ -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'
Expand Down

0 comments on commit cf9b195

Please sign in to comment.