Skip to content

Commit

Permalink
ADForestProperties: Add TombstoneLifetime Property (dsccommunity#549)
Browse files Browse the repository at this point in the history
* ADForestProperties: Add TomstoneLifetime
  • Loading branch information
X-Guardian authored Jan 20, 2020
1 parent 5dddc4b commit 5ea5a13
Show file tree
Hide file tree
Showing 11 changed files with 858 additions and 181 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,22 @@ For older change log history see the [historic changelog](HISTORIC_CHANGELOG.md)

## [Unreleased]

### Added

- ADForestProperties
- Added TombstoneLifetime property ([issue #302](https://github.com/PowerShell/ActiveDirectoryDsc/issues/302)).
- Added Integration tests ([issue #349](https://github.com/PowerShell/ActiveDirectoryDsc/issues/349)).

### Fixed

- ADForestProperties
- Fixed ability to clear `ServicePrincipalNameSuffix` and `UserPrincipalNameSuffix` ([issue #548](https://github.com/PowerShell/ActiveDirectoryDsc/issues/548)).

### Changed

- ADForestProperties
- Refactored unit tests.

## [5.0.0] - 2020-01-14

### Added
Expand Down
148 changes: 148 additions & 0 deletions Tests/Integration/MSFT_ADForestProperties.Integration.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
<#
.SYNOPSIS
Pester integration test for the ADForestProperties Resource of the ActiveDirectoryDsc Module
.DESCRIPTION
Verbose/Debug output can be set by running Invoke-pester -Script @{Path=<TestPath>;Parameters=@{Verbose=$true;Debug=$true}}
#>

[CmdletBinding()]
param ()

Set-StrictMode -Version 1.0

$script:dscModuleName = 'ActiveDirectoryDsc'
$script:dscResourceFriendlyName = 'ADForestProperties'
$script:dscResourceName = "MSFT_$($script:dscResourceFriendlyName)"

try
{
Import-Module -Name DscResource.Test -Force -ErrorAction 'Stop' -Verbose:$false
}
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).config.ps1"
. $configFile

Describe "$($script:dscResourceName)_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
}

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

It 'Should have set the resource and all the parameters should match' {
$resourceCurrentState = $script:currentConfiguration | Where-Object -FilterScript {
$_.ConfigurationName -eq $configurationName `
-and $_.ResourceId -eq $resourceId
}

foreach ($property in $ConfigurationData.AllNodes.Tests.$testName.Keys)
{
$resourceCurrentState.$property | Should -Be $ConfigurationData.AllNodes.Tests.$testName.$property
}
}

It 'Should return $true when Test-DscConfiguration is run' {
Test-DscConfiguration | Should -Be 'True'
}
}
}

$configurationName = "$($script:dscResourceName)_RestoreDefaultValues_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
}

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

It 'Should have set the resource and all the parameters should match' {
$resourceCurrentState = $script:currentConfiguration | Where-Object -FilterScript {
$_.ConfigurationName -eq $configurationName `
-and $_.ResourceId -eq $resourceId
}

foreach ($property in $ConfigurationData.Default.Keys)
{
$resourceCurrentState.$property | Should -Be $ConfigurationData.AllNodes.Default.$property
}
}

It 'Should return $true when Test-DscConfiguration is run' {
Test-DscConfiguration | Should -Be 'True'
}
}
}
}
finally
{
#region FOOTER
Restore-TestEnvironment -TestEnvironment $script:testEnvironment
#endregion
}
132 changes: 132 additions & 0 deletions Tests/Integration/MSFT_ADForestProperties.config.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
#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
{
$currentDomainController = Get-ADDomainController
$forestName = $currentDomainController.Forest

$ConfigurationData = @{
AllNodes = @(
@{
NodeName = 'localhost'
CertificateFile = $env:DscPublicCertificatePath
ForestName = $forestName
Tests = [Ordered]@{
SetPropertyValues = @{
TombstoneLifetime = 200
ServicePrincipalNameSuffix = 'fabrikam.com'
UserPrincipalNameSuffix = 'fabrikam.com'
}
SetAddProperties = @{
ServicePrincipalNameSuffixToAdd = 'test.com'
UserPrincipalNameSuffixToAdd = 'test.com'
}
SetRemoveProperties = @{
ServicePrincipalNameSuffixToRemove = 'test.com'
UserPrincipalNameSuffixToRemove = 'test.com'
}
}
Default = @{
TombstoneLifetime = 180
ServicePrincipalNameSuffix = ''
UserPrincipalNameSuffix = ''
}
}
)
}
}

<#
.SYNOPSIS
Sets the supported property values.
#>
Configuration MSFT_ADForestProperties_SetPropertyValues_Config
{
Import-DscResource -ModuleName 'ActiveDirectoryDsc'

$testName = 'SetPropertyValues'

node $AllNodes.NodeName
{
ADForestProperties 'Integration_Test'
{
ForestName = $Node.ForestName
TombstoneLifetime = $Node.Tests.$testName.TombstoneLifetime
ServicePrincipalNameSuffix = $Node.Tests.$testName.ServicePrincipalNameSuffix
UserPrincipalNameSuffix = $Node.Tests.$testName.UserPrincipalNameSuffix
}
}
}

<#
.SYNOPSIS
Sets the SPN/UPN suffix properties using the 'add' parameters.
#>
Configuration MSFT_ADForestProperties_SetAddProperties_Config
{
Import-DscResource -ModuleName 'ActiveDirectoryDsc'

$testName = 'SetAddProperties'

node $AllNodes.NodeName
{
ADForestProperties 'Integration_Test'
{
ForestName = $Node.ForestName
ServicePrincipalNameSuffixToAdd = $Node.Tests.$testName.ServicePrincipalNameSuffixToAdd
UserPrincipalNameSuffixToAdd = $Node.Tests.$testName.UserPrincipalNameSuffixToAdd
}
}
}

<#
.SYNOPSIS
Sets the SPN/UPN suffix properties using the 'remove' parameters.
#>
Configuration MSFT_ADForestProperties_SetRemoveProperties_Config
{
Import-DscResource -ModuleName 'ActiveDirectoryDsc'

$testName = 'SetRemoveProperties'

node $AllNodes.NodeName
{
ADForestProperties 'Integration_Test'
{
ForestName = $Node.ForestName
ServicePrincipalNameSuffixToRemove = $Node.Tests.$testName.ServicePrincipalNameSuffixToRemove
UserPrincipalNameSuffixToRemove = $Node.Tests.$testName.UserPrincipalNameSuffixToRemove
}
}
}

<#
.SYNOPSIS
Restore domain controller properties to the default values.
#>
Configuration MSFT_ADForestProperties_RestoreDefaultValues_Config
{
Import-DscResource -ModuleName 'ActiveDirectoryDsc'

node $AllNodes.NodeName
{
ADForestProperties 'Integration_Test'
{
ForestName = $Node.ForestName
TombstoneLifetime = $Node.Default.TombstoneLifetime
ServicePrincipalNameSuffix = $Node.Default.ServicePrincipalNameSuffix
UserPrincipalNameSuffix = $Node.Default.UserPrincipalNameSuffix
}
}
}
Loading

0 comments on commit 5ea5a13

Please sign in to comment.