Skip to content
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 3 commits into from
Feb 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
263 changes: 133 additions & 130 deletions DSCResources/MSFT_xRDRemoteApp/MSFT_xRDRemoteApp.psm1
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."}
Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

filed #16

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

Loading