From cda6ef175cf6277105d52d2c0e0c4179c053ef6e Mon Sep 17 00:00:00 2001 From: Klaudia Algiz Date: Tue, 5 Jun 2018 10:26:04 -0700 Subject: [PATCH] Remove not initialized variable $IsElevated from test in New-Item.Tests.ps1 (#6746) * Remove not initialized variable from PowerShell tests * Separate the tests that requires no elevation from the others. --- .../New-Item.Tests.ps1 | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Management/New-Item.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Management/New-Item.Tests.ps1 index 6a1c499e2..8fc8ce281 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Management/New-Item.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Management/New-Item.Tests.ps1 @@ -206,16 +206,26 @@ Describe "New-Item with links" -Tags @('CI', 'RequireAdminOnWindows') { Remove-Item $FullyQualifiedLink -Force } - It "Should error correctly when failing to create a symbolic link" -Skip:($IsWindows -or $IsElevated) { - Write-Host "Iselevated: $IsElevated" - # This test expects that /sbin exists but is not writable by the user - { New-Item -ItemType SymbolicLink -Path "/sbin/powershell-test" -Target $FullyQualifiedFolder -ErrorAction Stop } | - Should -Throw -ErrorId "NewItemSymbolicLinkElevationRequired,Microsoft.PowerShell.Commands.NewItemCommand" - } - It "New-Item -ItemType SymbolicLink should understand directory path ending with slash" { $folderName = [System.IO.Path]::GetRandomFileName() $symbolicLinkPath = New-Item -ItemType SymbolicLink -Path "$tmpDirectory/$folderName/" -Value "/bar/" $symbolicLinkPath | Should -Not -BeNullOrEmpty } } + +Describe "New-Item with links fails for non elevated user." -Tags "CI" { + BeforeAll { + $tmpDirectory = $TestDrive + $testfile = "testfile.txt" + $testfolder = "newDirectory" + $testlink = "testlink" + $FullyQualifiedFile = Join-Path -Path $tmpDirectory -ChildPath $testfile + $FullyQualifiedFolder = Join-Path -Path $tmpDirectory -ChildPath $testfolder + } + + It "Should error correctly when failing to create a symbolic link" { + # This test expects that /sbin exists but is not writable by the user + { New-Item -ItemType SymbolicLink -Path "/sbin/powershell-test" -Target $FullyQualifiedFolder -ErrorAction Stop } | + Should -Throw -ErrorId "NewItemSymbolicLinkElevationRequired,Microsoft.PowerShell.Commands.NewItemCommand" + } +}