-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BREAKING CHANGE: ADDomain: Change Domain Install Tracking File to Net…
…Logon Registry Test and Refactor (#566) * Refactor ADDomain Resource and Tests * Update ADDomain Example * Change Minimum PowerShellVersion to 5.0 * Add integration tests * Improve Credential parameter description * Increase markdownlint MD013 line length to 120
- Loading branch information
1 parent
dc20308
commit 856f028
Showing
13 changed files
with
1,031 additions
and
866 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
Tests/Integration/MSFT_ADDomain.Child.Integration.Tests.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} |
Oops, something went wrong.