Get-ChocolateyWebFile should pass the Options parameter to Get-WebFileName and Get-WebHeaders #3191
Open
Description
Checklist
- I have verified this is the correct repository for opening this issue.
- I have verified no other issues exist related to my problem.
- I have verified this is not an issue for a specific package.
- I have verified this issue is not security related.
What You Are Seeing?
We use chocolatey on an Air-gapped network for which we upload the nuget packages to our Artifactory server. This server requires basic authentication to access any resources.
We modify the nuget packages install scripts so that calls to Install-Chocolateypackage
use the Options
parameter in which we add an Authorization Headers.
This works fine and downloads the packages correctly, however it triggers errors which could be avoided.
What is Expected?
No errors are generated when download packages using Authorization headers.
How Did You Get This To Happen?
- Modify a package to add the 'Options' parameter with and Authorization header
- Upload this package to a repository requiring basic auth
choco install <package>
System Details
- Operating System: 10.0.19045.0
- Windows PowerShell version: 5.1.19041.2673
- Chocolatey CLI Version: 2.0.0
- Chocolatey Licensed Extension version: N/A
- Chocolatey License type: N/A
- Terminal/Emulator: Microsoft Terminal
Installed Packages
N/A
Output Log
- Running Get-WebFileName -url <URL> -defaultName <NAME>
- Url request/response fialed - file name will be <NAME>: Exception calling "GetResponse" with "0" argument(s): "The remote servier returned an error: (401) Unauthorized."
- Running Get-WebHeaders -url <URL> -ErrorAction 'Stop'
- Setting the UserAgent to 'chocolatey command line'
- Request Header:
- 'Accept':'*/*'
- 'User-Agent':'chocolatey command line'
- Attempt to get header for <URL> failed.
The remote file tierh doesn't exist, is unauthorized, or is forbidden for url <URL>. Exception calling "GetResponse" with "0" argument(s): "The remote servier returned an error: (401) Unauthorized."
Additional Context
The following should allow receiving Options
- Get-WebHeaders
- Get-WebFileName
The following should be changed to pass the Options
- https://github.com/chocolatey/choco/blob/master/src/chocolatey.resources/helpers/functions/Get-ChocolateyWebFile.ps1#L304
- https://github.com/chocolatey/choco/blob/master/src/chocolatey.resources/helpers/functions/Get-ChocolateyWebFile.ps1#L327
- https://github.com/chocolatey/choco/blob/master/src/chocolatey.resources/helpers/functions/Get-ChocolateyWebFile.ps1#L336