Skip to content

Commit

Permalink
Merge pull request #21 from PlagueHO/Support-v4-and-v6-DNS-Per-Interface
Browse files Browse the repository at this point in the history
Added support for setting DNS for both IPv4 and IPv6 on the same Interface
  • Loading branch information
Tyson J. Hayes committed Sep 10, 2015
2 parents 3b8b296 + 8298620 commit 687dd8a
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 10 deletions.
12 changes: 9 additions & 3 deletions DSCResources/MSFT_xDNSServerAddress/MSFT_xDNSServerAddress.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
######################################################################################
function Get-TargetResource
{
[OutputType([System.Collections.Hashtable])]
param
(
[Parameter(Mandatory)]
Expand All @@ -21,8 +22,9 @@ function Get-TargetResource
[ValidateNotNullOrEmpty()]
[String]$InterfaceAlias,

[Parameter(Mandatory)]
[ValidateSet("IPv4", "IPv6")]
[String]$AddressFamily = "IPv4"
[String]$AddressFamily
)


Expand Down Expand Up @@ -52,8 +54,9 @@ function Set-TargetResource
[ValidateNotNullOrEmpty()]
[String]$InterfaceAlias,

[Parameter(Mandatory)]
[ValidateSet("IPv4", "IPv6")]
[String]$AddressFamily = "IPv4"
[String]$AddressFamily
)

ValidateProperties @PSBoundParameters -Apply
Expand All @@ -65,6 +68,7 @@ function Set-TargetResource
######################################################################################
function Test-TargetResource
{
[OutputType([System.Boolean])]
param
(
[Parameter(Mandatory)]
Expand All @@ -75,8 +79,9 @@ function Test-TargetResource
[ValidateNotNullOrEmpty()]
[String]$InterfaceAlias,

[Parameter(Mandatory)]
[ValidateSet("IPv4", "IPv6")]
[String]$AddressFamily = "IPv4"
[String]$AddressFamily
)

ValidateProperties @PSBoundParameters
Expand All @@ -99,6 +104,7 @@ function ValidateProperties
[ValidateNotNullOrEmpty()]
[String]$InterfaceAlias,

[Parameter(Mandatory)]
[ValidateSet("IPv4", "IPv6")]
[String]$AddressFamily,

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[ClassVersion("1.0.0"), FriendlyName("xDNSServerAddress")]
class MSFT_xDNSServerAddress : OMI_BaseResource
{
[Required] string Address[];
[Key] string InterfaceAlias;
[Write,ValueMap{"IPv4", "IPv6"},Values{"IPv4", "IPv6"}] string AddressFamily;
};
[ClassVersion("1.0.0"), FriendlyName("xDNSServerAddress")]
class MSFT_xDNSServerAddress : OMI_BaseResource
{
[Required] string Address[];
[Key] string InterfaceAlias;
[Key,Write,ValueMap{"IPv4", "IPv6"},Values{"IPv4", "IPv6"}] string AddressFamily;
};
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ Please check out common DSC Resources [contributing guidelines](https://github.c

## Versions

### Unreleased
* Update to xDNSServerAddress to allow both IPv4 and IPv6 DNS addresses to be assigned to an
interface. xDNSServerAddress AddressFamily parameter has been changed to mandatory.

### 2.2.0.0
* Changes in xFirewall resources to meet Test-xDscResource criteria

Expand Down
100 changes: 100 additions & 0 deletions Tests/MSFT_xDNSServerAddress.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
$here = Split-Path -Parent $MyInvocation.MyCommand.Path

if (Get-Module MSFT_xDNSServerAddress -All)
{
Get-Module MSFT_xDNSServerAddress -All | Remove-Module
}

Import-Module -Name $PSScriptRoot\..\DSCResources\MSFT_xDNSServerAddress -Force -DisableNameChecking

InModuleScope MSFT_xDNSServerAddress {

Describe 'Get-TargetResource' {

#region Mocks
Mock Get-DnsClientServerAddress -MockWith {

[PSCustomObject]@{
ServerAddresses = '192.168.0.1'
InterfaceAlias = 'Ethernet'
AddressFamily = 'IPv4'
}
}
#endregion

Context 'comparing IPAddress' {
It 'should return true' {

$Splat = @{
Address = '192.168.0.1'
InterfaceAlias = 'Ethernet'
AddressFamily = 'IPv4'
}
$Result = Get-TargetResource @Splat
$Result.IPAddress | Should Be $Splat.IPAddress
}
}
}


Describe 'ValidateProperties' {

#region Mocks
Mock Get-DnsClientServerAddress -MockWith {

[PSCustomObject]@{
ServerAddresses = '192.168.0.1'
InterfaceAlias = 'Ethernet'
AddressFamily = 'IPv4'
}
}

Mock Set-DnsClientServerAddress -MockWith {}
#endregion

Context 'invoking without -Apply switch' {

It 'should be $false' {
$Splat = @{
Address = '10.0.0.2'
InterfaceAlias = 'Ethernet'
AddressFamily = 'IPv4'
}
$Result = ValidateProperties @Splat
$Result | Should Be $false
}

It 'should be $true' {
$Splat = @{
Address = '192.168.0.1'
InterfaceAlias = 'Ethernet'
AddressFamily = 'IPv4'
}
$Result = ValidateProperties @Splat
$Result | Should Be $true
}

It 'should call Get-DnsClientServerAddress once' {
Assert-MockCalled -commandName Get-DnsClientServerAddress
}
}

Context 'invoking with -Apply switch' {

It 'should be $null' {
$Splat = @{
Address = '10.0.0.2'
InterfaceAlias = 'Ethernet'
AddressFamily = 'IPv4'
}
$Result = ValidateProperties @Splat -Apply
$Result | Should BeNullOrEmpty
}

It 'should call all the mocks' {
Assert-MockCalled -commandName Get-DnsClientServerAddress
Assert-MockCalled -commandName Set-DnsClientServerAddress
}
}
}
}

0 comments on commit 687dd8a

Please sign in to comment.