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

BREAKING CHANGE: ADDomain: Change Domain Install Tracking File to NetLogon Registry Test and Refactor #566

Merged
merged 15 commits into from
Feb 12, 2020
Merged
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ For older change log history see the [historic changelog](HISTORIC_CHANGELOG.md)
- ActiveDirectoryDsc
- Updated Azure Pipeline Windows image ([issue #551](https://github.com/dsccommunity/ActiveDirectoryDsc/issues/551)).
- Updated license copyright ([issue #550](https://github.com/dsccommunity/ActiveDirectoryDsc/issues/550)).
- ADDomain
- Change Domain Install Tracking File to NetLogon Registry Test and Refactor. ([issue #560](https://github.com/dsccommunity/ActiveDirectoryDsc/issues/560)).
- ADForestProperties
- Refactored unit tests.

Expand Down
112 changes: 112 additions & 0 deletions Tests/Integration/MSFT_ADDomain.Child.Integration.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<#
.SYNOPSIS
Pester integration test for the ADDomain Resource of the ActiveDirectoryDsc Module
This Subtest creates a child domain in an existing forest

.DESCRIPTION
Verbose/Debug output can be set by running:

Invoke-pester -Script @{Path='.\MSFT_ADDomain.Child.Integration.Tests.ps1';Parameters=@{Verbose=$true;Debug=$true}}
#>

[CmdletBinding()]
param ()

Set-StrictMode -Version 1.0

$script:dscModuleName = 'ActiveDirectoryDsc'
$script:dscResourceFriendlyName = 'ADDomain'
$script:dscResourceName = "MSFT_$($script:dscResourceFriendlyName)"
$script:subTestName = 'Child'

try
{
Import-Module -Name DscResource.Test -Force -ErrorAction 'Stop'
}
catch [System.IO.FileNotFoundException]
{
throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -Tasks build" first.'
}

$script:testEnvironment = Initialize-TestEnvironment `
-DSCModuleName $script:dscModuleName `
-DSCResourceName $script:dscResourceName `
-ResourceType 'Mof' `
-TestType 'Integration'

try
{
$configFile = Join-Path -Path $PSScriptRoot -ChildPath "$($script:dscResourceName).$($script:subTestName).config.ps1"
. $configFile

Describe "$($script:dscResourceName).$($script:subTestName)_Integration" {
BeforeAll {
$resourceId = "[$($script:dscResourceFriendlyName)]Integration_Test"
}


foreach ($testName in $ConfigurationData.AllNodes.Tests.Keys )
{
$configurationName = "$($script:dscResourceName)_$($testName)_Config"

Context ('When using configuration {0}' -f $configurationName) {
It 'Should compile and apply the MOF without throwing' {
{
$configurationParameters = @{
OutputPath = $TestDrive
# The variable $ConfigurationData was dot-sourced above.
ConfigurationData = $ConfigurationData
}

& $configurationName @configurationParameters

$startDscConfigurationParameters = @{
Path = $TestDrive
ComputerName = 'localhost'
Wait = $true
Force = $true
ErrorAction = 'Stop'
}

Start-DscConfiguration @startDscConfigurationParameters
} | Should -Not -Throw
}

$DscConfigurationStatus = Get-DscConfigurationStatus
if ($DscConfigurationStatus.RebootRequested)
{
Write-Warning 'A Reboot has been requested by the DSC. Please reboot then re-run the test'
Return
}

It 'Should be able to call Get-DscConfiguration without throwing' {
{
$script:currentConfiguration = Get-DscConfiguration -ErrorAction Stop
} | Should -Not -Throw
}

$resourceCurrentState = $script:currentConfiguration | Where-Object -FilterScript {
$_.ConfigurationName -eq $configurationName `
-and $_.ResourceId -eq $resourceId
}

foreach ($property in $ConfigurationData.AllNodes.Tests.$testName.Keys)
{
It "Should have set the correct $property property" {
$resourceCurrentState.$property | Should -Be $ConfigurationData.AllNodes.Tests.$testName.$property
}
}

It 'Should return $true when Test-DscConfiguration is run' {
Test-DscConfiguration | Should -Be 'True'
}
}
}
}
}
finally
{
#region FOOTER
Restore-TestEnvironment -TestEnvironment $script:testEnvironment
#endregion
}
100 changes: 100 additions & 0 deletions Tests/Integration/MSFT_ADDomain.Child.config.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#region HEADER
# Integration Test Config Template Version: 1.2.0
#endregion

$configFile = [System.IO.Path]::ChangeExtension($MyInvocation.MyCommand.Path, 'json')
if (Test-Path -Path $configFile)
{
<#
Allows reading the configuration data from a JSON file, for real testing
scenarios outside of the CI.
#>
$ConfigurationData = Get-Content -Path $configFile | ConvertFrom-Json
}
else
{
$ConfigurationData = @{
AllNodes = @(
@{
NodeName = 'localhost'
CertificateFile = $env:DscPublicCertificatePath
CredentialUserName = '[email protected]'
CredentialPassword = 'password'
SafeModePassword = 'SafemodePassword@1'
Tests = [Ordered]@{
FeatureInstall = @{ }
ForestChildDomain = @{
DomainName = 'child'
ParentDomainName = 'contoso.com'
DomainNetbiosName = 'CHILD-CONTOSO'
DatabasePath = 'C:\NTDS'
LogPath = 'C:\NTDS'
SysvolPath = 'C:\SysVol'
DomainMode = 'WinThreshold'
}
}
}
)
}
}

<#
.SYNOPSIS
Initialise Config
#>
Configuration MSFT_ADDomain_FeatureInstall_Config
{
Import-DscResource -ModuleName 'PSDesiredStateConfiguration'

$testName = 'FeatureInstall'

node $AllNodes.NodeName
{
WindowsFeature 'ADDS'
{
Name = 'AD-Domain-Services'
}
}
}

<#
.SYNOPSIS
Initialise Config
#>
Configuration MSFT_ADDomain_ForestChildDomain_Config
{
Import-DscResource -ModuleName 'ActiveDirectoryDsc'

$testName = 'ForestChildDomain'

node $AllNodes.NodeName
{
$SecureCredentialPassword = ConvertTo-SecureString `
-String $Node.CredentialPassword `
-AsPlainText -Force

$Credential = [System.Management.Automation.PSCredential]::new(
$Node.CredentialUserName,
$SecureCredentialPassword
)

$SafeModePassword = ConvertTo-SecureString `
-String $Node.SafeModePassword `
-AsPlainText -Force

$SafemodeCredential = [System.Management.Automation.PSCredential]::new('n/a', $SafemodePassword)

ADDomain Integration_Test
{
DomainName = $Node.Tests.$testName.DomainName
ParentDomainName = $Node.Tests.$testName.ParentDomainName
Credential = $Credential
SafemodeAdministratorPassword = $SafeModeCredential
DomainNetbiosName = $Node.Tests.$testName.DomainNetbiosName
DatabasePath = $Node.Tests.$testName.DatabasePath
LogPath = $Node.Tests.$testName.LogPath
SysvolPath = $Node.Tests.$testName.SysvolPath
DomainMode = $Node.Tests.$testName.DomainMode
}
}
}
112 changes: 112 additions & 0 deletions Tests/Integration/MSFT_ADDomain.Root.Integration.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<#
.SYNOPSIS
Pester integration test for the ADDomain Resource of the ActiveDirectoryDsc Module
This Subtest creates a root domain in a new forest

.DESCRIPTION
Verbose/Debug output can be set by running:

Invoke-pester -Script @{Path='.\MSFT_ADDomain.Root.Integration.Tests.ps1';Parameters=@{Verbose=$true;Debug=$true}}
#>

[CmdletBinding()]
param ()

Set-StrictMode -Version 1.0

$script:dscModuleName = 'ActiveDirectoryDsc'
$script:dscResourceFriendlyName = 'ADDomain'
$script:dscResourceName = "MSFT_$($script:dscResourceFriendlyName)"
$script:subTestName = 'Root'

try
{
Import-Module -Name DscResource.Test -Force -ErrorAction 'Stop'
}
catch [System.IO.FileNotFoundException]
{
throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -Tasks build" first.'
}

$script:testEnvironment = Initialize-TestEnvironment `
-DSCModuleName $script:dscModuleName `
-DSCResourceName $script:dscResourceName `
-ResourceType 'Mof' `
-TestType 'Integration'

try
{
$configFile = Join-Path -Path $PSScriptRoot -ChildPath "$($script:dscResourceName).$($script:subTestName).config.ps1"
. $configFile

Describe "$($script:dscResourceName).$($script:subTestName)_Integration" {
BeforeAll {
$resourceId = "[$($script:dscResourceFriendlyName)]Integration_Test"
}


foreach ($testName in $ConfigurationData.AllNodes.Tests.Keys )
{
$configurationName = "$($script:dscResourceName)_$($testName)_Config"

Context ('When using configuration {0}' -f $configurationName) {
It 'Should compile and apply the MOF without throwing' {
{
$configurationParameters = @{
OutputPath = $TestDrive
# The variable $ConfigurationData was dot-sourced above.
ConfigurationData = $ConfigurationData
}

& $configurationName @configurationParameters

$startDscConfigurationParameters = @{
Path = $TestDrive
ComputerName = 'localhost'
Wait = $true
Force = $true
ErrorAction = 'Stop'
}

Start-DscConfiguration @startDscConfigurationParameters
} | Should -Not -Throw
}

$DscConfigurationStatus = Get-DscConfigurationStatus
if ($DscConfigurationStatus.RebootRequested)
{
Write-Warning 'A Reboot has been requested by the DSC. Please reboot then re-run the test'
Return
}

It 'Should be able to call Get-DscConfiguration without throwing' {
{
$script:currentConfiguration = Get-DscConfiguration -ErrorAction Stop
} | Should -Not -Throw
}

$resourceCurrentState = $script:currentConfiguration | Where-Object -FilterScript {
$_.ConfigurationName -eq $configurationName `
-and $_.ResourceId -eq $resourceId
}

foreach ($property in $ConfigurationData.AllNodes.Tests.$testName.Keys)
{
It "Should have set the correct $property property" {
$resourceCurrentState.$property | Should -Be $ConfigurationData.AllNodes.Tests.$testName.$property
}
}

It 'Should return $true when Test-DscConfiguration is run' {
Test-DscConfiguration | Should -Be 'True'
}
}
}
}
}
finally
{
#region FOOTER
Restore-TestEnvironment -TestEnvironment $script:testEnvironment
#endregion
}
Loading