FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix(repository:) Add input validation for `GetOperation` by Gijsreyn · Pull Request #2002 · PowerShell/PSResourceGet · GitHub

Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .ps1  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
5 changes: 5 additions & 0 deletions src/dsc/psresourceget.ps1
This file contains hidden or 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
Expand Up @@ -376,6 +376,11 @@ function GetOperation {
[string]$ResourceType
)

if ([string]::IsNullOrEmpty($stdinput)) {
Comment thread
Gijsreyn marked this conversation as resolved.
Write-Trace -level error -message "Get operation requires --input with the resource properties. No input was provided."
exit [ExitCode]::Error
}

$inputObj = $stdinput | ConvertFrom-Json -ErrorAction Stop

Write-Trace -message "Starting Get operation for ResourceType: $ResourceType" -level trace
Expand Down
10 changes: 10 additions & 0 deletions test/DscResource/PSResourceGetDSCResource.Tests.ps1
This file contains hidden or 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
Expand Up @@ -142,6 +142,16 @@ Describe 'Repository Resource Tests' -Tags 'CI' {
}
}

It 'Get operation without --input exits with a non-zero code and does not produce an unhandled exception' {
$output = & $script:dscExe resource get --resource Microsoft.PowerShell.PSResourceGet/Repository -o json 2>&1
$outputText = $output | Out-String
$LASTEXITCODE | Should -Not -Be 0
$outputText | Should -Match '--input'
$outputText | Should -Match 'required'
$outputText | Should -Not -Match 'Cannot bind argument to parameter'
$outputText | Should -Not -Match 'Unhandled exception'
}

It 'Can delete a Repository resource instance' {
# First, create a repository to delete
Register-PSResourceRepository -Name 'TestRepoToDelete' -uri 'https://www.doesnotexist.com' -ErrorAction SilentlyContinue -APIVersion Local
Expand Down

Back | FazBrowse Home | New Git URL