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

ADKDSKey: Add Integration Tests #526

Merged
merged 4 commits into from
Nov 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
([issue #512](https://github.com/PowerShell/ActiveDirectoryDsc/issues/512)).
- Resource unit tests refactored to use nested contexts and follow the logic of the module.
- Resource Integration tests added.
- Changes to ADKDSKey
- Added Integration testing ([issue #351](https://github.com/PowerShell/ActiveDirectoryDsc/issues/351))

## 4.2.0.0

Expand Down
90 changes: 90 additions & 0 deletions Tests/Integration/MSFT_ADKDSKey.Integration.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
if ($env:APPVEYOR -eq $true)
{
Write-Warning -Message 'Integration test is not supported in AppVeyor.'
return
}

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

#region HEADER
# Integration Test Template Version: 1.3.3
[System.String] $script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot)
if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or `
(-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) )
{
& git @('clone', 'https://github.com/PowerShell/DscResource.Tests.git', (Join-Path -Path $script:moduleRoot -ChildPath 'DscResource.Tests'))
}

Import-Module -Name (Join-Path -Path $script:moduleRoot -ChildPath (Join-Path -Path 'DSCResource.Tests' -ChildPath 'TestHelper.psm1')) -Force
$TestEnvironment = Initialize-TestEnvironment `
-DSCModuleName $script:dscModuleName `
-DSCResourceName $script:dscResourceName `
-TestType Integration
#endregion

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

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

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

$resourceCurrentState.EffectiveTime | Should -Be $ConfigurationData.AllNodes.EffectiveTime
$resourceCurrentState.Ensure | Should -Be 'Present'
}

It 'Should return $true when Test-DscConfiguration is run' {
Test-DscConfiguration -Verbose | Should -Be 'True'
}
}
}
}
finally
{
#region FOOTER
Restore-TestEnvironment -TestEnvironment $TestEnvironment
#endregion
}
44 changes: 44 additions & 0 deletions Tests/Integration/MSFT_ADKDSKey.config.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#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
EffectiveTime = (Get-Date -year 1999 -month 1 -day 1 -hour 0 -Minute 0 -Second 0).ToString()
}
)
}
}

<#
.SYNOPSIS
Create a KDS root key in the past. This will allow the key to be used right away
#>
Configuration MSFT_ADKDSKey_CreateKDSRootKeyInPast_Config
{
Import-DscResource -ModuleName 'ActiveDirectoryDsc'

node $AllNodes.NodeName
{
ADKDSKey 'Integration_Test'
{
Ensure = 'Present'
EffectiveTime = $ConfigurationData.AllNodes.EffectiveTime
AllowUnsafeEffectiveTime = $true
}
}
}