-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add validation of CollectionName length 1-15 characters and tests #15
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
263 changes: 133 additions & 130 deletions
263
DSCResources/MSFT_xRDRemoteApp/MSFT_xRDRemoteApp.psm1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,130 +1,133 @@ | ||
Import-Module -Name "$PSScriptRoot\..\..\xRemoteDesktopSessionHostCommon.psm1" | ||
if (!(Test-xRemoteDesktopSessionHostOsRequirement)) { Throw "The minimum OS requirement was not met."} | ||
Import-Module RemoteDesktop | ||
$localhost = [System.Net.Dns]::GetHostByName((hostname)).HostName | ||
|
||
####################################################################### | ||
# The Get-TargetResource cmdlet. | ||
####################################################################### | ||
function Get-TargetResource | ||
{ | ||
[CmdletBinding()] | ||
[OutputType([System.Collections.Hashtable])] | ||
param | ||
( | ||
[parameter(Mandatory)] | ||
[string] $CollectionName = "Tenant", | ||
[parameter(Mandatory)] | ||
[string] $DisplayName = "Calculator", | ||
[parameter(Mandatory)] | ||
[string] $FilePath = "C:\Windows\System32\calc.exe", | ||
[parameter(Mandatory)] | ||
[string] $Alias = "calc", | ||
[string] $FileVirtualPath, | ||
[string] $FolderName, | ||
[string] $CommandLineSetting, | ||
[string] $RequiredCommandLine, | ||
[uint32] $IconIndex, | ||
[string] $IconPath, | ||
[string] $UserGroups, | ||
[boolean] $ShowInWebAccess | ||
) | ||
Write-Verbose "Getting published RemoteApp program $DisplayName, if one exists." | ||
$CollectionName = Get-RDSessionCollection | % {Get-RDSessionHost $_.CollectionName} | ? {$_.SessionHost -ieq $localhost} | % {$_.CollectionName} | ||
$remoteApp = Get-RDRemoteApp -CollectionName $CollectionName -DisplayName $DisplayName -Alias $Alias | ||
|
||
@{ | ||
"CollectionName" = $remoteApp.CollectionName; | ||
"DisplayName" = $remoteApp.DisplayName; | ||
"FilePath" = $remoteApp.FilePath; | ||
"Alias" = $remoteApp.Alias; | ||
"FileVirtualPath" = $remoteApp.FileVirtualPath; | ||
"FolderName" = $remoteApp.FolderName; | ||
"CommandLineSetting" = $remoteApp.CommandLineSetting; | ||
"RequiredCommandLine" = $remoteApp.RequiredCommandLine; | ||
"IconIndex" = $remoteApp.IconIndex; | ||
"IconPath" = $remoteApp.IconPath; | ||
"UserGroups" = $remoteApp.UserGroups; | ||
"ShowInWebAccess" = $remoteApp.ShowInWebAccess; | ||
} | ||
} | ||
|
||
|
||
######################################################################## | ||
# The Set-TargetResource cmdlet. | ||
######################################################################## | ||
function Set-TargetResource | ||
|
||
{ | ||
[CmdletBinding()] | ||
param | ||
( | ||
[parameter(Mandatory)] | ||
[string] $CollectionName, | ||
[parameter(Mandatory)] | ||
[string] $DisplayName, | ||
[parameter(Mandatory)] | ||
[string] $FilePath, | ||
[parameter(Mandatory)] | ||
[string] $Alias, | ||
[string] $FileVirtualPath, | ||
[string] $FolderName, | ||
[string] $CommandLineSetting, | ||
[string] $RequiredCommandLine, | ||
[uint32] $IconIndex, | ||
[string] $IconPath, | ||
[string] $UserGroups, | ||
[boolean] $ShowInWebAccess | ||
) | ||
Write-Verbose "Making updates to RemoteApp." | ||
$CollectionName = Get-RDSessionCollection | % {Get-RDSessionHost $_.CollectionName} | ? {$_.SessionHost -ieq $localhost} | % {$_.CollectionName} | ||
$PSBoundParameters.collectionName = $CollectionName | ||
if (!$(Get-RDRemoteApp -Alias $Alias)) { | ||
New-RDRemoteApp @PSBoundParameters | ||
} | ||
else { | ||
Set-RDRemoteApp @PSBoundParameters | ||
} | ||
} | ||
|
||
|
||
####################################################################### | ||
# The Test-TargetResource cmdlet. | ||
####################################################################### | ||
function Test-TargetResource | ||
{ | ||
[CmdletBinding()] | ||
[OutputType([System.Boolean])] | ||
param | ||
( | ||
[parameter(Mandatory)] | ||
[string] $CollectionName, | ||
[parameter(Mandatory)] | ||
[string] $DisplayName, | ||
[parameter(Mandatory)] | ||
[string] $FilePath, | ||
[parameter(Mandatory)] | ||
[string] $Alias, | ||
[string] $FileVirtualPath, | ||
[string] $FolderName, | ||
[string] $CommandLineSetting, | ||
[string] $RequiredCommandLine, | ||
[uint32] $IconIndex, | ||
[string] $IconPath, | ||
[string] $UserGroups, | ||
[boolean] $ShowInWebAccess | ||
) | ||
Write-Verbose "Testing if RemoteApp is published." | ||
$collectionName = Get-RDSessionCollection | % {Get-RDSessionHost $_.CollectionName} | ? {$_.SessionHost -ieq $localhost} | % {$_.CollectionName} | ||
$PSBoundParameters.Remove("Verbose") | out-null | ||
$PSBoundParameters.Remove("Debug") | out-null | ||
$PSBoundParameters.Remove("ConnectionBroker") | out-null | ||
$Check = $true | ||
|
||
$Get = Get-TargetResource -CollectionName $CollectionName -DisplayName $DisplayName -FilePath $FilePath -Alias $Alias | ||
$PSBoundParameters.keys | % {if ($PSBoundParameters[$_] -ne $Get[$_]) {$Check = $false} } | ||
$Check | ||
} | ||
|
||
Export-ModuleMember -Function *-TargetResource | ||
|
||
Import-Module -Name "$PSScriptRoot\..\..\xRemoteDesktopSessionHostCommon.psm1" | ||
if (!(Test-xRemoteDesktopSessionHostOsRequirement)) { Throw "The minimum OS requirement was not met."} | ||
Import-Module RemoteDesktop | ||
$localhost = [System.Net.Dns]::GetHostByName((hostname)).HostName | ||
|
||
####################################################################### | ||
# The Get-TargetResource cmdlet. | ||
####################################################################### | ||
function Get-TargetResource | ||
{ | ||
[CmdletBinding()] | ||
[OutputType([System.Collections.Hashtable])] | ||
param | ||
( | ||
[parameter(Mandatory)] | ||
[ValidateLength(1,15)] | ||
[string] $CollectionName = "Tenant", | ||
[parameter(Mandatory)] | ||
[string] $DisplayName = "Calculator", | ||
[parameter(Mandatory)] | ||
[string] $FilePath = "C:\Windows\System32\calc.exe", | ||
[parameter(Mandatory)] | ||
[string] $Alias = "calc", | ||
[string] $FileVirtualPath, | ||
[string] $FolderName, | ||
[string] $CommandLineSetting, | ||
[string] $RequiredCommandLine, | ||
[uint32] $IconIndex, | ||
[string] $IconPath, | ||
[string] $UserGroups, | ||
[boolean] $ShowInWebAccess | ||
) | ||
Write-Verbose "Getting published RemoteApp program $DisplayName, if one exists." | ||
$CollectionName = Get-RDSessionCollection | % {Get-RDSessionHost $_.CollectionName} | ? {$_.SessionHost -ieq $localhost} | % {$_.CollectionName} | ||
$remoteApp = Get-RDRemoteApp -CollectionName $CollectionName -DisplayName $DisplayName -Alias $Alias | ||
|
||
@{ | ||
"CollectionName" = $remoteApp.CollectionName; | ||
"DisplayName" = $remoteApp.DisplayName; | ||
"FilePath" = $remoteApp.FilePath; | ||
"Alias" = $remoteApp.Alias; | ||
"FileVirtualPath" = $remoteApp.FileVirtualPath; | ||
"FolderName" = $remoteApp.FolderName; | ||
"CommandLineSetting" = $remoteApp.CommandLineSetting; | ||
"RequiredCommandLine" = $remoteApp.RequiredCommandLine; | ||
"IconIndex" = $remoteApp.IconIndex; | ||
"IconPath" = $remoteApp.IconPath; | ||
"UserGroups" = $remoteApp.UserGroups; | ||
"ShowInWebAccess" = $remoteApp.ShowInWebAccess; | ||
} | ||
} | ||
|
||
|
||
######################################################################## | ||
# The Set-TargetResource cmdlet. | ||
######################################################################## | ||
function Set-TargetResource | ||
|
||
{ | ||
[CmdletBinding()] | ||
param | ||
( | ||
[parameter(Mandatory)] | ||
[ValidateLength(1,15)] | ||
[string] $CollectionName, | ||
[parameter(Mandatory)] | ||
[string] $DisplayName, | ||
[parameter(Mandatory)] | ||
[string] $FilePath, | ||
[parameter(Mandatory)] | ||
[string] $Alias, | ||
[string] $FileVirtualPath, | ||
[string] $FolderName, | ||
[string] $CommandLineSetting, | ||
[string] $RequiredCommandLine, | ||
[uint32] $IconIndex, | ||
[string] $IconPath, | ||
[string] $UserGroups, | ||
[boolean] $ShowInWebAccess | ||
) | ||
Write-Verbose "Making updates to RemoteApp." | ||
$CollectionName = Get-RDSessionCollection | % {Get-RDSessionHost $_.CollectionName} | ? {$_.SessionHost -ieq $localhost} | % {$_.CollectionName} | ||
$PSBoundParameters.collectionName = $CollectionName | ||
if (!$(Get-RDRemoteApp -Alias $Alias)) { | ||
New-RDRemoteApp @PSBoundParameters | ||
} | ||
else { | ||
Set-RDRemoteApp @PSBoundParameters | ||
} | ||
} | ||
|
||
|
||
####################################################################### | ||
# The Test-TargetResource cmdlet. | ||
####################################################################### | ||
function Test-TargetResource | ||
{ | ||
[CmdletBinding()] | ||
[OutputType([System.Boolean])] | ||
param | ||
( | ||
[parameter(Mandatory)] | ||
[ValidateLength(1,15)] | ||
[string] $CollectionName, | ||
[parameter(Mandatory)] | ||
[string] $DisplayName, | ||
[parameter(Mandatory)] | ||
[string] $FilePath, | ||
[parameter(Mandatory)] | ||
[string] $Alias, | ||
[string] $FileVirtualPath, | ||
[string] $FolderName, | ||
[string] $CommandLineSetting, | ||
[string] $RequiredCommandLine, | ||
[uint32] $IconIndex, | ||
[string] $IconPath, | ||
[string] $UserGroups, | ||
[boolean] $ShowInWebAccess | ||
) | ||
Write-Verbose "Testing if RemoteApp is published." | ||
$collectionName = Get-RDSessionCollection | % {Get-RDSessionHost $_.CollectionName} | ? {$_.SessionHost -ieq $localhost} | % {$_.CollectionName} | ||
$PSBoundParameters.Remove("Verbose") | out-null | ||
$PSBoundParameters.Remove("Debug") | out-null | ||
$PSBoundParameters.Remove("ConnectionBroker") | out-null | ||
$Check = $true | ||
|
||
$Get = Get-TargetResource -CollectionName $CollectionName -DisplayName $DisplayName -FilePath $FilePath -Alias $Alias | ||
$PSBoundParameters.keys | % {if ($PSBoundParameters[$_] -ne $Get[$_]) {$Check = $false} } | ||
$Check | ||
} | ||
|
||
Export-ModuleMember -Function *-TargetResource | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Import is not a good place to throw an error. It will basically be hidden. This should be turned into a function and called at the beginning of test set and get
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TravisEz13 You wrote that code and committed it on Feb 23, 2016. It is not part of the code I wrote. It is also not a test, it appears to be part of the functional code to block the resource being deployed on an OS that does not support the feature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, we can just file an issue for it.
This change involves a formatting change. Can you submit the formatting change separately from the code changes. I cannot tell what changed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
filed #16