Skip to content

Commit

Permalink
Return valid path values with Get-TargetResource
Browse files Browse the repository at this point in the history
  • Loading branch information
claudiospizzi committed Oct 16, 2016
1 parent 7e96a0f commit 12c850c
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
56 changes: 44 additions & 12 deletions Tests/Unit/MSFT_xADDomainController.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down

0 comments on commit 12c850c

Please sign in to comment.