Skip to content

Commit

Permalink
AdfsServerApplication: Add basic support for AdfsServerApplication (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
watschi authored Oct 24, 2023
1 parent 477b13b commit 497c5b7
Show file tree
Hide file tree
Showing 11 changed files with 1,376 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- AdfsServerApplication
- Added basic support for AdfsServerApplicaitons (WIA only, not client certificates/secrets)

### Changed

- Update Azure DevOps DownloadBuildArtifacts to v1.
Expand Down
90 changes: 90 additions & 0 deletions Tests/Integration/MSFT_AdfsServerApplication.Config.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<#
.SYNOPSIS
AdfsServerApplication DSC Resource Integration Test Configuration
.NOTES
The AdfsServerApplication resource has a dependency on an AdfsApplicationGroup resource
#>

#region HEADER
# Integration Test Config Template Version: 1.2.1
#endregion

$configFile = [System.IO.Path]::ChangeExtension($MyInvocation.MyCommand.Path, 'json')
if (Test-Path -Path $configFile)
{
$ConfigurationData = Get-Content -Path $configFile | ConvertFrom-Json
}
else
{
$ConfigurationData = @{
AllNodes = @(
@{
NodeName = 'localhost'
CertificateFile = $env:DscPublicCertificatePath
}
)
AdfsApplicationGroup = @{
Name = 'DscAppGroup1'
Description = "This is the AppGroup1 Description"
Ensure = 'Present'
}
AdfsServerApplication = @{
Name = 'DscServerApplication1'
Description = 'This is the DscServerApplication1 Description'
Identifier = '96ec073d-9200-4d74-aeb7-d5028d6efa4b'
ADUserPrincipalName = 'CONTOSO\Svc.App1'
RedirectUri = 'https://serverapp1.contoso.com'
LogoutUri = 'https://serverapp1.contoso.com/logout'
}
}
}

Configuration MSFT_AdfsServerApplication_Init_Config
{
<#
.SYNOPSIS
Initialises the Integration test resources
#>

Import-DscResource -ModuleName 'AdfsDsc'

node $AllNodes.NodeName
{
AdfsApplicationGroup 'Integration_Test'
{
Name = $ConfigurationData.AdfsApplicationGroup.Name
Ensure = 'Absent'
}
}
}

Configuration MSFT_AdfsServerApplication_Config
{
<#
.SYNOPSIS
Manages an ADFS Application Group and AdfsServerApplication
#>

Import-DscResource -ModuleName 'AdfsDsc'

node $AllNodes.NodeName
{
AdfsApplicationGroup 'Integration_Test'
{
Name = $ConfigurationData.AdfsApplicationGroup.Name
Description = $ConfigurationData.AdfsApplicationGroup.Description
}

AdfsServerApplication 'Integration_Test'
{
Name = $ConfigurationData.AdfsServerApplication.Name
Description = $ConfigurationData.AdfsServerApplication.Description
ApplicationGroupIdentifier = $ConfigurationData.AdfsApplicationGroup.Name
Identifier = $ConfigurationData.AdfsServerApplication.Identifier
ADUserPrincipalName = $ConfigurationData.AdfsServerApplication.ADUserPrincipalName
RedirectUri = $ConfigurationData.AdfsServerApplication.RedirectUri
LogoutUri = $ConfigurationData.AdfsServerApplication.LogoutUri
}
}
}
136 changes: 136 additions & 0 deletions Tests/Integration/MSFT_AdfsServerApplication.Integration.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
<#
.SYNOPSIS
AdfsServerApplication DSC Resource Integration Tests
.DESCRIPTION
Verbose/Debug output can be set by running:
Invoke-pester -Script @{Path='.\MSFT_AdfsServerApplication.Integration.Tests.ps1';Parameters=@{Verbose=$true;Debug=$true}}
The AdfsServerApplication resource has a dependency on an AdfsApplicationGroup resource
#>

[CmdletBinding()]
param()

Set-StrictMode -Version 2.0

$script:dscModuleName = 'AdfsDsc'
$script:dscResourceFriendlyName = 'AdfsServerApplication'
$script:dscResourceName = "MSFT_$($script:dscResourceFriendlyName)"

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
{
#region Integration Tests
$configurationFile = Join-Path -Path $PSScriptRoot -ChildPath "$($script:dscResourceName).config.ps1"
. $configurationFile

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

$startDscConfigurationParameters = @{
Path = $TestDrive
ComputerName = 'localhost'
Wait = $true
Verbose = $true
Force = $true
Debug = $true
ErrorAction = 'Stop'
}

$configurationName = "$($script:dscResourceName)_Init_Config"

Context ('When using configuration {0}' -f $configurationName) {
It 'Should compile and apply the MOF without throwing' {
{
$configurationParameters = @{
OutputPath = $TestDrive
ConfigurationData = $ConfigurationData
}

& $configurationName @configurationParameters

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 ensured the resource is absent' {
$resourceCurrentState = $script:currentConfiguration | Where-Object -FilterScript {
$_.ConfigurationName -eq $configurationName
}
$resourceCurrentState.Ensure | Should -Be 'Absent'
}

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

$configurationName = "$($script:dscResourceName)_Config"

Context ('When using configuration {0}' -f $configurationName) {
It 'Should compile and apply the MOF without throwing' {
{
$configurationParameters = @{
OutputPath = $TestDrive
ConfigurationData = $ConfigurationData
}

& $configurationName @configurationParameters

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.AdfsServerApplication.Keys)
{
$resourceCurrentState.$property | Should -Be $ConfigurationData.AdfsServerApplication.$property
}
}

It 'Should return $true when Test-DscConfiguration is run' {
Test-DscConfiguration | Should -Be 'True'
}
}
}
#endregion
}
finally
{
Restore-TestEnvironment -TestEnvironment $script:testEnvironment
}
Loading

0 comments on commit 497c5b7

Please sign in to comment.