Skip to content

Commit 5ea5a13

Browse files
authored
ADForestProperties: Add TombstoneLifetime Property (#549)
* ADForestProperties: Add TomstoneLifetime
1 parent 5dddc4b commit 5ea5a13

File tree

11 files changed

+858
-181
lines changed

11 files changed

+858
-181
lines changed

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,22 @@ For older change log history see the [historic changelog](HISTORIC_CHANGELOG.md)
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- ADForestProperties
13+
- Added TombstoneLifetime property ([issue #302](https://github.com/PowerShell/ActiveDirectoryDsc/issues/302)).
14+
- Added Integration tests ([issue #349](https://github.com/PowerShell/ActiveDirectoryDsc/issues/349)).
15+
16+
### Fixed
17+
18+
- ADForestProperties
19+
- Fixed ability to clear `ServicePrincipalNameSuffix` and `UserPrincipalNameSuffix` ([issue #548](https://github.com/PowerShell/ActiveDirectoryDsc/issues/548)).
20+
21+
### Changed
22+
23+
- ADForestProperties
24+
- Refactored unit tests.
25+
1026
## [5.0.0] - 2020-01-14
1127

1228
### Added
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
<#
2+
.SYNOPSIS
3+
Pester integration test for the ADForestProperties Resource of the ActiveDirectoryDsc Module
4+
5+
.DESCRIPTION
6+
Verbose/Debug output can be set by running Invoke-pester -Script @{Path=<TestPath>;Parameters=@{Verbose=$true;Debug=$true}}
7+
#>
8+
9+
[CmdletBinding()]
10+
param ()
11+
12+
Set-StrictMode -Version 1.0
13+
14+
$script:dscModuleName = 'ActiveDirectoryDsc'
15+
$script:dscResourceFriendlyName = 'ADForestProperties'
16+
$script:dscResourceName = "MSFT_$($script:dscResourceFriendlyName)"
17+
18+
try
19+
{
20+
Import-Module -Name DscResource.Test -Force -ErrorAction 'Stop' -Verbose:$false
21+
}
22+
catch [System.IO.FileNotFoundException]
23+
{
24+
throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -Tasks build" first.'
25+
}
26+
27+
$script:testEnvironment = Initialize-TestEnvironment `
28+
-DSCModuleName $script:dscModuleName `
29+
-DSCResourceName $script:dscResourceName `
30+
-ResourceType 'Mof' `
31+
-TestType 'Integration'
32+
33+
try
34+
{
35+
$configFile = Join-Path -Path $PSScriptRoot -ChildPath "$($script:dscResourceName).config.ps1"
36+
. $configFile
37+
38+
Describe "$($script:dscResourceName)_Integration" {
39+
BeforeAll {
40+
$resourceId = "[$($script:dscResourceFriendlyName)]Integration_Test"
41+
}
42+
43+
foreach ($testName in $ConfigurationData.AllNodes.Tests.Keys )
44+
{
45+
$configurationName = "$($script:dscResourceName)_$($testName)_Config"
46+
47+
Context ('When using configuration {0}' -f $configurationName) {
48+
It 'Should compile and apply the MOF without throwing' {
49+
{
50+
$configurationParameters = @{
51+
OutputPath = $TestDrive
52+
# The variable $ConfigurationData was dot-sourced above.
53+
ConfigurationData = $ConfigurationData
54+
}
55+
56+
& $configurationName @configurationParameters
57+
58+
$startDscConfigurationParameters = @{
59+
Path = $TestDrive
60+
ComputerName = 'localhost'
61+
Wait = $true
62+
Force = $true
63+
ErrorAction = 'Stop'
64+
}
65+
66+
Start-DscConfiguration @startDscConfigurationParameters
67+
} | Should -Not -Throw
68+
}
69+
70+
It 'Should be able to call Get-DscConfiguration without throwing' {
71+
{
72+
$script:currentConfiguration = Get-DscConfiguration -ErrorAction Stop
73+
} | Should -Not -Throw
74+
}
75+
76+
It 'Should have set the resource and all the parameters should match' {
77+
$resourceCurrentState = $script:currentConfiguration | Where-Object -FilterScript {
78+
$_.ConfigurationName -eq $configurationName `
79+
-and $_.ResourceId -eq $resourceId
80+
}
81+
82+
foreach ($property in $ConfigurationData.AllNodes.Tests.$testName.Keys)
83+
{
84+
$resourceCurrentState.$property | Should -Be $ConfigurationData.AllNodes.Tests.$testName.$property
85+
}
86+
}
87+
88+
It 'Should return $true when Test-DscConfiguration is run' {
89+
Test-DscConfiguration | Should -Be 'True'
90+
}
91+
}
92+
}
93+
94+
$configurationName = "$($script:dscResourceName)_RestoreDefaultValues_Config"
95+
96+
Context ('When using configuration {0}' -f $configurationName) {
97+
It 'Should compile and apply the MOF without throwing' {
98+
{
99+
$configurationParameters = @{
100+
OutputPath = $TestDrive
101+
# The variable $ConfigurationData was dot-sourced above.
102+
ConfigurationData = $ConfigurationData
103+
}
104+
105+
& $configurationName @configurationParameters
106+
107+
$startDscConfigurationParameters = @{
108+
Path = $TestDrive
109+
ComputerName = 'localhost'
110+
Wait = $true
111+
Force = $true
112+
ErrorAction = 'Stop'
113+
}
114+
115+
Start-DscConfiguration @startDscConfigurationParameters
116+
} | Should -Not -Throw
117+
}
118+
119+
It 'Should be able to call Get-DscConfiguration without throwing' {
120+
{
121+
$script:currentConfiguration = Get-DscConfiguration -ErrorAction Stop
122+
} | Should -Not -Throw
123+
}
124+
125+
It 'Should have set the resource and all the parameters should match' {
126+
$resourceCurrentState = $script:currentConfiguration | Where-Object -FilterScript {
127+
$_.ConfigurationName -eq $configurationName `
128+
-and $_.ResourceId -eq $resourceId
129+
}
130+
131+
foreach ($property in $ConfigurationData.Default.Keys)
132+
{
133+
$resourceCurrentState.$property | Should -Be $ConfigurationData.AllNodes.Default.$property
134+
}
135+
}
136+
137+
It 'Should return $true when Test-DscConfiguration is run' {
138+
Test-DscConfiguration | Should -Be 'True'
139+
}
140+
}
141+
}
142+
}
143+
finally
144+
{
145+
#region FOOTER
146+
Restore-TestEnvironment -TestEnvironment $script:testEnvironment
147+
#endregion
148+
}
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
#region HEADER
2+
# Integration Test Config Template Version: 1.2.0
3+
#endregion
4+
5+
$configFile = [System.IO.Path]::ChangeExtension($MyInvocation.MyCommand.Path, 'json')
6+
if (Test-Path -Path $configFile)
7+
{
8+
<#
9+
Allows reading the configuration data from a JSON file, for real testing
10+
scenarios outside of the CI.
11+
#>
12+
$ConfigurationData = Get-Content -Path $configFile | ConvertFrom-Json
13+
}
14+
else
15+
{
16+
$currentDomainController = Get-ADDomainController
17+
$forestName = $currentDomainController.Forest
18+
19+
$ConfigurationData = @{
20+
AllNodes = @(
21+
@{
22+
NodeName = 'localhost'
23+
CertificateFile = $env:DscPublicCertificatePath
24+
ForestName = $forestName
25+
Tests = [Ordered]@{
26+
SetPropertyValues = @{
27+
TombstoneLifetime = 200
28+
ServicePrincipalNameSuffix = 'fabrikam.com'
29+
UserPrincipalNameSuffix = 'fabrikam.com'
30+
}
31+
SetAddProperties = @{
32+
ServicePrincipalNameSuffixToAdd = 'test.com'
33+
UserPrincipalNameSuffixToAdd = 'test.com'
34+
}
35+
SetRemoveProperties = @{
36+
ServicePrincipalNameSuffixToRemove = 'test.com'
37+
UserPrincipalNameSuffixToRemove = 'test.com'
38+
}
39+
}
40+
Default = @{
41+
TombstoneLifetime = 180
42+
ServicePrincipalNameSuffix = ''
43+
UserPrincipalNameSuffix = ''
44+
}
45+
}
46+
)
47+
}
48+
}
49+
50+
<#
51+
.SYNOPSIS
52+
Sets the supported property values.
53+
#>
54+
Configuration MSFT_ADForestProperties_SetPropertyValues_Config
55+
{
56+
Import-DscResource -ModuleName 'ActiveDirectoryDsc'
57+
58+
$testName = 'SetPropertyValues'
59+
60+
node $AllNodes.NodeName
61+
{
62+
ADForestProperties 'Integration_Test'
63+
{
64+
ForestName = $Node.ForestName
65+
TombstoneLifetime = $Node.Tests.$testName.TombstoneLifetime
66+
ServicePrincipalNameSuffix = $Node.Tests.$testName.ServicePrincipalNameSuffix
67+
UserPrincipalNameSuffix = $Node.Tests.$testName.UserPrincipalNameSuffix
68+
}
69+
}
70+
}
71+
72+
<#
73+
.SYNOPSIS
74+
Sets the SPN/UPN suffix properties using the 'add' parameters.
75+
#>
76+
Configuration MSFT_ADForestProperties_SetAddProperties_Config
77+
{
78+
Import-DscResource -ModuleName 'ActiveDirectoryDsc'
79+
80+
$testName = 'SetAddProperties'
81+
82+
node $AllNodes.NodeName
83+
{
84+
ADForestProperties 'Integration_Test'
85+
{
86+
ForestName = $Node.ForestName
87+
ServicePrincipalNameSuffixToAdd = $Node.Tests.$testName.ServicePrincipalNameSuffixToAdd
88+
UserPrincipalNameSuffixToAdd = $Node.Tests.$testName.UserPrincipalNameSuffixToAdd
89+
}
90+
}
91+
}
92+
93+
<#
94+
.SYNOPSIS
95+
Sets the SPN/UPN suffix properties using the 'remove' parameters.
96+
#>
97+
Configuration MSFT_ADForestProperties_SetRemoveProperties_Config
98+
{
99+
Import-DscResource -ModuleName 'ActiveDirectoryDsc'
100+
101+
$testName = 'SetRemoveProperties'
102+
103+
node $AllNodes.NodeName
104+
{
105+
ADForestProperties 'Integration_Test'
106+
{
107+
ForestName = $Node.ForestName
108+
ServicePrincipalNameSuffixToRemove = $Node.Tests.$testName.ServicePrincipalNameSuffixToRemove
109+
UserPrincipalNameSuffixToRemove = $Node.Tests.$testName.UserPrincipalNameSuffixToRemove
110+
}
111+
}
112+
}
113+
114+
<#
115+
.SYNOPSIS
116+
Restore domain controller properties to the default values.
117+
#>
118+
Configuration MSFT_ADForestProperties_RestoreDefaultValues_Config
119+
{
120+
Import-DscResource -ModuleName 'ActiveDirectoryDsc'
121+
122+
node $AllNodes.NodeName
123+
{
124+
ADForestProperties 'Integration_Test'
125+
{
126+
ForestName = $Node.ForestName
127+
TombstoneLifetime = $Node.Default.TombstoneLifetime
128+
ServicePrincipalNameSuffix = $Node.Default.ServicePrincipalNameSuffix
129+
UserPrincipalNameSuffix = $Node.Default.UserPrincipalNameSuffix
130+
}
131+
}
132+
}

0 commit comments

Comments
 (0)