forked from dsccommunity/ActiveDirectoryDsc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ADForestProperties: Add TombstoneLifetime Property (dsccommunity#549)
* ADForestProperties: Add TomstoneLifetime
- Loading branch information
1 parent
5dddc4b
commit 5ea5a13
Showing
11 changed files
with
858 additions
and
181 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
148 changes: 148 additions & 0 deletions
148
Tests/Integration/MSFT_ADForestProperties.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,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 | ||
} |
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,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 | ||
} | ||
} | ||
} |
Oops, something went wrong.