From 12c850c16ae647b4994f95aff968e96fe9b8d0c7 Mon Sep 17 00:00:00 2001 From: Claudio Spizzi Date: Mon, 17 Oct 2016 00:29:31 +0200 Subject: [PATCH] Return valid path values with Get-TargetResource --- .../MSFT_xADDomainController.psm1 | 11 +++- Tests/Unit/MSFT_xADDomainController.Tests.ps1 | 56 +++++++++++++++---- 2 files changed, 53 insertions(+), 14 deletions(-) diff --git a/DSCResources/MSFT_xADDomainController/MSFT_xADDomainController.psm1 b/DSCResources/MSFT_xADDomainController/MSFT_xADDomainController.psm1 index a80abde74..985909cec 100644 --- a/DSCResources/MSFT_xADDomainController/MSFT_xADDomainController.psm1 +++ b/DSCResources/MSFT_xADDomainController/MSFT_xADDomainController.psm1 @@ -45,8 +45,15 @@ function Get-TargetResource if ($dc.Domain -eq $DomainName) { Write-Verbose -Message "Current node '$($dc.Name)' is already a domain controller for domain '$($dc.Domain)'." - $returnValue.Ensure = $true - $returnValue.SiteName = $dc.Site + + $serviceNTDS = Get-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Services\NTDS\Parameters' + $serviceNETLOGON = Get-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Services\Netlogon\Parameters' + + $returnValue.Ensure = $true + $returnValue.DatabasePath = $serviceNTDS.'DSA Working Directory' + $returnValue.LogPath = $serviceNTDS.'Database log files path' + $returnValue.SysvolPath = $serviceNETLOGON.SysVol -replace '\\sysvol$', '' + $returnValue.SiteName = $dc.Site } } catch diff --git a/Tests/Unit/MSFT_xADDomainController.Tests.ps1 b/Tests/Unit/MSFT_xADDomainController.Tests.ps1 index 15234a7a4..891328cd1 100644 --- a/Tests/Unit/MSFT_xADDomainController.Tests.ps1 +++ b/Tests/Unit/MSFT_xADDomainController.Tests.ps1 @@ -23,10 +23,13 @@ $TestEnvironment = Initialize-TestEnvironment ` try { #region Pester Test Initialization - $correctSiteName = 'PresentSite' - $incorrectSiteName = 'IncorrectSite' - $correctDomainName = 'present.com' + $correctDomainName = 'present.com' $testAdminCredential = [System.Management.Automation.PSCredential]::Empty + $correctDatabasePath = 'C:\Windows\NTDS' + $correctLogPath = 'C:\Windows\NTDS' + $correctSysvolPath = 'C:\Windows\SYSVOL' + $correctSiteName = 'PresentSite' + $incorrectSiteName = 'IncorrectSite' $testDefaultParams = @{ DomainAdministratorCredential = $testAdminCredential @@ -56,17 +59,43 @@ try #region Function Get-TargetResource Describe -Tag 'xADDomainController' "$($Script:DSCResourceName)\Get-TargetResource" { - It 'Returns current "SiteName"' { - Mock Get-ADDomain { return $true } @commonMockParams - Mock Get-ADDomainController { - return $stubDomainController = @{ - Site = 'PresentSite' - Domain = 'present.com' - } - } @commonMockParams - $result = Get-TargetResource @testDefaultParams -DomainName $correctDomainName -SiteName $correctSiteName + Mock Get-ADDomain { return $true } @commonMockParams + Mock Get-ADDomainController { + return $stubDomainController = @{ + Site = 'PresentSite' + Domain = 'present.com' + } + } @commonMockParams + Mock Get-ItemProperty -ParameterFilter { $Path -eq 'HKLM:\SYSTEM\CurrentControlSet\Services\NTDS\Parameters' } { + return @{ + 'Database log files path' = 'C:\Windows\NTDS' + 'DSA Working Directory' = 'C:\Windows\NTDS' + } + } @commonMockParams + Mock Get-ItemProperty -ParameterFilter { $Path -eq 'HKLM:\SYSTEM\CurrentControlSet\Services\Netlogon\Parameters' } { + return @{ + 'SysVol' = 'C:\Windows\SYSVOL\sysvol' + } + } @commonMockParams + + It 'Returns current "DatabasePath"' { + $result = Get-TargetResource @testDefaultParams -DomainName $correctDomainName + $result.DatabasePath | Should Be $correctDatabasePath + } + + It 'Returns current "LogPath"' { + $result = Get-TargetResource @testDefaultParams -DomainName $correctDomainName + $result.LogPath | Should Be $correctLogPath + } + It 'Returns current "SysvolPath"' { + $result = Get-TargetResource @testDefaultParams -DomainName $correctDomainName + $result.SysvolPath | Should Be $correctSysvolPath + } + + It 'Returns current "SiteName"' { + $result = Get-TargetResource @testDefaultParams -DomainName $correctDomainName $result.SiteName | Should Be $correctSiteName } } @@ -98,6 +127,8 @@ try Mock Get-ADDomain { return $true } Mock Get-ADDomainController { return $stubDomainController } Mock Test-ADReplicationSite { return $true } + Mock Get-ItemProperty { return @{} } + $result = Test-TargetResource @testDefaultParams -DomainName $correctDomainName -SiteName $correctSiteName $result | Should Be $false @@ -113,6 +144,7 @@ try Mock Get-ADDomain { return $true } Mock Get-ADDomainController { return $stubDomainController } Mock Test-ADReplicationSite { return $true } + Mock Get-ItemProperty { return @{} } $result = Test-TargetResource @testDefaultParams -DomainName $correctDomainName -SiteName $correctSiteName