-
Notifications
You must be signed in to change notification settings - Fork 133
Change default scope in Install-Module and Install-Script #315
Change default scope in Install-Module and Install-Script #315
Conversation
edyoung
left a comment
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.
Thanks!
| if (-not ($Scope)) | ||
| { | ||
| # Throw an error when Install-Module is used as a non-admin user and '-Scope CurrentUser' is not specified | ||
| $message = $LocalizedData.InstallModuleNeedsCurrentUserScopeParameterForNonAdminUser -f @($script:programFilesModulesPath, $script:MyDocumentsModulesPath) |
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.
Consider: when the user is not an admin and they explicitly specify -Scope AllUsers shouldn't they see this message?
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.
They still see the error message because this function calls PackageManagement\Install-Module, which has the same error message. I don't think it's necessary to keep it in there unless there's a specific situation where it's advantageous to throw the error early on.
Tests/PowerShellGet.Tests.ps1
Outdated
| } | ||
|
|
||
| It "Should install a module correctly to the required location with CurrentUser scope" { | ||
| It "Should install a module correctly to the required location with CurrentUser scope and no elevated privileges" { |
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.
do these tests always run without elevated privileges, or just with the default privileges of how you start the shell? ie if I run these tests in an Administrator window won't they fail?
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.
The tests will run based off of the default privileges of the shell. The previous install-module/install-script tests were already split up into "Module tests" and "Module tests (Admin)" (the latter is tagged with "RequireAdminOnWindows"). Running without privileges causes all the non-elevated privilege tests to pass and vice versa.
|
Lgtm |
| -CallerPSCmdlet $PSCmdlet ` | ||
| -ErrorCategory InvalidArgument | ||
| $Scope = "CurrentUser" | ||
| if(Test-RunningAsElevated) |
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.
if(Test-RunningAsElevated) [](start = 12, length = 26)
On non-Windows OS platforms, this function returns true as there is no straight forward way to identify whether PS is running as admin. I think, the default scope the non-Windows platforms should be CurrentUser.
Tests/PowerShellGet.Tests.ps1
Outdated
|
|
||
| $installedModuleInfo | Should Not Be $null | ||
| $installedModuleInfo.Name | Should Be $ContosoServer | ||
| $installedModuleInfo.InstalledLocation.StartsWith($script:MyDocumentsModulesPath, [System.StringComparison]::OrdinalIgnoreCase) | Should Be $true |
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.
This tests in this file gets executed only in the daily test pass and it is sanity tests file for PS core builds.
In PowerShellGet daily test runs, all the tests in this file are executed with admin privileges.
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.
@bmanikm So what should I do to ensure both admin and non-admin tests run? Should I only include admin tests?
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.
Please take a look at https://github.com/PowerShell/PowerShellGet/blob/development/Tests/PSGetInstallModule.Tests.ps1#L522 for running the tests as non-admin.
| -ErrorId "InstallModuleNeedsCurrentUserScopeParameterForNonAdminUser" ` | ||
| -CallerPSCmdlet $PSCmdlet ` | ||
| -ErrorCategory InvalidArgument | ||
| $Scope = "CurrentUser" |
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.
$Scope = "CurrentUser" [](start = 12, length = 22)
It is also required to change the default scope value in the Install-Package provider function as users can use the PackageManagement Install-Package cmdlet with PowerShellGet provider name.
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.
I think that whilst yes you could do that, the majority would not drop down to use Install-Package instead of Install-Module unless really needed, which I can't think of a reason off the top of my head as to why anyone would
bmanikm
left a comment
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.
🕐
|
@bmanikm can you review recent changes? Core tests are temporarily skipped until dotnet in appveyor environment is updated. |
| $Scope = $null | ||
| $NoPathUpdate = $false | ||
| $AcceptLicense = $false | ||
| $script:IsWindowsOS = (-not (Get-Variable -Name IsWindows -ErrorAction Ignore)) -or $IsWindows |
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.
$script:IsWindowsOS = (-not (Get-Variable -Name IsWindows -ErrorAction Ignore)) -or $IsWindows [](start = 4, length = 94)
Any specific reason for not using $script:IsWindows defined in .\PowerShellGet\private\modulefile\PartOne.ps1 ?
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.
I made that change, please let me know if there's other changes I should make before pushing.
Tests/PSGetInstallModule.Tests.ps1
Outdated
| Start-Process $PSprocess -ArgumentList '$null = Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force -Scope CurrentUser; | ||
| $null = Import-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force; | ||
| if(-not (Get-PSRepository -Name INTGallery -ErrorAction SilentlyContinue)) { | ||
| Register-PSRepository -Name INTGallery -SourceLocation https://dtlgalleryint.cloudapp.net/api/v2/ -InstallationPolicy Trusted |
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.
https://dtlgalleryint.cloudapp.net/api/v2/ [](start = 119, length = 42)
Please use www.poshtestgallery.com here
|
@JKeithB can you review the changelog? I included scope changes made to "install-package", but it's a provider function so I'm not sure how that should be treated. |
| ## 2.0.0 | ||
| Breaking Change | ||
| - For both administrative privileges and non-administrative privileges, default user scope for Install-Module, Install-Script, and Install-Package is now current user when running PowerShell version 6.0.0 and up. For versions less than 6.0.0 administrative privileges will default to all users and non-administrative privileges will default to current user. | ||
|
|
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.
I would separate these differently. Suggested rewording accounts for the fact that most users are on PowerShell 5.1:
Default user scope for Install-Module, Install-Script, and Install-Package has changed. For Windows PowerShell (version 5.1), the default user scope is AllUsers when running in an elevated session, and CurrentUser at all other times.
For PowerShell version 6.0.0 and above, the default user scope is always CurrentUser.
| $AdminPrivilegeErrorMessage = $LocalizedData.InstallScriptNeedsCurrentUserScopeParameterForNonAdminUser -f @($script:ProgramFilesScriptsPath, $script:MyDocumentsScriptsPath) | ||
| $AdminPrivilegeErrorId = 'InstallScriptNeedsCurrentUserScopeParameterForNonAdminUser' | ||
| # Throw an error when Install-Script is used as a non-admin user and '-Scope AllUsers' | ||
| $message = $LocalizedData.InstallScriptAdminPrivilegeRequiredForAllUsersScope -f @($script:programFilesModulesPath, $script:MyDocumentsModulesPath) |
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.
@($script:programFilesModulesPath, $script:MyDocumentsModulesPath) [](start = 93, length = 66)
These vars are for modules, please use @($script:ProgramFilesScriptsPath, $script:MyDocumentsScriptsPath) here. #Closed
|
@bmanikm the tests are no longer hanging. I believe everything should be good to go now. |
No description provided.