1+ Import-Module $PSScriptRoot \..\..\Common\Test.Helpers.psm1
12Describe " Basic FileSystem Provider Tests" - Tags " CI" {
23 BeforeAll {
34 $testDir = " TestDir"
@@ -20,6 +21,9 @@ Describe "Basic FileSystem Provider Tests" -Tags "CI" {
2021 $newTestFile = " NewTestFile.txt"
2122 $testContent = " Some Content"
2223 $testContent2 = " More Content"
24+ $reservedNames = " CON" , " PRN" , " AUX" , " CLOCK$" , " NUL" ,
25+ " COM0" , " COM1" , " COM2" , " COM3" , " COM4" , " COM5" , " COM6" , " COM7" , " COM8" , " COM9" ,
26+ " LPT0" , " LPT1" , " LPT2" , " LPT3" , " LPT4" , " LPT5" , " LPT6" , " LPT7" , " LPT8" , " LPT9"
2327 }
2428
2529 BeforeEach {
@@ -103,6 +107,53 @@ Describe "Basic FileSystem Provider Tests" -Tags "CI" {
103107 $contentBefore.Count | Should Be 1
104108 $contentAfter.Count | Should Be 0
105109 }
110+
111+ It " Copy-Item on Windows rejects Windows reserved device names" - Skip:(-not $IsWindows ) {
112+ foreach ($deviceName in $reservedNames )
113+ {
114+ { Copy-Item - Path $testFile - Destination $deviceName - ErrorAction Stop } | ShouldBeErrorId " CopyError,Microsoft.PowerShell.Commands.CopyItemCommand"
115+ }
116+ }
117+
118+ It " Move-Item on Windows rejects Windows reserved device names" - Skip:(-not $IsWindows ) {
119+ foreach ($deviceName in $reservedNames )
120+ {
121+ { Move-Item - Path $testFile - Destination $deviceName - ErrorAction Stop } | ShouldBeErrorId " MoveError,Microsoft.PowerShell.Commands.MoveItemCommand"
122+ }
123+ }
124+
125+ It " Rename-Item on Windows rejects Windows reserved device names" - Skip:(-not $IsWindows ) {
126+ foreach ($deviceName in $reservedNames )
127+ {
128+ { Rename-Item - Path $testFile - NewName $deviceName - ErrorAction Stop } | ShouldBeErrorId " RenameError,Microsoft.PowerShell.Commands.RenameItemCommand"
129+ }
130+ }
131+
132+ It " Copy-Item on Unix succeeds with Windows reserved device names" - Skip:($IsWindows ) {
133+ foreach ($deviceName in $reservedNames )
134+ {
135+ Copy-Item - Path $testFile - Destination $deviceName - Force - ErrorAction SilentlyContinue
136+ Test-Path $deviceName | Should Be $true
137+ }
138+ }
139+
140+ It " Move-Item on Unix succeeds with Windows reserved device names" - Skip:($IsWindows ) {
141+ foreach ($deviceName in $reservedNames )
142+ {
143+ Move-Item - Path $testFile - Destination $deviceName - Force - ErrorAction SilentlyContinue
144+ Test-Path $deviceName | Should Be $true
145+ New-Item - Path $testFile - ItemType File - Force - ErrorAction SilentlyContinue
146+ }
147+ }
148+
149+ It " Rename-Item on Unix succeeds with Windows reserved device names" - Skip:($IsWindows ) {
150+ foreach ($deviceName in $reservedNames )
151+ {
152+ Rename-Item - Path $testFile - NewName $deviceName - Force - ErrorAction SilentlyContinue
153+ Test-Path $deviceName | Should Be $true
154+ New-Item - Path $testFile - ItemType File - Force - ErrorAction SilentlyContinue
155+ }
156+ }
106157 }
107158
108159 Context " Validate basic host navigation functionality" {
@@ -667,4 +718,4 @@ Describe "Extended FileSystem Path/Location Cmdlet Provider Tests" -Tags "Featur
667718 catch { $_.FullyQualifiedErrorId | Should Be " Argument,Microsoft.PowerShell.Commands.PopLocationCommand" }
668719 }
669720 }
670- }
721+ }
0 commit comments