@@ -18,8 +18,8 @@ function SuiteSetup {
18
18
Import-Module " $PSScriptRoot \PSGetTestUtils.psm1" - WarningAction SilentlyContinue
19
19
Import-Module " $PSScriptRoot \Asserts.psm1" - WarningAction SilentlyContinue
20
20
21
- $script :ProgramFilesScriptsPath = Get-AllUsersScriptsPath
22
- $script :MyDocumentsScriptsPath = Get-CurrentUserScriptsPath
21
+ $script :ProgramFilesScriptsPath = Get-AllUsersScriptsPath
22
+ $script :MyDocumentsScriptsPath = Get-CurrentUserScriptsPath
23
23
$script :PSGetLocalAppDataPath = Get-PSGetLocalAppDataPath
24
24
$script :TempPath = Get-TempPath
25
25
@@ -41,17 +41,6 @@ function SuiteSetup {
41
41
Get-InstalledScript - Name Fabrikam- ServerScript - ErrorAction SilentlyContinue | Uninstall-Script - Force
42
42
Get-InstalledScript - Name Fabrikam- ClientScript - ErrorAction SilentlyContinue | Uninstall-Script - Force
43
43
44
- if ($PSEdition -ne ' Core' )
45
- {
46
- $script :userName = " PSGetUser"
47
- $password = " Password1"
48
- $null = net user $script :userName $password / add
49
- $secstr = ConvertTo-SecureString $password - AsPlainText - Force
50
- $script :credential = new-object - typename System.Management.Automation.PSCredential - argumentlist $script :userName , $secstr
51
- }
52
-
53
- $script :assertTimeOutms = 20000
54
-
55
44
# Create temp folder for saving the scripts
56
45
$script :TempSavePath = Join-Path - Path $script :TempPath - ChildPath " PSGet_$ ( Get-Random ) "
57
46
$null = New-Item - Path $script :TempSavePath - ItemType Directory - Force
@@ -73,17 +62,6 @@ function SuiteCleanup {
73
62
# Import the PowerShellGet provider to reload the repositories.
74
63
$null = Import-PackageProvider - Name PowerShellGet - Force
75
64
76
- if ($PSEdition -ne ' Core' )
77
- {
78
- # Delete the user
79
- net user $script :UserName / delete | Out-Null
80
- # Delete the user profile
81
- $userProfile = (Get-WmiObject - Class Win32_UserProfile | Where-Object {$_.LocalPath -match $script :UserName })
82
- if ($userProfile )
83
- {
84
- RemoveItem $userProfile.LocalPath
85
- }
86
- }
87
65
RemoveItem $script :TempSavePath
88
66
89
67
@@ -343,7 +321,7 @@ Describe PowerShell.PSGet.UpdateScriptTests -Tags 'BVT','InnerLoop' {
343
321
$DateTimeBeforeUpdate = Get-Date
344
322
Update-Script Fabrikam-* - Force - ErrorVariable MyError
345
323
Assert ($MyError.Count -eq 0 ) " There should not be any error when updating multiple scripts with wildcard in name, $MyError "
346
-
324
+
347
325
$res = Get-InstalledScript - Name Fabrikam- ServerScript - MinimumVersion ' 1.1'
348
326
Assert ($res -and ($res.Name -eq " Fabrikam-ServerScript" ) -and ($res.Version -gt [Version ]" 1.0" )) " Update-Script should update when wildcard specified in name"
349
327
@@ -415,33 +393,25 @@ Describe PowerShell.PSGet.UpdateScriptTests -Tags 'BVT','InnerLoop' {
415
393
#
416
394
# Action: Install a script as admin and try to update it as non-admin user
417
395
#
418
- # Expected Result: should fail with an error
396
+ # Expected Result: should pass, installing the update in currentuser scope
419
397
#
420
- It " AdminPrivilegesAreRequiredForUpdatingAllUsersScript " {
398
+ It " AdminPrivilegesAreNotRequiredForUpdatingAllUsersScript " {
421
399
Install-Script - Name Fabrikam- ServerScript - RequiredVersion 1.0 - Scope AllUsers
422
- $NonAdminConsoleOutput = Join-Path ([System.IO.Path ]::GetTempPath()) ' nonadminconsole-out.txt'
423
- Start-Process " $PSHOME \PowerShell.exe" - ArgumentList ' $null = Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force -Scope CurrentUser;
424
- $null = Import-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force;
425
- Update-Script -Name Fabrikam-ServerScript' `
426
- - Credential $script :credential `
427
- - Wait `
428
- - WorkingDirectory $PSHOME `
429
- - RedirectStandardOutput $NonAdminConsoleOutput
430
-
431
- waitFor {Test-Path $NonAdminConsoleOutput } - timeoutInMilliseconds $script :assertTimeOutms - exceptionMessage " Install-Script on non-admin console failed to complete"
432
- $content = Get-Content $NonAdminConsoleOutput
433
- Assert ($content -match ' AdminPrivilegesAreRequiredForUpdate' ) " Update-Script should fail when non-admin user is trying to update a script installed to allusers scope, $content "
434
- RemoveItem $NonAdminConsoleOutput
435
- } `
400
+ $content = Invoke-WithoutAdminPrivileges (@'
401
+ Import-Module "{0}\PowerShellGet.psd1" -Force -Passthru | select ModuleBase
402
+ Update-Script -Name Fabrikam-ServerScript
403
+ '@ -f (Get-Module PowerShellGet).ModuleBase)
404
+
405
+ $updatedScript = Get-InstalledScript Fabrikam- ServerScript
406
+ Assert ($updatedScript.Version -gt 1.0 ) " Update-Script failed to updated script running as non-admin: $content "
407
+ } `
436
408
- Skip:$ (
437
409
$whoamiValue = (whoami)
438
-
439
410
($whoamiValue -eq " NT AUTHORITY\SYSTEM" ) -or
440
411
($whoamiValue -eq " NT AUTHORITY\LOCAL SERVICE" ) -or
441
412
($whoamiValue -eq " NT AUTHORITY\NETWORK SERVICE" ) -or
442
413
($env: APPVEYOR_TEST_PASS -eq ' True' ) -or
443
- ($PSEdition -eq ' Core' ) -or
444
- ($PSVersionTable.PSVersion -lt ' 4.0.0' )
414
+ ($PSVersionTable.PSVersion -lt ' 4.0.0' )
445
415
)
446
416
447
417
# Purpose: UpdateScriptWithLowerReqVersionShouldNotUpdate
@@ -451,7 +421,7 @@ Describe PowerShell.PSGet.UpdateScriptTests -Tags 'BVT','InnerLoop' {
451
421
# Expected Result: Script should not be downgraded to 1.0
452
422
#
453
423
It " UpdateScriptWithLowerReqVersionShouldNotUpdate" {
454
- Install-Script Fabrikam- ServerScript
424
+ Install-Script Fabrikam- ServerScript - Force
455
425
Update-Script Fabrikam- ServerScript - RequiredVersion 1.0
456
426
$res = Get-InstalledScript Fabrikam- ServerScript
457
427
Assert ($res.Name -eq " Fabrikam-ServerScript" -and $res.Version -gt [Version ]" 1.0" ) " Update-Script should not downgrade the script version with -RequiredVersion, Name: $ ( $res.Name ) , Version: $ ( $res.Version ) "
@@ -483,7 +453,8 @@ Describe PowerShell.PSGet.UpdateScriptTests -Tags 'BVT','InnerLoop' {
483
453
It " UpdateAllScripts" {
484
454
Install-Script Fabrikam- ClientScript - RequiredVersion 1.0
485
455
Install-Script Fabrikam- ServerScript - RequiredVersion 1.0
486
- Update-Script
456
+ Update-Script - ErrorAction SilentlyContinue - ErrorVariable err
457
+ $err | ? { $_.FullyQualifiedErrorId -notmatch " NoMatchFoundForCriteria" } | % { Write-Error $_ }
487
458
488
459
$res = Get-InstalledScript - Name Fabrikam- ServerScript, Fabrikam- ClientScript
489
460
Assert (($res.Count -eq 2 ) -and ($res [0 ].Version -gt [Version ]" 1.0" ) -and ($res [1 ].Version -gt [Version ]" 1.0" )) " Multiple script should be updated"
@@ -498,11 +469,11 @@ Describe PowerShell.PSGet.UpdateScriptTests -Tags 'BVT','InnerLoop' {
498
469
#
499
470
It " UpdateMultipleScriptsWithForce" {
500
471
Install-Script Fabrikam- ClientScript, Fabrikam- ServerScript
501
-
502
- $MyError = $null
472
+
473
+ $MyError = $null
503
474
Update-Script Fabrikam- ClientScript, Fabrikam- ServerScript - Force - ErrorVariable MyError
504
475
Assert ($MyError.Count -eq 0 ) " There should not be any error from force update for multiple scripts, $MyError "
505
-
476
+
506
477
$res = Get-InstalledScript Fabrikam- ServerScript
507
478
Assert (($res.Name -eq ' Fabrikam-ServerScript' ) -and ($res.Version -gt [Version ]" 1.0" )) " Update-Script should update when multiple scripts are specified"
508
479
@@ -518,6 +489,7 @@ Describe PowerShell.PSGet.UpdateScriptTests -Tags 'BVT','InnerLoop' {
518
489
#
519
490
It " UpdateScriptUnderCurrentUserScope" {
520
491
$scriptName = ' Fabrikam-ServerScript'
492
+
521
493
Install-Script $scriptName - Scope CurrentUser - RequiredVersion 1.0
522
494
Update-Script $scriptName
523
495
@@ -531,17 +503,22 @@ Describe PowerShell.PSGet.UpdateScriptTests -Tags 'BVT','InnerLoop' {
531
503
#
532
504
# Action: Install a script with AllUsers scope then update it
533
505
#
534
- # Expected Result: updated script should be under AllUsers windows powershell scripts folder
506
+ # Expected Result: updated script should be under AllUsers windows powershell scripts folder for an admin on Windows Powershell, currentuser otherwise
535
507
#
536
508
It " UpdateScriptUnderAllUsersScope" {
537
509
$scriptName = ' Fabrikam-ServerScript'
510
+ $shouldBeInAllUsers = ($PSVersionTable.PSVersion -lt " 5.0" -or $PSEdition -eq ' Desktop' ) # when running these tests we always need to be an admin
538
511
Install-Script $scriptName - Scope AllUsers - RequiredVersion 1.0
539
512
Update-Script $scriptName
540
513
541
514
$res = Get-InstalledScript $scriptName
542
515
543
- Assert (($res.Name -eq $scriptName ) -and ($res.Version -gt [Version ]" 1.0" )) " Update-Script should update the script installed to current user scope, $res "
544
- AssertEquals $res.InstalledLocation $script :ProgramFilesScriptsPath " Update-Script should update the script installed to current user scope, updated script base: $ ( $res.InstalledLocation ) "
516
+ Assert (($res.Name -eq $scriptName ) -and ($res.Version -gt [Version ]" 1.0" )) " Update-Script should update the script, $res "
517
+ if ($shouldBeInAllUsers ) {
518
+ AssertEquals $res.InstalledLocation $script :ProgramFilesScriptsPath " Update-Script should put update in all users scope, but updated script base: $ ( $res.InstalledLocation ) "
519
+ } else {
520
+ AssertEquals $res.InstalledLocation $script :MyDocumentsScriptsPath " Update-Script should put update in current user scope, updated script base: $ ( $res.InstalledLocation ) "
521
+ }
545
522
}
546
523
}
547
524
@@ -578,11 +555,11 @@ Describe PowerShell.PSGet.UpdateScriptTests.P1 -Tags 'P1','OuterLoop' {
578
555
$DepencyNames = $res1.Dependencies.Name
579
556
$res2 = Find-Script - Name $ScriptName - IncludeDependencies - MaximumVersion " 1.0" - MinimumVersion " 0.1"
580
557
Assert ($res2.Count -ge ($DepencyNames.Count + 1 )) " Find-Script with -IncludeDependencies returned wrong results, $res2 "
581
-
558
+
582
559
Install-Script - Name $ScriptName - MaximumVersion " 1.0" - MinimumVersion " 0.1"
583
560
$ActualScriptDetails = Get-InstalledScript - Name $ScriptName - RequiredVersion $res1.Version
584
561
AssertNotNull $ActualScriptDetails " $ScriptName script with dependencies is not installed properly"
585
-
562
+
586
563
$NamesToUninstall += $res2.Name
587
564
588
565
$res2 | ForEach-Object {
@@ -595,7 +572,7 @@ Describe PowerShell.PSGet.UpdateScriptTests.P1 -Tags 'P1','OuterLoop' {
595
572
596
573
# Find the latest available version
597
574
$res3 = Find-Script - Name $ScriptName - IncludeDependencies
598
-
575
+
599
576
Update-Script - Name $ScriptName
600
577
601
578
$NamesToUninstall += $res3.Name
@@ -616,5 +593,5 @@ Describe PowerShell.PSGet.UpdateScriptTests.P1 -Tags 'P1','OuterLoop' {
616
593
PowerShellGet\Uninstall-Module $_ - Force - ErrorAction SilentlyContinue
617
594
}
618
595
}
619
- } - Skip:$ ($PSVersionTable.PSVersion -lt ' 5.0.0' )
596
+ } - Skip:$ ($PSVersionTable.PSVersion -lt ' 5.0.0' )
620
597
}
0 commit comments