Skip to content
This repository was archived by the owner on Jun 13, 2024. It is now read-only.

Conversation

@alerickson
Copy link
Member

No description provided.

Copy link
Contributor

@edyoung edyoung left a 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)
Copy link
Contributor

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?

Copy link
Member Author

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.

}

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" {
Copy link
Contributor

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?

Copy link
Member Author

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.

@edyoung
Copy link
Contributor

edyoung commented Aug 23, 2018

Lgtm

-CallerPSCmdlet $PSCmdlet `
-ErrorCategory InvalidArgument
$Scope = "CurrentUser"
if(Test-RunningAsElevated)
Copy link
Contributor

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.


$installedModuleInfo | Should Not Be $null
$installedModuleInfo.Name | Should Be $ContosoServer
$installedModuleInfo.InstalledLocation.StartsWith($script:MyDocumentsModulesPath, [System.StringComparison]::OrdinalIgnoreCase) | Should Be $true
Copy link
Contributor

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.

Copy link
Member Author

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?

Copy link
Contributor

Choose a reason for hiding this comment

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

-ErrorId "InstallModuleNeedsCurrentUserScopeParameterForNonAdminUser" `
-CallerPSCmdlet $PSCmdlet `
-ErrorCategory InvalidArgument
$Scope = "CurrentUser"
Copy link
Contributor

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.

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

Copy link
Contributor

@bmanikm bmanikm left a comment

Choose a reason for hiding this comment

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

🕐

@alerickson
Copy link
Member Author

@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
Copy link
Contributor

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 ?

Copy link
Member Author

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.

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
Copy link
Contributor

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

@alerickson
Copy link
Member Author

@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.

Copy link

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)
Copy link
Contributor

@bmanikm bmanikm Sep 12, 2018

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

@alerickson
Copy link
Member Author

@bmanikm the tests are no longer hanging. I believe everything should be good to go now.

@bmanikm bmanikm merged commit f0728e0 into PowerShell:development Sep 13, 2018
@alerickson alerickson deleted the scopeForInstallModule branch September 13, 2018 17:21
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants