Skip to content

Commit a31a756

Browse files
authored
Fix for Issue with Local testing on systems with non en-us Culture (#285)
1 parent f12ae73 commit a31a756

File tree

3 files changed

+19
-34
lines changed

3 files changed

+19
-34
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
5757
- DSC_DnsServerClientSubnet
5858
- Fixed wrong SYNAPSIS.
5959
- Pester tests
60+
- Fixed issue with local testing on systems with non en-US Culture in DSC_DnsServerRootHint
61+
unit test. It fixes [[Issue #283](https://github.com/dsccommunity/DnsServerDsc/issues/283)].
6062
- Fixed a typo in stream suppression causing Error stream to be suppressed when
6163
it was supposed not to be ([issue #274](https://github.com/dsccommunity/DnsServerDsc/issues/274)).
6264
- Fixed Unit test for DSC_DnsRecordPtr DSC resource. -ErrorMassage changed to -ErrorId 'InvalidCastParseTargetInvocation'.

source/Classes/020.DnsRecordPtr.ps1

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ class DnsRecordPtr : DnsRecordBase
170170
}
171171

172172
# Translate the IP address to the reverse notation used by the DNS server
173-
hidden [System.String] getReverseNotation([System.Net.IpAddress] $ipAddressObj)
173+
hidden [System.String] getReverseNotation([System.Net.IpAddress] $IPAddressObj)
174174
{
175175
$significantData = [System.Collections.ArrayList]::New()
176176

@@ -197,8 +197,11 @@ class DnsRecordPtr : DnsRecordBase
197197
}
198198

199199
# Determine the record host name
200-
hidden [System.String] getRecordHostName([System.Net.IpAddress] $ipAddressObj)
200+
hidden [System.String] getRecordHostName([System.String] $IPAddress)
201201
{
202+
Assert-IPAddress -Address $IPAddress
203+
$ipAddressObj = [System.Net.IpAddress] $IPAddress
204+
202205
$reverseLookupAddressComponent = ''
203206

204207
switch ($ipAddressObj.AddressFamily)

tests/Unit/Classes/DnsRecordPtr.Tests.ps1

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ Describe 'Testing DnsRecordPtr Get Method' -Tag 'Get', 'DnsRecord', 'DnsRecordPt
103103
Mock -CommandName Get-DnsServerResourceRecord -MockWith {
104104
Write-Verbose -Message 'Mock Get-DnsServerResourceRecord Called' -Verbose
105105
}
106+
Mock -CommandName Assert-IPAddress
106107
}
107108

108109
It 'Should return the state as absent' {
@@ -114,7 +115,8 @@ Describe 'Testing DnsRecordPtr Get Method' -Tag 'Get', 'DnsRecord', 'DnsRecordPt
114115
$currentState.Ensure | Should -Be 'Absent'
115116
}
116117

117-
Should -Invoke Get-DnsServerResourceRecord -Exactly -Times 1 -Scope It
118+
Should -Invoke -CommandName Assert-IPAddress -Exactly -Times 1 -Scope It
119+
Should -Invoke -CommandName Get-DnsServerResourceRecord -Exactly -Times 1 -Scope It
118120
}
119121

120122
It 'Should return the same values as present in Key properties' {
@@ -127,6 +129,9 @@ Describe 'Testing DnsRecordPtr Get Method' -Tag 'Get', 'DnsRecord', 'DnsRecordPt
127129
$getMethodResourceResult.IpAddress | Should -Be $script:instanceDesiredState.IpAddress
128130
$getMethodResourceResult.Name | Should -Be $script:instanceDesiredState.Name
129131
}
132+
133+
Should -Invoke -CommandName Assert-IPAddress -Exactly -Times 1 -Scope It
134+
Should -Invoke -CommandName Get-DnsServerResourceRecord -Exactly -Times 1 -Scope It
130135
}
131136

132137
It 'Should return $false or $null respectively for the rest of the non-key properties' {
@@ -147,20 +152,21 @@ Describe 'Testing DnsRecordPtr Get Method' -Tag 'Get', 'DnsRecord', 'DnsRecordPt
147152

148153
Mock -CommandName Get-DnsServerResourceRecord -MockWith {
149154
Write-Verbose -Message 'Mock Get-DnsServerResourceRecord Called' -Verbose
150-
151155
return Import-Clixml -Path "$($mockInstancesPath)\..\MockObjects\PtrRecordInstance.xml"
152156
}
157+
Mock -CommandName Assert-IPAddress
153158
}
154159

155160
It 'Should return the state as present' {
156161
InModuleScope -ScriptBlock {
157162
Set-StrictMode -Version 1.0
158163

159164
$currentState = $script:instanceDesiredState.Get()
160-
161-
Should -Invoke Get-DnsServerResourceRecord -Exactly -Times 1 -Scope It
162165
$currentState.Ensure | Should -Be 'Present'
163166
}
167+
168+
Should -Invoke -CommandName Assert-IPAddress -Exactly -Times 1 -Scope It
169+
Should -Invoke -CommandName Get-DnsServerResourceRecord -Exactly -Times 1 -Scope It
164170
}
165171

166172
It 'Should return the same values as present in Key properties' {
@@ -172,6 +178,8 @@ Describe 'Testing DnsRecordPtr Get Method' -Tag 'Get', 'DnsRecord', 'DnsRecordPt
172178
$getMethodResourceResult.IpAddress | Should -Be $script:instanceDesiredState.IpAddress
173179
$getMethodResourceResult.Name | Should -Be $script:instanceDesiredState.Name
174180
}
181+
182+
Should -Invoke -CommandName Assert-IPAddress -Exactly -Times 1 -Scope It
175183
}
176184
}
177185
}
@@ -474,34 +482,6 @@ Describe 'Testing DnsRecordPtr Set Method' -Tag 'Set', 'DnsRecord', 'DnsRecordPt
474482
}
475483

476484
Describe 'Test bad inputs (both IPv4 and IPv6)' -Tag 'Test', 'DnsRecord', 'DnsRecordPtr' {
477-
It 'Throws when the IPv4 address is malformatted' {
478-
InModuleScope -ScriptBlock {
479-
Set-StrictMode -Version 1.0
480-
$malformattedIPv4State = [DnsRecordPtr] @{
481-
ZoneName = '0.168.192.in-addr.arpa'
482-
IpAddress = '192.168.0.DS9'
483-
Name = 'quarks.contoso.com'
484-
Ensure = 'Present'
485-
}
486-
487-
{ $malformattedIPv4State.Get() } | Should -Throw -ExpectedMessage ('*' + '"Cannot convert value "{0}" to type "System.Net.IPAddress". Error: "An invalid IP address was specified.""' -f $malformattedIPv4State.IpAddress)
488-
}
489-
}
490-
491-
It 'Throws when the IPv6 address is malformatted' {
492-
InModuleScope -ScriptBlock {
493-
Set-StrictMode -Version 1.0
494-
495-
$malformattedIPv6State = [DnsRecordPtr] @{
496-
ZoneName = '0.0.d.f.ip6.arpa'
497-
IpAddress = 'fd00::1::9'
498-
Name = 'quarks.contoso.com'
499-
Ensure = 'Present'
500-
}
501-
502-
{ $malformattedIPv6State.Get() } | Should -Throw -ExpectedMessage ('*' + '"Cannot convert value "{0}" to type "System.Net.IPAddress". Error: "An invalid IP address was specified.""' -f $malformattedIPv6State.IpAddress)
503-
}
504-
}
505485

506486
It 'Throws when placed in an incorrect IPv4 reverse lookup zone' {
507487
InModuleScope -ScriptBlock {

0 commit comments

Comments
 (0)