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" + } +}