Skip to content

Commit 1728bdb

Browse files
author
tysonjhayes
committed
Merge branch 'dcrreynolds-master' into dev
2 parents d715779 + ae137bb commit 1728bdb

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

DSCResources/MSFT_xComputer/MSFT_xComputer.psm1

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ function Get-TargetResource
99
param
1010
(
1111
[parameter(Mandatory)]
12+
[ValidateLength(1,15)]
13+
[ValidateScript({$_ -inotmatch'[\/\\:*?"<>|]' })]
1214
[string] $Name,
1315

1416
[string] $DomainName,
@@ -43,6 +45,8 @@ function Set-TargetResource
4345
param
4446
(
4547
[parameter(Mandatory)]
48+
[ValidateLength(1,15)]
49+
[ValidateScript({$_ -inotmatch'[\/\\:*?"<>|]' })]
4650
[string] $Name,
4751

4852
[string] $DomainName,
@@ -197,6 +201,8 @@ function Test-TargetResource
197201
param
198202
(
199203
[parameter(Mandatory)]
204+
[ValidateLength(1,15)]
205+
[ValidateScript({$_ -inotmatch'[\/\\:*?"<>|]' })]
200206
[string] $Name,
201207

202208
[string] $JoinOU,
@@ -209,6 +215,8 @@ function Test-TargetResource
209215

210216
[string] $WorkGroupName
211217
)
218+
219+
Write-Verbose -Message "Validate desired Name is a valid name"
212220

213221
Write-Verbose -Message "Checking if computer name is $Name"
214222
if ($Name -ne $env:COMPUTERNAME) {return $false}

Tests/xComputermanagement.Tests.ps1

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ InModuleScope MSFT_xComputer {
8282
Mock GetComputerDomain {'contoso.com'}
8383
Test-TargetResource -Name $Env:ComputerName -WorkGroupName 'Contoso' -Credential $Credential -UnjoinCredential $Credential | Should Be $false
8484
}
85+
It 'Throws if name is to long' {
86+
{Test-TargetResource -Name "ThisNameIsTooLong"} | Should Throw
87+
}
88+
It 'Throws if name contains illigal characters' {
89+
{Test-TargetResource -Name "ThisIsBad<>"} | Should Throw
90+
}
8591

8692
}
8793
Context Get-TargetResource {
@@ -93,6 +99,12 @@ InModuleScope MSFT_xComputer {
9399
$Result.GetType().Fullname | Should Be 'System.Collections.Hashtable'
94100
$Result.Keys | Should Be @('Name', 'DomainName', 'JoinOU', 'CurrentOU', 'Credential', 'UnjoinCredential', 'WorkGroupName')
95101
}
102+
It 'Throws if name is to long' {
103+
{Get-TargetResource -Name "ThisNameIsTooLong"} | Should Throw
104+
}
105+
It 'Throws if name contains illigal characters' {
106+
{Get-TargetResource -Name "ThisIsBad<>"} | Should Throw
107+
}
96108
}
97109
Context Set-TargetResource {
98110
Mock Rename-Computer {}
@@ -196,6 +208,12 @@ InModuleScope MSFT_xComputer {
196208
Assert-MockCalled -CommandName Rename-Computer -Exactly 1 -Scope It
197209
Assert-MockCalled -CommandName Add-Computer -Exactly 0 -Scope It
198210
}
211+
It 'Throws if name is to long' {
212+
{Set-TargetResource -Name "ThisNameIsTooLong"} | Should Throw
213+
}
214+
It 'Throws if name contains illigal characters' {
215+
{Set-TargetResource -Name "ThisIsBad<>"} | Should Throw
216+
}
199217
}
200218
}
201219
}

0 commit comments

Comments
 (0)