From 7f0c05c187baf01fdb1e922ce416574e3117741d Mon Sep 17 00:00:00 2001 From: kvprasoon Date: Sun, 18 Nov 2018 14:28:06 +0530 Subject: [PATCH 01/14] Fix for issue 8242 --- .../commands/management/Navigation.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/Navigation.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/Navigation.cs index eedbeb4855d..c8f09f712d0 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/Navigation.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/Navigation.cs @@ -1375,6 +1375,12 @@ protected override void ProcessRecord() ThrowTerminatingError(er); } + // Trimming forward and backward slash for FileSystem provider when -Persist is used. + if (Persist && provider.Name.Equals(FileSystemProvider.ProviderName, StringComparison.OrdinalIgnoreCase)) + { + Root = Root.TrimEnd(new[] {'/','\\'}); + } + // Create the new drive PSDriveInfo newDrive = new PSDriveInfo( @@ -4544,4 +4550,3 @@ protected override void ProcessRecord() #endregion Provider commands } // namespace Microsoft.PowerShell.Commands - From 1788e66eb0b93bba59af55ef61c39298cb8d09ff Mon Sep 17 00:00:00 2001 From: kvprasoon Date: Sun, 18 Nov 2018 15:36:53 +0530 Subject: [PATCH 02/14] codefactor fix --- .../commands/management/Navigation.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/Navigation.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/Navigation.cs index c8f09f712d0..ced113a4dd1 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/Navigation.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/Navigation.cs @@ -1378,7 +1378,7 @@ protected override void ProcessRecord() // Trimming forward and backward slash for FileSystem provider when -Persist is used. if (Persist && provider.Name.Equals(FileSystemProvider.ProviderName, StringComparison.OrdinalIgnoreCase)) { - Root = Root.TrimEnd(new[] {'/','\\'}); + Root = Root.TrimEnd(new[] { '/', '\\' }); } // Create the new drive From 2415fa94dbc27523b4d272f170dbec92af32e8bf Mon Sep 17 00:00:00 2001 From: kvprasoon Date: Tue, 20 Nov 2018 08:50:06 +0530 Subject: [PATCH 03/14] Changes as per review comments --- .../commands/management/Navigation.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/Navigation.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/Navigation.cs index ced113a4dd1..c9a58d0a021 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/Navigation.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/Navigation.cs @@ -1378,7 +1378,7 @@ protected override void ProcessRecord() // Trimming forward and backward slash for FileSystem provider when -Persist is used. if (Persist && provider.Name.Equals(FileSystemProvider.ProviderName, StringComparison.OrdinalIgnoreCase)) { - Root = Root.TrimEnd(new[] { '/', '\\' }); + Root = Root.TrimEnd('/', '\\'); } // Create the new drive From dbddef254933b8a8710ad5f39c08fbf5ccb63205 Mon Sep 17 00:00:00 2001 From: kvprasoon Date: Wed, 21 Nov 2018 00:34:26 +0530 Subject: [PATCH 04/14] added tests for #8305 --- .../PSDrive.Tests.ps1 | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Management/PSDrive.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Management/PSDrive.Tests.ps1 index 8959f0b09a4..873ecce6678 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Management/PSDrive.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Management/PSDrive.Tests.ps1 @@ -1,5 +1,22 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. +Describe "Tests with elevated permissions" -Tag "CI","WindowsRequireAdmin" { + Context "Validate PSDrive Cmdlets" { + It "Create a new persistent PSDrive targetting remote Windows share." { + try { + #Arrange + $RemoteShare = "\\$env:COMPUTERNAME\$($env:SystemDrive.replace(':','$\'))" + + #Act and Assert + {New-PSDrive -Name "W" -PSProvider FileSystem -Root $RemoteShare -Persist} | Should -Not -Throw + } + finally { + Remove-PSDrive -Name "W" -Force -ErrorAction SilentlyContinue + } + } -Skip:(-not $IsWindows) + } +} + Describe "Basic Alias Provider Tests" -Tags "CI" { Context "Validate basic PSDrive Cmdlets" { BeforeAll { From 7155f5bcf2f1eef6a60744b99e8dba0fa096707c Mon Sep 17 00:00:00 2001 From: kvprasoon Date: Wed, 21 Nov 2018 01:02:45 +0530 Subject: [PATCH 05/14] Correcting WindowsRequireAdmin to RequireAdminOnWindows --- .../Modules/Microsoft.PowerShell.Management/PSDrive.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Management/PSDrive.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Management/PSDrive.Tests.ps1 index 873ecce6678..cdcc32ac523 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Management/PSDrive.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Management/PSDrive.Tests.ps1 @@ -1,6 +1,6 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. -Describe "Tests with elevated permissions" -Tag "CI","WindowsRequireAdmin" { +Describe "Tests with elevated permissions" -Tag "CI","RequireAdminOnWindows" { Context "Validate PSDrive Cmdlets" { It "Create a new persistent PSDrive targetting remote Windows share." { try { From 9977732bab3a50c88a482d1f3fa8e2c41d20d7a1 Mon Sep 17 00:00:00 2001 From: kvprasoon Date: Thu, 22 Nov 2018 01:15:32 +0530 Subject: [PATCH 06/14] Changes as per review comment --- .../Modules/Microsoft.PowerShell.Management/PSDrive.Tests.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Management/PSDrive.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Management/PSDrive.Tests.ps1 index cdcc32ac523..0d492619065 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Management/PSDrive.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Management/PSDrive.Tests.ps1 @@ -2,7 +2,7 @@ # Licensed under the MIT License. Describe "Tests with elevated permissions" -Tag "CI","RequireAdminOnWindows" { Context "Validate PSDrive Cmdlets" { - It "Create a new persistent PSDrive targetting remote Windows share." { + It "Create a new persistent PSDrive targetting remote Windows share." -Skip:(-not $IsWindows) { try { #Arrange $RemoteShare = "\\$env:COMPUTERNAME\$($env:SystemDrive.replace(':','$\'))" @@ -13,7 +13,7 @@ Describe "Tests with elevated permissions" -Tag "CI","RequireAdminOnWindows" { finally { Remove-PSDrive -Name "W" -Force -ErrorAction SilentlyContinue } - } -Skip:(-not $IsWindows) + } } } From 9cf4236f741a7e274894af3685f9abf004ebb0db Mon Sep 17 00:00:00 2001 From: kvprasoon Date: Thu, 22 Nov 2018 23:57:03 +0530 Subject: [PATCH 07/14] Changes as per review comments by adding a new line. --- .../Modules/Microsoft.PowerShell.Management/PSDrive.Tests.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Management/PSDrive.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Management/PSDrive.Tests.ps1 index 0d492619065..12bd6855d81 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Management/PSDrive.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Management/PSDrive.Tests.ps1 @@ -1,5 +1,6 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. + Describe "Tests with elevated permissions" -Tag "CI","RequireAdminOnWindows" { Context "Validate PSDrive Cmdlets" { It "Create a new persistent PSDrive targetting remote Windows share." -Skip:(-not $IsWindows) { From 29b5fed1c56c9f5cd799a6c01787798c279f5c97 Mon Sep 17 00:00:00 2001 From: kvprasoon Date: Fri, 23 Nov 2018 08:11:42 +0530 Subject: [PATCH 08/14] trigger ci again From 4c4159b04c6e59e0e7edd6a82c78d2ddb87d25e2 Mon Sep 17 00:00:00 2001 From: kvprasoon Date: Sat, 24 Nov 2018 22:36:36 +0530 Subject: [PATCH 09/14] Adding New-PSDrive.tests as per review comments. --- .../New-PSDrive.Tests.ps1 | 28 +++++++++++++++++++ .../PSDrive.Tests.ps1 | 19 +------------ 2 files changed, 29 insertions(+), 18 deletions(-) create mode 100644 test/powershell/Modules/Microsoft.PowerShell.Management/New-PSDrive.Tests.ps1 diff --git a/test/powershell/Modules/Microsoft.PowerShell.Management/New-PSDrive.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Management/New-PSDrive.Tests.ps1 new file mode 100644 index 00000000000..0bb2c5e3fe9 --- /dev/null +++ b/test/powershell/Modules/Microsoft.PowerShell.Management/New-PSDrive.Tests.ps1 @@ -0,0 +1,28 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. + +Describe "Tests for New-PSDrive cmdlet." -Tag "CI","RequireAdminOnWindows" { + Context "Validate New-PSDrive Cmdlet with -Persist switch." { + BeforeEach { + $PSDriveName = "W" + $RemoteShare = "\\$env:COMPUTERNAME\$($env:SystemDrive.replace(':','$\'))" + } + + AfterEach { + Remove-PSDrive -Name $PSDriveName -Force -ErrorAction SilentlyContinue + } + + It "Should not throw exception for persistent PSDrive creation." -Skip:(-not $IsWindows) { + { New-PSDrive -Name $PSDriveName -PSProvider FileSystem -Root $RemoteShare -Persist -ErrorAction Stop } | Should -Not -Throw + } + + it "Should throw exception if root is not a remote share." { + { New-PSDrive -Root "TestDrive:\" -PSProvider FileSystem -Name $PSDriveName -Persist -ErrorAction Stop } | Should -Throw -ErrorId 'DriveRootNotNetworkPath' + } + + it "Should throw exception if PSDrive is not a drive letter supported by operating system." { + $PSDriveName = 'AB' + { New-PSDrive -Root $RemoteShare -PSProvider FileSystem -Name $PSDriveName -Persist -ErrorAction Stop } | Should -Throw -ErrorId 'DriveNameNotSupportedForPersistence' + } + } +} \ No newline at end of file diff --git a/test/powershell/Modules/Microsoft.PowerShell.Management/PSDrive.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Management/PSDrive.Tests.ps1 index 12bd6855d81..ac4bcd63f4f 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Management/PSDrive.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Management/PSDrive.Tests.ps1 @@ -1,23 +1,6 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. -Describe "Tests with elevated permissions" -Tag "CI","RequireAdminOnWindows" { - Context "Validate PSDrive Cmdlets" { - It "Create a new persistent PSDrive targetting remote Windows share." -Skip:(-not $IsWindows) { - try { - #Arrange - $RemoteShare = "\\$env:COMPUTERNAME\$($env:SystemDrive.replace(':','$\'))" - - #Act and Assert - {New-PSDrive -Name "W" -PSProvider FileSystem -Root $RemoteShare -Persist} | Should -Not -Throw - } - finally { - Remove-PSDrive -Name "W" -Force -ErrorAction SilentlyContinue - } - } - } -} - Describe "Basic Alias Provider Tests" -Tags "CI" { Context "Validate basic PSDrive Cmdlets" { BeforeAll { @@ -39,7 +22,7 @@ Describe "Basic Alias Provider Tests" -Tags "CI" { $newDrive = New-PSDrive -Name "NewDifferentPSDrive" -PSProvider FileSystem -Root $psDriveRoot $newDrive.Name | Should -BeExactly "NewDifferentPSDrive" $newDrive.Root | Should -BeExactly (Convert-Path $psDriveRoot) - } + ` } finally { Remove-PSDrive -Name "NewDifferentPSDrive" -Force -ErrorAction SilentlyContinue } From e99746663c0be847a56d56a26997fdaf7014b61c Mon Sep 17 00:00:00 2001 From: kvprasoon Date: Sun, 25 Nov 2018 10:07:32 +0530 Subject: [PATCH 10/14] removing typo and adding new line at EoF as per review comments. --- .../Microsoft.PowerShell.Management/New-PSDrive.Tests.ps1 | 2 +- .../Modules/Microsoft.PowerShell.Management/PSDrive.Tests.ps1 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Management/New-PSDrive.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Management/New-PSDrive.Tests.ps1 index 0bb2c5e3fe9..6c41f0376d0 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Management/New-PSDrive.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Management/New-PSDrive.Tests.ps1 @@ -25,4 +25,4 @@ Describe "Tests for New-PSDrive cmdlet." -Tag "CI","RequireAdminOnWindows" { { New-PSDrive -Root $RemoteShare -PSProvider FileSystem -Name $PSDriveName -Persist -ErrorAction Stop } | Should -Throw -ErrorId 'DriveNameNotSupportedForPersistence' } } -} \ No newline at end of file +} diff --git a/test/powershell/Modules/Microsoft.PowerShell.Management/PSDrive.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Management/PSDrive.Tests.ps1 index ac4bcd63f4f..1a689df124d 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Management/PSDrive.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Management/PSDrive.Tests.ps1 @@ -22,7 +22,7 @@ Describe "Basic Alias Provider Tests" -Tags "CI" { $newDrive = New-PSDrive -Name "NewDifferentPSDrive" -PSProvider FileSystem -Root $psDriveRoot $newDrive.Name | Should -BeExactly "NewDifferentPSDrive" $newDrive.Root | Should -BeExactly (Convert-Path $psDriveRoot) - ` } + } finally { Remove-PSDrive -Name "NewDifferentPSDrive" -Force -ErrorAction SilentlyContinue } From 3a5b4812cd9816b8914d6ffabe090475e2970d5e Mon Sep 17 00:00:00 2001 From: kvprasoon Date: Sun, 25 Nov 2018 10:36:47 +0530 Subject: [PATCH 11/14] Adding missed OS Check --- .../Microsoft.PowerShell.Management/New-PSDrive.Tests.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Management/New-PSDrive.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Management/New-PSDrive.Tests.ps1 index 6c41f0376d0..e6e8c348a73 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Management/New-PSDrive.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Management/New-PSDrive.Tests.ps1 @@ -16,11 +16,11 @@ Describe "Tests for New-PSDrive cmdlet." -Tag "CI","RequireAdminOnWindows" { { New-PSDrive -Name $PSDriveName -PSProvider FileSystem -Root $RemoteShare -Persist -ErrorAction Stop } | Should -Not -Throw } - it "Should throw exception if root is not a remote share." { + it "Should throw exception if root is not a remote share." -Skip:(-not $IsWindows) { { New-PSDrive -Root "TestDrive:\" -PSProvider FileSystem -Name $PSDriveName -Persist -ErrorAction Stop } | Should -Throw -ErrorId 'DriveRootNotNetworkPath' } - it "Should throw exception if PSDrive is not a drive letter supported by operating system." { + it "Should throw exception if PSDrive is not a drive letter supported by operating system." -Skip:(-not $IsWindows) { $PSDriveName = 'AB' { New-PSDrive -Root $RemoteShare -PSProvider FileSystem -Name $PSDriveName -Persist -ErrorAction Stop } | Should -Throw -ErrorId 'DriveNameNotSupportedForPersistence' } From d47081f35eb2d0789dc2293777a8f65176a9c6c9 Mon Sep 17 00:00:00 2001 From: kvprasoon Date: Thu, 29 Nov 2018 22:37:15 +0530 Subject: [PATCH 12/14] rearranged parameters and get unused drive names as per review comments --- .../Microsoft.PowerShell.Management/New-PSDrive.Tests.ps1 | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Management/New-PSDrive.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Management/New-PSDrive.Tests.ps1 index e6e8c348a73..c54aceeaca9 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Management/New-PSDrive.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Management/New-PSDrive.Tests.ps1 @@ -4,7 +4,8 @@ Describe "Tests for New-PSDrive cmdlet." -Tag "CI","RequireAdminOnWindows" { Context "Validate New-PSDrive Cmdlet with -Persist switch." { BeforeEach { - $PSDriveName = "W" + $UsedDrives = Get-PSDrive | Select-Object -ExpandProperty Name + $PSDriveName = 'D'..'Z' | Where-Object -FilterScript {$_ -notin $UsedDrives} | Get-Random $RemoteShare = "\\$env:COMPUTERNAME\$($env:SystemDrive.replace(':','$\'))" } @@ -17,12 +18,12 @@ Describe "Tests for New-PSDrive cmdlet." -Tag "CI","RequireAdminOnWindows" { } it "Should throw exception if root is not a remote share." -Skip:(-not $IsWindows) { - { New-PSDrive -Root "TestDrive:\" -PSProvider FileSystem -Name $PSDriveName -Persist -ErrorAction Stop } | Should -Throw -ErrorId 'DriveRootNotNetworkPath' + { New-PSDrive -Name $PSDriveName -PSProvider FileSystem -Root "TestDrive:\" -Persist -ErrorAction Stop } | Should -Throw -ErrorId 'DriveRootNotNetworkPath' } it "Should throw exception if PSDrive is not a drive letter supported by operating system." -Skip:(-not $IsWindows) { $PSDriveName = 'AB' - { New-PSDrive -Root $RemoteShare -PSProvider FileSystem -Name $PSDriveName -Persist -ErrorAction Stop } | Should -Throw -ErrorId 'DriveNameNotSupportedForPersistence' + { New-PSDrive Name $PSDriveName -PSProvider FileSystem -Root $RemoteShare -Persist -ErrorAction Stop } | Should -Throw -ErrorId 'DriveNameNotSupportedForPersistence' } } } From 795a7509071920e9023be0e9636ad64d8b02e39d Mon Sep 17 00:00:00 2001 From: kvprasoon Date: Thu, 29 Nov 2018 22:54:33 +0530 Subject: [PATCH 13/14] Merging from master --- .../commands/management/Navigation.cs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/Navigation.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/Navigation.cs index aaefc0a69b1..33c774f48c1 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/Navigation.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/Navigation.cs @@ -4200,8 +4200,4 @@ protected override void ProcessRecord() #endregion GetProviderCommand #endregion Provider commands -<<<<<<< HEAD -} // namespace Microsoft.PowerShell.Commands -======= } ->>>>>>> 0cc1f06be4c2f5f46852fec65549eb9260555298 From b4c70aabe0c351fd388acb1af4a1df882af9ba36 Mon Sep 17 00:00:00 2001 From: kvprasoon Date: Thu, 29 Nov 2018 23:34:37 +0530 Subject: [PATCH 14/14] Corrrecting Typo in Name parameter --- .../Microsoft.PowerShell.Management/New-PSDrive.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Management/New-PSDrive.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Management/New-PSDrive.Tests.ps1 index c54aceeaca9..16cddb30496 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Management/New-PSDrive.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Management/New-PSDrive.Tests.ps1 @@ -23,7 +23,7 @@ Describe "Tests for New-PSDrive cmdlet." -Tag "CI","RequireAdminOnWindows" { it "Should throw exception if PSDrive is not a drive letter supported by operating system." -Skip:(-not $IsWindows) { $PSDriveName = 'AB' - { New-PSDrive Name $PSDriveName -PSProvider FileSystem -Root $RemoteShare -Persist -ErrorAction Stop } | Should -Throw -ErrorId 'DriveNameNotSupportedForPersistence' + { New-PSDrive -Name $PSDriveName -PSProvider FileSystem -Root $RemoteShare -Persist -ErrorAction Stop } | Should -Throw -ErrorId 'DriveNameNotSupportedForPersistence' } } }