From e5404ed190b3940e2dc11a90a6af43713f13c46f Mon Sep 17 00:00:00 2001 From: Brandon Padgett Date: Mon, 7 May 2018 03:59:19 -0500 Subject: [PATCH 1/7] Fix name param to ZoneName in Get-TargetResource (#64) - Fix bug in xDnsServerPrimaryZone Get-TargetResource that caused the Zone Name to be null --- .../MSFT_xDnsServerPrimaryZone/MSFT_xDnsServerPrimaryZone.psm1 | 2 +- README.md | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/DSCResources/MSFT_xDnsServerPrimaryZone/MSFT_xDnsServerPrimaryZone.psm1 b/DSCResources/MSFT_xDnsServerPrimaryZone/MSFT_xDnsServerPrimaryZone.psm1 index cc657bb4..f356ad47 100644 --- a/DSCResources/MSFT_xDnsServerPrimaryZone/MSFT_xDnsServerPrimaryZone.psm1 +++ b/DSCResources/MSFT_xDnsServerPrimaryZone/MSFT_xDnsServerPrimaryZone.psm1 @@ -47,7 +47,7 @@ function Get-TargetResource $dnsServerZone = Get-DnsServerZone -Name $Name -ErrorAction SilentlyContinue; $targetResource = @{ - Name = $dnsServerZone.Name; + Name = $dnsServerZone.ZoneName; ZoneFile = $dnsServerZone.ZoneFile; DynamicUpdate = $dnsServerZone.DynamicUpdate; Ensure = if ($null -eq $dnsServerZone) { 'Absent' } else { 'Present' }; diff --git a/README.md b/README.md index 162567da..341f4aa6 100644 --- a/README.md +++ b/README.md @@ -153,6 +153,7 @@ Please check out common DSC Resources [contributing guidelines](https://github.c * Added resource xDnsServerSetting * MSFT_xDnsRecord: Added DnsServer property +* Fix bug in xDnsServerPrimaryZone Get-TargetResource that caused the Zone Name to be null ### 1.8.0.0 From 554e1e27a38f85b93a5d670afab761122af05375 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Mon, 7 May 2018 11:19:58 +0200 Subject: [PATCH 2/7] Update CHANGELOG.md (#72) --- README.md | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 341f4aa6..9040325f 100644 --- a/README.md +++ b/README.md @@ -138,12 +138,19 @@ Please check out common DSC Resources [contributing guidelines](https://github.c ### Unreleased +* Changes to xDnsServerPrimaryZone + * Fix bug in Get-TargetResource that caused the Zone Name to be null + ([issue #63](https://github.com/PowerShell/xDnsServer/issues/63)). + [Brandon Padgett (@gerane)](https://github.com/gerane) + ### 1.10.0.0 * Changes to xDnsServerADZone - * Fixed bug introduced by [#49](https://github.com/PowerShell/xDnsServer/pull/49). Previously, CimSessions were always used - regardless of connecting to a remote machine or the local machine. Now CimSessions are only utilized when a computername or - computername and credential are used. ([issue #53](https://github.com/PowerShell/xDnsServer/issues/53)). + * Fixed bug introduced by [PR #49](https://github.com/PowerShell/xDnsServer/pull/49). + Previously, CimSessions were always used regardless of connecting to a remote + machine or the local machine. Now CimSessions are only utilized when a + computername, or computername and credential are used + ([issue #53](https://github.com/PowerShell/xDnsServer/issues/53)). [Michael Fyffe (@TraGicCode)](https://github.com/TraGicCode) * Fixed all PSSA rule warnings. [Michael Fyffe (@TraGicCode)](https://github.com/TraGicCode) * Fix DsAvailable key missing ([#66](https://github.com/PowerShell/xDnsServer/issues/66)). @@ -153,7 +160,6 @@ Please check out common DSC Resources [contributing guidelines](https://github.c * Added resource xDnsServerSetting * MSFT_xDnsRecord: Added DnsServer property -* Fix bug in xDnsServerPrimaryZone Get-TargetResource that caused the Zone Name to be null ### 1.8.0.0 From ba1dc792edd1f288e0144a59c07f32721a07dc81 Mon Sep 17 00:00:00 2001 From: Claudio Spizzi Date: Wed, 16 May 2018 10:46:26 +0200 Subject: [PATCH 3/7] Add resource xDnsServerZoneAging (#61) --- .../MSFT_xDnsServerZoneAging.psm1 | 189 ++++++++++++ .../MSFT_xDnsServerZoneAging.schema.mof | 8 + README.md | 54 +++- Tests/Unit/MSFT_xDnsServerZoneAging.Tests.ps1 | 269 ++++++++++++++++++ 4 files changed, 519 insertions(+), 1 deletion(-) create mode 100644 DSCResources/MSFT_xDnsServerZoneAging/MSFT_xDnsServerZoneAging.psm1 create mode 100644 DSCResources/MSFT_xDnsServerZoneAging/MSFT_xDnsServerZoneAging.schema.mof create mode 100644 Tests/Unit/MSFT_xDnsServerZoneAging.Tests.ps1 diff --git a/DSCResources/MSFT_xDnsServerZoneAging/MSFT_xDnsServerZoneAging.psm1 b/DSCResources/MSFT_xDnsServerZoneAging/MSFT_xDnsServerZoneAging.psm1 new file mode 100644 index 00000000..609470a9 --- /dev/null +++ b/DSCResources/MSFT_xDnsServerZoneAging/MSFT_xDnsServerZoneAging.psm1 @@ -0,0 +1,189 @@ + +<# + .SYNOPSIS + Get the DNS zone aging settings. + + .PARAMETER Name + Name of the DNS forward or reverse loookup zone. + + .PARAMETER Enabled + Option to enable scavenge stale resource records on the zone. +#> +function Get-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Collections.Hashtable])] + param + ( + [Parameter(Mandatory = $true)] + [System.String] + $Name, + + [Parameter(Mandatory = $true)] + [System.Boolean] + $Enabled + ) + + Write-Verbose -Message "Getting the DNS zone aging for $Name." + + # Get the current zone aging from the local DNS server + $zoneAging = Get-DnsServerZoneAging -Name $Name + + return @{ + Name = $Name + Enabled = $zoneAging.AgingEnabled + RefreshInterval = $zoneAging.RefreshInterval.TotalHours + NoRefreshInterval = $zoneAging.NoRefreshInterval.TotalHours + } +} + +<# + .SYNOPSIS + Set the DNS zone aging settings. + + .PARAMETER Name + Name of the DNS forward or reverse loookup zone. + + .PARAMETER Enabled + Option to enable scavenge stale resource records on the zone. + + .PARAMETER RefreshInterval + Refresh interval for record scavencing in hours. Default value is 7 days. + + .PARAMETER NoRefreshInterval + No-refresh interval for record scavencing in hours. Default value is 7 days. +#> +function Set-TargetResource +{ + [CmdletBinding()] + param + ( + [Parameter(Mandatory = $true)] + [System.String] + $Name, + + [Parameter(Mandatory = $true)] + [System.Boolean] + $Enabled, + + [Parameter()] + [System.UInt32] + $RefreshInterval = 168, + + [Parameter()] + [System.UInt32] + $NoRefreshInterval = 168 + ) + + $currentConfiguration = Get-TargetResource -Name $Name -Enabled $Enabled + + # Enable or disable zone aging + if ($currentConfiguration.Enabled -ne $Enabled) + { + if ($Enabled) + { + Write-Verbose -Message "Enable DNS zone aging on $Name." + } + else + { + Write-Verbose -Message "Disable DNS zone aging on $Name." + } + + Set-DnsServerZoneAging -Name $Name -Aging $Enabled -WarningAction 'SilentlyContinue' + } + + # Update the refresh interval + if ($PSBoundParameters.ContainsKey('RefreshInterval')) + { + if ($currentConfiguration.RefreshInterval -ne $RefreshInterval) + { + Write-Verbose -Message "Set DNS zone refresh interval to $RefreshInterval hours." + + $refreshIntervalTimespan = [System.TimeSpan]::FromHours($RefreshInterval) + + <# + Hide the following warning if aging is not enabled: Specified + parameters related to aging of records have been set. However, + aging was not enabled and hence the settings are ineffective. + #> + Set-DnsServerZoneAging -Name $Name -RefreshInterval $refreshIntervalTimespan -WarningAction 'SilentlyContinue' + } + } + + # Update the no refresh interval + if ($PSBoundParameters.ContainsKey('NoRefreshInterval')) + { + if ($currentConfiguration.NoRefreshInterval -ne $NoRefreshInterval) + { + Write-Verbose -Message "Set DNS zone no refresh interval to $NoRefreshInterval hours." + + $noRefreshIntervalTimespan = [System.TimeSpan]::FromHours($NoRefreshInterval) + + <# + Hide the following warning if aging is not enabled: Specified + parameters related to aging of records have been set. However, + aging was not enabled and hence the settings are ineffective. + #> + Set-DnsServerZoneAging -Name $Name -NoRefreshInterval $noRefreshIntervalTimespan -WarningAction 'SilentlyContinue' + } + } +} + +<# + .SYNOPSIS + Test the DNS zone aging settings. + + .PARAMETER Name + Name of the DNS forward or reverse loookup zone. + + .PARAMETER Enabled + Option to enable scavenge stale resource records on the zone. + + .PARAMETER RefreshInterval + Refresh interval for record scavencing in hours. Default value is 7 days. + + .PARAMETER NoRefreshInterval + No-refresh interval for record scavencing in hours. Default value is 7 days. +#> +function Test-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Boolean])] + [CmdletBinding()] + param + ( + [Parameter(Mandatory = $true)] + [System.String] + $Name, + + [Parameter(Mandatory = $true)] + [System.Boolean] + $Enabled, + + [Parameter()] + [System.UInt32] + $RefreshInterval = 168, + + [Parameter()] + [System.UInt32] + $NoRefreshInterval = 168 + ) + + Write-Verbose -Message "Testing the DNS zone aging for $Name." + + $currentConfiguration = Get-TargetResource -Name $Name -Enabled $Enabled + + $isDesiredState = $currentConfiguration.Enabled -eq $Enabled + + if ($PSBoundParameters.ContainsKey('RefreshInterval')) + { + $isDesiredState = $isDesiredState -and $currentConfiguration.RefreshInterval -eq $RefreshInterval + } + + if ($PSBoundParameters.ContainsKey('NoRefreshInterval')) + { + $isDesiredState = $isDesiredState -and $currentConfiguration.NoRefreshInterval -eq $NoRefreshInterval + } + + return $isDesiredState +} diff --git a/DSCResources/MSFT_xDnsServerZoneAging/MSFT_xDnsServerZoneAging.schema.mof b/DSCResources/MSFT_xDnsServerZoneAging/MSFT_xDnsServerZoneAging.schema.mof new file mode 100644 index 00000000..3f285826 --- /dev/null +++ b/DSCResources/MSFT_xDnsServerZoneAging/MSFT_xDnsServerZoneAging.schema.mof @@ -0,0 +1,8 @@ +[ClassVersion("1.0.0.0"), FriendlyName("xDnsServerZoneAging")] +class MSFT_xDnsServerZoneAging : OMI_BaseResource +{ + [Key, Description("Name of the DNS forward or reverse loookup zone.")] String Name; + [Required, Description("Option to enable scavenge stale resource records on the zone.")] Boolean Enabled; + [Write, Description("Refresh interval for record scavencing in hours. Default value is 7 days.")] UInt32 RefreshInterval; + [Write, Description("No-refresh interval for record scavencing in hours. Default value is 7 days.")] UInt32 NoRefreshInterval; +}; diff --git a/README.md b/README.md index 9040325f..5833dc80 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ Please check out common DSC Resources [contributing guidelines](https://github.c * **IsSingleInstance**: Specifies the resource is a single instance, the value must be 'Yes' * **IPAddresses**: IP addresses of the forwarders -#### xDnsServerADZone +### xDnsServerADZone * **Name**: Name of the AD DNS zone * **Ensure**: Whether the AD zone should be present or removed @@ -60,6 +60,13 @@ Please check out common DSC Resources [contributing guidelines](https://github.c * **Ensure**: Whether the secondary zone should be present or removed * **Type**: Type of the DNS server zone +### xDnsServerZoneAging + +* **Name**: Name of the DNS forward or reverse loookup zone. +* **Enabled**: Option to enable scavenge stale resource records on the zone. +* **RefreshInterval**: Refresh interval for record scavencing in hours. Default value is 7 days. +* **NoRefreshInterval**: No-refresh interval for record scavencing in hours. Default value is 7 days. + ### xDnsServerZoneTransfer * **Name**: Name of the DNS zone @@ -138,6 +145,7 @@ Please check out common DSC Resources [contributing guidelines](https://github.c ### Unreleased +* Added resource xDnsServerZoneAging * Changes to xDnsServerPrimaryZone * Fix bug in Get-TargetResource that caused the Zone Name to be null ([issue #63](https://github.com/PowerShell/xDnsServer/issues/63)). @@ -467,3 +475,47 @@ configuration Sample_DnsSettings Sample_DnsSettings ``` + +### Enable DNS Zone Aging + +```powershell +configuration Sample_DnsZoneAging +{ + Import-DscResource -ModuleName xDnsServer + + node localhost + { + xDnsServerZoneAging DnsServerZoneAging + { + Name = 'contoso.com' + Enabled = $true + RefreshInterval = 120 # 5 days + NoRefreshInterval = 240 # 10 days + } + } +} + +Sample_DnsZoneAging +``` + +### Enable DNS Reverse Zone Aging + +```powershell +configuration Sample_DnsReverseZoneAging +{ + Import-DscResource -ModuleName xDnsServer + + node localhost + { + xDnsServerZoneAging DnsServerReverseZoneAging + { + Name = '168.192.in-addr-arpa' + Enabled = $true + RefreshInterval = 168 # 7 days + NoRefreshInterval = 168 # 7 days + } + } +} + +Sample_DnsReverseZoneAging +``` diff --git a/Tests/Unit/MSFT_xDnsServerZoneAging.Tests.ps1 b/Tests/Unit/MSFT_xDnsServerZoneAging.Tests.ps1 new file mode 100644 index 00000000..74640e05 --- /dev/null +++ b/Tests/Unit/MSFT_xDnsServerZoneAging.Tests.ps1 @@ -0,0 +1,269 @@ +$Global:DSCModuleName = 'xDnsServer' +$Global:DSCResourceName = 'MSFT_xDnsServerZoneAging' + +#region HEADER + +# Unit Test Template Version: 1.2.1 +$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 $Global:DSCModuleName ` + -DSCResourceName $Global:DSCResourceName ` + -TestType Unit + +#endregion HEADER + +function Invoke-TestSetup { } + +function Invoke-TestCleanup { + Restore-TestEnvironment -TestEnvironment $TestEnvironment +} + +# Begin Testing +try +{ + Invoke-TestSetup + + InModuleScope $Global:DSCResourceName { + + #region Pester Test Initialization + $zoneName = 'contoso.com' + $getParameterEnable = @{ + Name = $zoneName + Enabled = $true + } + $getParameterDisable = @{ + Name = $zoneName + Enabled = $false + } + $testParameterEnable = @{ + Name = $zoneName + Enabled = $true + RefreshInterval = 168 + NoRefreshInterval = 168 + } + $testParameterDisable = @{ + Name = $zoneName + Enabled = $false + RefreshInterval = 168 + NoRefreshInterval = 168 + } + $setParameterEnable = @{ + Name = $zoneName + Enabled = $true + } + $setParameterDisable = @{ + Name = $zoneName + Enabled = $false + } + $setParameterRefreshInterval = @{ + Name = $zoneName + Enabled = $true + RefreshInterval = 24 + } + $setParameterNoRefreshInterval = @{ + Name = $zoneName + Enabled = $true + NoRefreshInterval = 36 + } + $setFilterEnable = { + $Name -eq $zoneName -and + $Aging -eq $true + } + $setFilterDisable = { + $Name -eq $zoneName -and + $Aging -eq $false + } + $setFilterRefreshInterval = { + $Name -eq $zoneName -and + $RefreshInterval -eq ([System.TimeSpan]::FromHours(24)) + } + $setFilterNoRefreshInterval = { + $Name -eq $zoneName -and + $NoRefreshInterval -eq ([System.TimeSpan]::FromHours(36)) + } + $fakeDnsServerZoneAgingEnabled = @{ + ZoneName = $zoneName + AgingEnabled = $true + RefreshInterval = [System.TimeSpan]::FromHours(168) + NoRefreshInterval = [System.TimeSpan]::FromHours(168) + } + $fakeDnsServerZoneAgingDisabled = @{ + ZoneName = $zoneName + AgingEnabled = $false + RefreshInterval = [System.TimeSpan]::FromHours(168) + NoRefreshInterval = [System.TimeSpan]::FromHours(168) + } + #endregion + + #region Function Get-TargetResource + Describe "$($Global:DSCResourceName)\Get-TargetResource" { + + Context "The zone aging on $zoneName is enabled" { + + Mock -CommandName Get-DnsServerZoneAging -MockWith { return $fakeDnsServerZoneAgingEnabled } + + It 'Should return a "System.Collections.Hashtable" object type' { + # Act + $targetResource = Get-TargetResource @getParameterDisable + + # Assert + $targetResource | Should BeOfType [System.Collections.Hashtable] + } + + It 'Should return valid values when aging is enabled' { + # Act + $targetResource = Get-TargetResource @getParameterEnable + + # Assert + $targetResource.Name | Should Be $testParameterEnable.Name + $targetResource.Enabled | Should Be $testParameterEnable.Enabled + $targetResource.RefreshInterval | Should Be $testParameterEnable.RefreshInterval + $targetResource.NoRefreshInterval | Should Be $testParameterEnable.NoRefreshInterval + } + } + + Context "The zone aging on $zoneName is disabled" { + + Mock -CommandName Get-DnsServerZoneAging -MockWith { return $fakeDnsServerZoneAgingDisabled } + + It 'Should return valid values when aging is not enabled' { + # Act + $targetResource = Get-TargetResource @getParameterDisable + + # Assert + $targetResource.Name | Should Be $testParameterDisable.Name + $targetResource.Enabled | Should Be $testParameterDisable.Enabled + $targetResource.RefreshInterval | Should Be $testParameterDisable.RefreshInterval + $targetResource.NoRefreshInterval | Should Be $testParameterDisable.NoRefreshInterval + } + } + } + #endregion + + #region Function Test-TargetResource + Describe "$($Global:DSCResourceName)\Test-TargetResource" { + + Context "The zone aging on $zoneName is enabled" { + + Mock -CommandName Get-DnsServerZoneAging -MockWith { return $fakeDnsServerZoneAgingEnabled } + + It 'Should return a "System.Boolean" object type' { + # Act + $targetResource = Test-TargetResource @testParameterDisable + + # Assert + $targetResource | Should BeOfType [System.Boolean] + } + + It 'Should pass when everything matches (enabled)' { + # Act + $targetResource = Test-TargetResource @testParameterEnable + + # Assert + $targetResource | Should Be $true + } + + It 'Should fail when everything matches (enabled)' { + # Act + $targetResource = Test-TargetResource @testParameterDisable + + # Assert + $targetResource | Should Be $false + } + } + + Context "The zone aging on $zoneName is disabled" { + + Mock -CommandName Get-DnsServerZoneAging -MockWith { return $fakeDnsServerZoneAgingDisabled } + + It 'Should pass when everything matches (disabled)' { + # Act + $targetResource = Test-TargetResource @testParameterDisable + + # Assert + $targetResource | Should Be $true + } + + It 'Should fail when everything matches (disabled)' { + # Act + $targetResource = Test-TargetResource @testParameterEnable + + # Assert + $targetResource | Should Be $false + } + } + } + #endregion + + #region Function Set-TargetResource + Describe "$($Global:DSCResourceName)\Set-TargetResource" { + + Context "The zone aging on $zoneName is enabled" { + + Mock -CommandName Get-DnsServerZoneAging -MockWith { return $fakeDnsServerZoneAgingEnabled } + + It 'Should disable the DNS zone aging' { + # Arrange + Mock -CommandName Set-DnsServerZoneAging -ParameterFilter $setFilterDisable -Verifiable + + # Act + Set-TargetResource @setParameterDisable + + # Assert + Assert-MockCalled -CommandName Set-DnsServerZoneAging -ParameterFilter $setFilterDisable -Times 1 -Exactly -Scope It + } + + It 'Should set the DNS zone refresh interval' { + # Arrange + Mock -CommandName Set-DnsServerZoneAging -ParameterFilter $setFilterRefreshInterval -Verifiable + + # Act + Set-TargetResource @setParameterRefreshInterval + + # Assert + Assert-MockCalled -CommandName Set-DnsServerZoneAging -ParameterFilter $setFilterRefreshInterval -Times 1 -Exactly -Scope It + } + + It 'Should set the DNS zone no refresh interval' { + # Arrange + Mock -CommandName Set-DnsServerZoneAging -ParameterFilter $setFilterNoRefreshInterval -Verifiable + + # Act + Set-TargetResource @setParameterNoRefreshInterval + + # Assert + Assert-MockCalled -CommandName Set-DnsServerZoneAging -ParameterFilter $setFilterNoRefreshInterval -Times 1 -Exactly -Scope It + } + } + + Context "The zone aging on $zoneName is disabled" { + + Mock -CommandName Get-DnsServerZoneAging -MockWith { return $fakeDnsServerZoneAgingDisabled } + + It 'Should enable the DNS zone aging' { + # Arrange + Mock -CommandName Set-DnsServerZoneAging -ParameterFilter $setFilterEnable -Verifiable + + # Act + Set-TargetResource @setParameterEnable + + # Assert + Assert-MockCalled -CommandName Set-DnsServerZoneAging -ParameterFilter $setFilterEnable -Times 1 -Exactly -Scope It + } + } + } + #endregion + } +} +finally +{ + Invoke-TestCleanup +} From 57132918e943632fa4223fd21b2ee642fab4ccad Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Wed, 23 May 2018 11:27:05 +0200 Subject: [PATCH 4/7] xDnsServer: Add CodeCov support (#74) - Changes to xDsnServer - Updated appveyor.yml to use the default template and add CodeCov support (issue #73). - Adding a Branches section to the README.md with Codecov badges for both master and dev branch (issue #73). - Updated description of resource module in README.md. --- README.md | 33 +++++++++++++++++++++++++++++---- appveyor.yml | 45 ++++++++------------------------------------- 2 files changed, 37 insertions(+), 41 deletions(-) diff --git a/README.md b/README.md index 5833dc80..4e9a265a 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,31 @@ # xDnsServer -[![Build status](https://ci.appveyor.com/api/projects/status/qqspiio117bgaieo/branch/master?svg=true)](https://ci.appveyor.com/project/PowerShell/xdnsserver/branch/master) - -The **xDnsServer** DSC resources configure and manage a DNS server. +The **xDnsServer** module contains DSC resources for the management and +configuration of Windows Server DNS Server. This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. +## Branches + +### master + +[![Build status](https://ci.appveyor.com/api/projects/status/qqspiio117bgaieo/branch/master?svg=true)](https://ci.appveyor.com/project/PowerShell/xDnsServer/branch/master) +[![codecov](https://codecov.io/gh/PowerShell/xDnsServer/branch/master/graph/badge.svg)](https://codecov.io/gh/PowerShell/xDnsServer/branch/master) + +This is the branch containing the latest release - +no contributions should be made directly to this branch. + +### dev + +[![Build status](https://ci.appveyor.com/api/projects/status/qqspiio117bgaieo/branch/dev?svg=true)](https://ci.appveyor.com/project/PowerShell/xDnsServer/branch/dev) +[![codecov](https://codecov.io/gh/PowerShell/xDnsServer/branch/dev/graph/badge.svg)](https://codecov.io/gh/PowerShell/xDnsServer/branch/dev) + +This is the development branch +to which contributions should be proposed by contributors as pull requests. +This development branch will periodically be merged to the master branch, +and be released to [PowerShell Gallery](https://www.powershellgallery.com/). + ## Contributing Please check out common DSC Resources [contributing guidelines](https://github.com/PowerShell/DscResource.Kit/blob/master/CONTRIBUTING.md). @@ -145,7 +164,13 @@ Please check out common DSC Resources [contributing guidelines](https://github.c ### Unreleased -* Added resource xDnsServerZoneAging +* Changes to xDnsServer + * Updated appveyor.yml to use the default template and add CodeCov support + ([issue #73](https://github.com/PowerShell/xActiveDirectory/issues/73)). + * Adding a Branches section to the README.md with Codecov badges for both + master and dev branch ([issue #73](https://github.com/PowerShell/xActiveDirectory/issues/73)). + * Updated description of resource module in README.md. +* Added resource xDnsServerZoneAging. [Claudio Spizzi (@claudiospizzi)](https://github.com/claudiospizzi) * Changes to xDnsServerPrimaryZone * Fix bug in Get-TargetResource that caused the Zone Name to be null ([issue #63](https://github.com/PowerShell/xDnsServer/issues/63)). diff --git a/appveyor.yml b/appveyor.yml index 87486a6b..acfaec85 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -3,15 +3,12 @@ #---------------------------------# version: 1.7.{build}.0 install: - - git clone https://github.com/PowerShell/DscResource.Tests - - ps: | - Push-Location - cd DscResource.Tests - Import-Module .\TestHelper.psm1 -force - Pop-Location - Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force - Install-Module -Name Pester -Repository PSGallery -Force - Add-WindowsFeature RSAT-DNS-Server + - git clone https://github.com/PowerShell/DscResource.Tests + - ps: Write-Verbose -Message "PowerShell version $($PSVersionTable.PSVersion)" -Verbose + - ps: Import-Module "$env:APPVEYOR_BUILD_FOLDER\DscResource.Tests\AppVeyor.psm1" + - ps: Invoke-AppveyorInstallTask + - ps: Add-WindowsFeature RSAT-DNS-Server + #---------------------------------# # build configuration # #---------------------------------# @@ -24,12 +21,7 @@ build: false test_script: - ps: | - $testResultsFile = ".\TestsResults.xml" - $res = Invoke-Pester -OutputFormat NUnitXml -OutputFile $testResultsFile -PassThru - (New-Object 'System.Net.WebClient').UploadFile("https://ci.appveyor.com/api/testresults/nunit/$($env:APPVEYOR_JOB_ID)", (Resolve-Path $testResultsFile)) - if ($res.FailedCount -gt 0) { - throw "$($res.FailedCount) tests failed." - } + Invoke-AppveyorTestScriptTask -CodeCoverage -CodeCovIo -ExcludeTag @() #---------------------------------# # deployment configuration # @@ -38,25 +30,4 @@ test_script: # scripts to run before deployment deploy_script: - ps: | - # Creating project artifact - $stagingDirectory = (Resolve-Path ..).Path - $manifest = Join-Path $pwd "xDnsServer.psd1" - (Get-Content $manifest -Raw).Replace("1.7.0.0", $env:APPVEYOR_BUILD_VERSION) | Out-File $manifest - $zipFilePath = Join-Path $stagingDirectory "$(Split-Path $pwd -Leaf).zip" - Add-Type -assemblyname System.IO.Compression.FileSystem - [System.IO.Compression.ZipFile]::CreateFromDirectory($pwd, $zipFilePath) - - # Creating NuGet package artifact - New-Nuspec -packageName $env:APPVEYOR_PROJECT_NAME -version $env:APPVEYOR_BUILD_VERSION -author "Microsoft" -owners "Microsoft" -licenseUrl "https://github.com/PowerShell/DscResources/blob/master/LICENSE" -projectUrl "https://github.com/$($env:APPVEYOR_REPO_NAME)" -packageDescription $env:APPVEYOR_PROJECT_NAME -tags "DesiredStateConfiguration DSC DSCResourceKit" -destinationPath . - nuget pack ".\$($env:APPVEYOR_PROJECT_NAME).nuspec" -outputdirectory . - $nuGetPackageName = $env:APPVEYOR_PROJECT_NAME + "." + $env:APPVEYOR_BUILD_VERSION + ".nupkg" - $nuGetPackagePath = (Get-ChildItem $nuGetPackageName).FullName - - @( - # You can add other artifacts here - $zipFilePath, - $nuGetPackagePath - ) | % { - Write-Host "Pushing package $_ as Appveyor artifact" - Push-AppveyorArtifact $_ - } + Invoke-AppveyorAfterTestTask From 0f163ddaf1d3f8c045050a049b1cfabcdc19106b Mon Sep 17 00:00:00 2001 From: Reggie Gibson <31147354+regedit32@users.noreply.github.com> Date: Wed, 6 Jun 2018 04:55:47 -0500 Subject: [PATCH 5/7] Adding Ptr record support to xDnsRecord (#60) - Added Ptr record support to xDnsRecord --- .../MSFT_xDnsRecord/MSFT_xDnsRecord.psm1 | 85 ++++- .../MSFT_xDnsRecord.schema.mof | 10 +- README.md | 26 +- Tests/Unit/MSFT_xDnsRecord.Tests.ps1 | 295 ++++++++++-------- 4 files changed, 272 insertions(+), 144 deletions(-) diff --git a/DSCResources/MSFT_xDnsRecord/MSFT_xDnsRecord.psm1 b/DSCResources/MSFT_xDnsRecord/MSFT_xDnsRecord.psm1 index 3c3937ba..5920b3f5 100644 --- a/DSCResources/MSFT_xDnsRecord/MSFT_xDnsRecord.psm1 +++ b/DSCResources/MSFT_xDnsRecord/MSFT_xDnsRecord.psm1 @@ -12,7 +12,28 @@ data LocalizedData '@ } +<# + .SYNOPSIS + This will return the current state of the resource. + .PARAMETER Name + Specifies the name of the DNS server resource record object. + + .PARAMETER Zone + Specifies the name of a DNS zone. + + .PARAMETER Type + Specifies the type of DNS record. + + .PARAMETER Target + Specifies the Target Hostname or IP Address. + + .PARAMETER DnsServer + Name of the DnsServer to create the record on. + + .PARAMETER Ensure + Whether the host record should be present or removed. +#> function Get-TargetResource { [CmdletBinding()] @@ -28,7 +49,7 @@ function Get-TargetResource $Zone, [Parameter(Mandatory = $true)] - [ValidateSet("ARecord", "CName")] + [ValidateSet("ARecord", "CName", "Ptr")] [System.String] $Type, @@ -67,6 +88,10 @@ function Get-TargetResource { $recordData = $record.RecordData.IPv4address.IPAddressToString } + if ($Type -eq "PTR") + { + $recordData = ($record.RecordData.PtrDomainName).TrimEnd('.') + } return @{ Name = $record.HostName; @@ -77,6 +102,28 @@ function Get-TargetResource } } #end function Get-TargetResource +<# + .SYNOPSIS + This will set the resource to the desired state. + + .PARAMETER Name + Specifies the name of the DNS server resource record object. + + .PARAMETER Zone + Specifies the name of a DNS zone. + + .PARAMETER Type + Specifies the type of DNS record. + + .PARAMETER Target + Specifies the Target Hostname or IP Address. + + .PARAMETER DnsServer + Name of the DnsServer to create the record on. + + .PARAMETER Ensure + Whether the host record should be present or removed. +#> function Set-TargetResource { [CmdletBinding()] @@ -91,7 +138,7 @@ function Set-TargetResource $Zone, [Parameter(Mandatory = $true)] - [ValidateSet("ARecord", "CName")] + [ValidateSet("ARecord", "CName", "Ptr")] [System.String] $Type, @@ -123,13 +170,17 @@ function Set-TargetResource $DNSParameters.Add('CName',$true) $DNSParameters.Add('HostNameAlias',$Target) } + if ($Type -eq "PTR") + { + $DNSParameters.Add('Ptr',$true) + $DNSParameters.Add('PtrDomainName',$Target) + } Write-Verbose -Message ($LocalizedData.CreatingDnsRecordMessage -f $Type, $Target, $Zone, $DnsServer) Add-DnsServerResourceRecord @DNSParameters } elseif ($Ensure -eq 'Absent') { - $DNSParameters.Add('Force',$true) if ($Type -eq "ARecord") @@ -140,11 +191,37 @@ function Set-TargetResource { $DNSParameters.Add('RRType','CName') } + if ($Type -eq "PTR") + { + $DNSParameters.Add('RRType','Ptr') + } Write-Verbose -Message ($LocalizedData.RemovingDnsRecordMessage -f $Type, $Target, $Zone, $DnsServer) Remove-DnsServerResourceRecord @DNSParameters } } #end function Set-TargetResource +<# + .SYNOPSIS + This will return whether the resource is in desired state. + + .PARAMETER Name + Specifies the name of the DNS server resource record object. + + .PARAMETER Zone + Specifies the name of a DNS zone. + + .PARAMETER Type + Specifies the type of DNS record. + + .PARAMETER Target + Specifies the Target Hostname or IP Address. + + .PARAMETER DnsServer + Name of the DnsServer to create the record on. + + .PARAMETER Ensure + Whether the host record should be present or removed. +#> function Test-TargetResource { [CmdletBinding()] @@ -160,7 +237,7 @@ function Test-TargetResource $Zone, [Parameter(Mandatory = $true)] - [ValidateSet("ARecord", "CName")] + [ValidateSet("ARecord", "CName", "Ptr")] [System.String] $Type, diff --git a/DSCResources/MSFT_xDnsRecord/MSFT_xDnsRecord.schema.mof b/DSCResources/MSFT_xDnsRecord/MSFT_xDnsRecord.schema.mof index f1911f86..31ce61e9 100644 --- a/DSCResources/MSFT_xDnsRecord/MSFT_xDnsRecord.schema.mof +++ b/DSCResources/MSFT_xDnsRecord/MSFT_xDnsRecord.schema.mof @@ -1,11 +1,11 @@ [ClassVersion("1.0.0.0"), FriendlyName("xDnsRecord")] class MSFT_xDnsRecord : OMI_BaseResource { - [Key] string Name; - [Key] string Zone; - [Required, ValueMap{"ARecord","CName"}, Values{"ARecord","CName"}] string Type; - [Key] string Target; - [Write] string DnsServer; + [Key, Description("Specifies the name of the DNS server resource record object.")] string Name; + [Key, Description("Specifies the name of a DNS zone.")] string Zone; + [Required, Description("Specifies the type of DNS record."), ValueMap{"ARecord","CName","Ptr"}, Values{"ARecord","CName","Ptr"}] string Type; + [Key, Description("Specifies the Target Hostname or IP Address.")] string Target; + [Write, Description("Name of the DnsServer to create the record on.")] string DnsServer; [Write, Description("Should this DNS resource record be present or absent"), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure; }; diff --git a/README.md b/README.md index 4e9a265a..15e860ae 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ Please check out common DSC Resources [contributing guidelines](https://github.c * **xDnsServerSecondaryZone** sets a Secondary zone on a given DNS server. * Secondary zones allow client machine in primary DNS zones to do DNS resolution of machines in the secondary DNS zone. * **xDnsServerZoneTransfer** This resource allows a DNS Server zone data to be replicated to another DNS server. -* **xDnsRecord** This resource allows for the creation of IPv4 host (A) records or CNames against a specific zone on the DNS server. +* **xDnsRecord** This resource allows for the creation of IPv4 host (A) records, CNames, or PTRs against a specific zone on the DNS server. * **xDnsServerSetting** This resource manages the DNS sever settings/properties. ### xDnsServerForwarder @@ -102,13 +102,13 @@ Please check out common DSC Resources [contributing guidelines](https://github.c ### xDnsRecord -* **Name**: Name of the host +* **Name**: Specifies the name of the DNS server resource record object * **Zone**: The name of the zone to create the host record in * **Target**: Target Hostname or IP Address {*Only Supports IPv4 in the current release*} * **DnsServer**: Name of the DnsServer to create the record on. * If not specified, defaults to 'localhost'. * **Type**: DNS Record Type. - * Values include: { ARecord | CName } + * Values include: { ARecord | CName | Ptr } * **Ensure**: Whether the host record should be present or removed ### xDnsServerSetting @@ -164,6 +164,8 @@ Please check out common DSC Resources [contributing guidelines](https://github.c ### Unreleased +* Added Ptr record support to xDnsRecord + * Changes to xDnsServer * Updated appveyor.yml to use the default template and add CodeCov support ([issue #73](https://github.com/PowerShell/xActiveDirectory/issues/73)). @@ -453,6 +455,24 @@ configuration Sample_CName Sample_Crecord ``` +### Adding a DNS PTR record + +```powershell +configuration Sample_Ptr +{ + Import-DscResource -module xDnsServer + xDnsRecord TestPtrRecord + { + Name = "123" + Target = "TestA.contoso.com" + Zone = "0.168.192.in-addr.arpa" + Type = "PTR" + Ensure = "Present" + } +} +Sample_Ptr +``` + ### Removing a DNS A Record ```powershell diff --git a/Tests/Unit/MSFT_xDnsRecord.Tests.ps1 b/Tests/Unit/MSFT_xDnsRecord.Tests.ps1 index 29e444de..c7ac8c79 100644 --- a/Tests/Unit/MSFT_xDnsRecord.Tests.ps1 +++ b/Tests/Unit/MSFT_xDnsRecord.Tests.ps1 @@ -1,21 +1,19 @@ -$Global:DSCModuleName = 'xDnsServer' # Example xNetworking -$Global:DSCResourceName = 'MSFT_xDnsRecord' # Example MSFT_xFirewall +$script:DSCModuleName = 'xDnsServer' +$script:DSCResourceName = 'MSFT_xDnsRecord' #region HEADER -[String] $moduleRoot = Split-Path -Parent (Split-Path -Parent (Split-Path -Parent $Script:MyInvocation.MyCommand.Path)) -if ( (-not (Test-Path -Path (Join-Path -Path $moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` - (-not (Test-Path -Path (Join-Path -Path $moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) +$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 $moduleRoot -ChildPath '\DSCResource.Tests\')) + & git @('clone', 'https://github.com/PowerShell/DscResource.Tests.git', (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests')) } -else -{ - & git @('-C',(Join-Path -Path $moduleRoot -ChildPath '\DSCResource.Tests\'),'pull') -} -Import-Module (Join-Path -Path $moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1') -Force + +Import-Module -Name (Join-Path -Path $script:moduleRoot -ChildPath (Join-Path -Path 'DSCResource.Tests' -ChildPath 'TestHelper.psm1')) -Force + $TestEnvironment = Initialize-TestEnvironment ` - -DSCModuleName $Global:DSCModuleName ` - -DSCResourceName $Global:DSCResourceName ` + -DSCModuleName $script:DSCModuleName ` + -DSCResourceName $script:DSCResourceName ` -TestType Unit #endregion @@ -24,149 +22,182 @@ try { #region Pester Tests - InModuleScope $Global:DSCResourceName { + InModuleScope $script:DSCResourceName { #region Pester Test Initialization - $testPresentParams = @{ - Name = "test" - Zone = "contoso.com" - Target = "192.168.0.1" - Type = "ARecord" - DnsServer = "localhost" - Ensure = "Present" - } - $testAbsentParams = @{ - Name = $testPresentParams.Name - Zone = $testPresentParams.Zone - Target = $testPresentParams.Target - Type = $testPresentParams.Type - DnsServer = $testPresentParams.DnsServer - Ensure = "Absent" - } - $fakeDnsServerResourceRecord = @{ - HostName = $testPresentParams.Name; - RecordType = 'A' - DnsServer = $testPresentParams.DnsServer - TimeToLive = '01:00:00' - RecordData = @{ - IPv4Address = @{ - IPAddressToString = $testPresentParams.Target + $dnsRecordsToTest = @( + @{ + TestParameters = @{ + Name = 'test' + Zone = 'contoso.com' + Target = '192.168.0.1' + Type = 'ARecord' + DnsServer = 'localhost' + Ensure = 'Present' + } + MockRecord = @{ + HostName = 'test' + RecordType = 'A' + DnsServer = 'localhost' + TimeToLive = '01:00:00' + RecordData = @{ + IPv4Address = @{ + IPAddressToString = '192.168.0.1' + } + } } } - } + @{ + TestParameters = @{ + Name = '123' + Target = 'TestA.contoso.com' + Zone = '0.168.192.in-addr.arpa' + Type = 'PTR' + DnsServer = 'localhost' + Ensure = 'Present' + } + MockRecord = @{ + HostName = 'test' + RecordType = 'PTR' + DnsServer = 'localhost' + TimeToLive = '01:00:00' + RecordData = @{ + PtrDomainName = '192.168.0.1' + } + } + } + ) #endregion #region Function Get-TargetResource - Describe "$($Global:DSCResourceName)\Get-TargetResource" { - - It "Returns Ensure is Present when DNS record exists" { - Mock Get-DnsServerResourceRecord { return $fakeDnsServerResourceRecord } - (Get-TargetResource @testPresentParams).Ensure | Should Be 'Present' - } + Describe "MSFT_xDnsRecord\Get-TargetResource" { + foreach ($dnsRecord in $dnsRecordsToTest) + { + Context "When managing $($dnsRecord.TestParameters.Type) type DNS record" { + $presentParameters = $dnsRecord.TestParameters + + It "Should return Ensure is Present when DNS record exists" { + Mock -CommandName Get-DnsServerResourceRecord -MockWith { return $dnsRecord.MockRecord } + (Get-TargetResource @presentParameters).Ensure | Should Be 'Present' + } - It "Returns Ensure is Absent when DNS record does not exist" { - Mock Get-DnsServerResourceRecord { return $null } - (Get-TargetResource @testPresentParams).Ensure | Should Be 'Absent' - } - + It "Should returns Ensure is Absent when DNS record does not exist" { + Mock -CommandName Get-DnsServerResourceRecord -MockWith { return $null } + (Get-TargetResource @presentParameters).Ensure | Should Be 'Absent' + } + } + } } #endregion - #region Function Test-TargetResource - Describe "$($Global:DSCResourceName)\Test-TargetResource" { - - It "Fails when no DNS record exists and Ensure is Present" { - Mock Get-TargetResource { return $testAbsentParams } - Test-TargetResource @testPresentParams | Should Be $false - } - - It "Fails when a record exists, target does not match and Ensure is Present" { - Mock Get-TargetResource { - return @{ - Name = $testPresentParams.Name - Zone = $testPresentParams.Zone - Target = "192.168.0.10" - DnsServer = $testPresentParams.DnsServer - Ensure = $testPresentParams.Ensure + Describe "MSFT_xDnsRecord\Test-TargetResource" { + foreach ($dnsRecord in $dnsRecordsToTest) + { + Context "When managing $($dnsRecord.TestParameters.Type) type DNS record" { + $presentParameters = $dnsRecord.TestParameters + $absentParameters = $presentParameters.Clone() + $absentParameters['Ensure'] = 'Absent' + + It "Should fail when no DNS record exists and Ensure is Present" { + Mock -CommandName Get-TargetResource -MockWith { return $absentParameters } + Test-TargetResource @presentParameters | Should Be $false } - } - Test-TargetResource @testPresentParams | Should Be $false - } - - It "Fails when round-robin record exists, target does not match and Ensure is Present (Issue #23)" { - Mock Get-TargetResource { - return @{ - Name = $testPresentParams.Name - Zone = $testPresentParams.Zone - Target = @("192.168.0.10","192.168.0.11") - DnsServer = $testPresentParams.DnsServer - Ensure = $testPresentParams.Ensure + + It "Should fail when a record exists, target does not match and Ensure is Present" { + Mock -CommandName Get-TargetResource -MockWith { + return @{ + Name = $presentParameters.Name + Zone = $presentParameters.Zone + Target = "192.168.0.10" + DnsServer = $presentParameters.DnsServer + Ensure = $presentParameters.Ensure + } + } + Test-TargetResource @presentParameters | Should Be $false } - } - Test-TargetResource @testPresentParams | Should Be $false - } - - It "Fails when a record exists and Ensure is Absent" { - Mock Get-TargetResource { return $testPresentParams } - Test-TargetResource @testAbsentParams | Should Be $false - } - - It "Fails when round-robin record exists, and Ensure is Absent (Issue #23)" { - Mock Get-TargetResource { - return @{ - Name = $testPresentParams.Name - Zone = $testPresentParams.Zone - Target = @("192.168.0.1","192.168.0.2") - DnsServer = $testPresentParams.DnsServer - Ensure = $testPresentParams.Ensure + + It "Should fail when round-robin record exists, target does not match and Ensure is Present (Issue #23)" { + Mock -CommandName Get-TargetResource -MockWith { + return @{ + Name = $presentParameters.Name + Zone = $presentParameters.Zone + Target = @("192.168.0.10", "192.168.0.11") + DnsServer = $presentParameters.DnsServer + Ensure = $presentParameters.Ensure + } + } + Test-TargetResource @presentParameters | Should Be $false } - } - Test-TargetResource @testAbsentParams | Should Be $false - } - - It "Passes when record exists, target matches and Ensure is Present" { - Mock Get-TargetResource { return $testPresentParams } - Test-TargetResource @testPresentParams | Should Be $true - } - - It "Passes when round-robin record exists, target matches and Ensure is Present (Issue #23)" { - Mock Get-TargetResource { - return @{ - Name = $testPresentParams.Name - Zone = $testPresentParams.Zone - Target = @("192.168.0.1","192.168.0.2") - DnsServer = $testPresentParams.DnsServer - Ensure = $testPresentParams.Ensure + + It "Should fail when a record exists and Ensure is Absent" { + Mock -CommandName Get-TargetResource -MockWith { return $presentParameters } + Test-TargetResource @absentParameters | Should Be $false + } + + It "Should fail when round-robin record exists, and Ensure is Absent (Issue #23)" { + Mock -CommandName Get-TargetResource -MockWith { + return @{ + Name = $presentParameters.Name + Zone = $presentParameters.Zone + Target = @("192.168.0.1", "192.168.0.2") + DnsServer = $presentParameters.DnsServer + Ensure = $presentParameters.Ensure + } + } + Test-TargetResource @absentParameters | Should Be $false + } + + It "Should pass when record exists, target matches and Ensure is Present" { + Mock -CommandName Get-TargetResource -MockWith { return $presentParameters } + Test-TargetResource @presentParameters | Should Be $true + } + + It "Should pass when round-robin record exists, target matches and Ensure is Present (Issue #23)" { + Mock -CommandName Get-TargetResource -MockWith { + return @{ + Name = $presentParameters.Name + Zone = $presentParameters.Zone + Target = @($presentParameters.Target, "192.168.0.2") + DnsServer = $presentParameters.DnsServer + Ensure = $presentParameters.Ensure + } + } + Test-TargetResource @presentParameters | Should Be $true + } + + It "Should pass when record does not exist and Ensure is Absent" { + Mock -CommandName Get-TargetResource -MockWith { return $absentParameters } + Test-TargetResource @absentParameters | Should Be $true } } - Test-TargetResource @testPresentParams | Should Be $true - } - - It "Passes when record does not exist and Ensure is Absent" { - Mock Get-TargetResource { return $testAbsentParams } - Test-TargetResource @testAbsentParams | Should Be $true } } #endregion - #region Function Set-TargetResource - Describe "$($Global:DSCResourceName)\Set-TargetResource" { - - It "Calls Add-DnsServerResourceRecord in the set method when Ensure is Present" { - Mock Add-DnsServerResourceRecord { return $null } - Set-TargetResource @testPresentParams - Assert-MockCalled Add-DnsServerResourceRecord -Scope It - } - - It "Calls Remove-DnsServerResourceRecord in the set method when Ensure is Absent" { - Mock Remove-DnsServerResourceRecord { return $null } - Set-TargetResource @testAbsentParams - Assert-MockCalled Remove-DnsServerResourceRecord -Scope It + Describe "MSFT_xDnsRecord\Set-TargetResource" { + foreach ($dnsRecord in $dnsRecordsToTest) + { + $presentParameters = $dnsRecord.TestParameters + $absentParameters = $presentParameters.Clone() + $absentParameters['Ensure'] = 'Absent' + + Context "When managing $($dnsRecord.TestParameters.Type) type DNS record" { + It "Calls Add-DnsServerResourceRecord in the set method when Ensure is Present" { + Mock -CommandName Add-DnsServerResourceRecord + Set-TargetResource @presentParameters + Assert-MockCalled Add-DnsServerResourceRecord -Scope It + } + + It "Calls Remove-DnsServerResourceRecord in the set method when Ensure is Absent" { + Mock -CommandName Remove-DnsServerResourceRecord + Set-TargetResource @absentParameters + Assert-MockCalled Remove-DnsServerResourceRecord -Scope It + } + } } } #endregion - } #end InModuleScope } finally From adbb94a09c37f2977050f03d5ae1b8a8ebeda9d8 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Wed, 6 Jun 2018 12:18:51 +0200 Subject: [PATCH 6/7] Update change log (#75) --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 15e860ae..9d598b1c 100644 --- a/README.md +++ b/README.md @@ -164,8 +164,6 @@ Please check out common DSC Resources [contributing guidelines](https://github.c ### Unreleased -* Added Ptr record support to xDnsRecord - * Changes to xDnsServer * Updated appveyor.yml to use the default template and add CodeCov support ([issue #73](https://github.com/PowerShell/xActiveDirectory/issues/73)). @@ -177,6 +175,9 @@ Please check out common DSC Resources [contributing guidelines](https://github.c * Fix bug in Get-TargetResource that caused the Zone Name to be null ([issue #63](https://github.com/PowerShell/xDnsServer/issues/63)). [Brandon Padgett (@gerane)](https://github.com/gerane) +* Changes to xDnsRecord + * Added Ptr record support (partly resolves issue #34). + [Reggie Gibson (@regedit32)](https://github.com/regedit32) ### 1.10.0.0 From 1262d5dcac93b13e075a230be640cc0227db86dd Mon Sep 17 00:00:00 2001 From: Katie Keim Date: Wed, 13 Jun 2018 09:44:19 -0700 Subject: [PATCH 7/7] Releasing version 1.11.0.0 --- README.md | 2 ++ xDnsServer.psd1 | 25 ++++++++++++++++--------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 9d598b1c..9b12a8ac 100644 --- a/README.md +++ b/README.md @@ -164,6 +164,8 @@ Please check out common DSC Resources [contributing guidelines](https://github.c ### Unreleased +### 1.11.0.0 + * Changes to xDnsServer * Updated appveyor.yml to use the default template and add CodeCov support ([issue #73](https://github.com/PowerShell/xActiveDirectory/issues/73)). diff --git a/xDnsServer.psd1 b/xDnsServer.psd1 index dad89611..b81cf808 100644 --- a/xDnsServer.psd1 +++ b/xDnsServer.psd1 @@ -1,6 +1,6 @@ @{ # Version number of this module. -moduleVersion = '1.10.0.0' +moduleVersion = '1.11.0.0' # ID used to uniquely identify this module GUID = '5f70e6a1-f1b2-4ba0-8276-8967d43a7ec2' @@ -47,14 +47,20 @@ PrivateData = @{ # IconUri = '' # ReleaseNotes of this module - ReleaseNotes = '* Changes to xDnsServerADZone - * Fixed bug introduced by [49](https://github.com/PowerShell/xDnsServer/pull/49). Previously, CimSessions were always used - regardless of connecting to a remote machine or the local machine. Now CimSessions are only utilized when a computername or - computername and credential are used. ([issue 53](https://github.com/PowerShell/xDnsServer/issues/53)). - [Michael Fyffe (@TraGicCode)](https://github.com/TraGicCode) -* Fixed all PSSA rule warnings. [Michael Fyffe (@TraGicCode)](https://github.com/TraGicCode) -* Fix DsAvailable key missing ([66](https://github.com/PowerShell/xDnsServer/issues/66)). - [Claudio Spizzi (@claudiospizzi)](https://github.com/claudiospizzi) + ReleaseNotes = '* Changes to xDnsServer + * Updated appveyor.yml to use the default template and add CodeCov support + ([issue 73](https://github.com/PowerShell/xActiveDirectory/issues/73)). + * Adding a Branches section to the README.md with Codecov badges for both + master and dev branch ([issue 73](https://github.com/PowerShell/xActiveDirectory/issues/73)). + * Updated description of resource module in README.md. +* Added resource xDnsServerZoneAging. [Claudio Spizzi (@claudiospizzi)](https://github.com/claudiospizzi) +* Changes to xDnsServerPrimaryZone + * Fix bug in Get-TargetResource that caused the Zone Name to be null + ([issue 63](https://github.com/PowerShell/xDnsServer/issues/63)). + [Brandon Padgett (@gerane)](https://github.com/gerane) +* Changes to xDnsRecord + * Added Ptr record support (partly resolves issue 34). + [Reggie Gibson (@regedit32)](https://github.com/regedit32) ' @@ -68,3 +74,4 @@ PrivateData = @{ +