Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid unnecessary path resolution for Get-Acl -LiteralPath #13107

Merged
merged 3 commits into from Jul 31, 2020

Conversation

Shriram0908
Copy link
Contributor

@Shriram0908 Shriram0908 commented Jul 5, 2020

PR Summary

Fix #11566
Removes unnecessary path resolution when using LiteralPath parameter in Get-Acl cmdlet.
Add pester test for Get-Acl cmdlet

PR Context

This PR will resolve the bug reported in #11566. The PR will also reduce the calls made. Adding pester tests to help easier refactoring and to avoid regression.

PR Checklist

@ghost ghost assigned daxian-dbw Jul 5, 2020
@rjmholt rjmholt marked this pull request as draft July 7, 2020 17:20
@rjmholt
Copy link
Collaborator

rjmholt commented Jul 7, 2020

Converted this PR to draft to match the WIP tag. Please feel free to change it back when ready

@@ -1,10 +1,64 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
Describe "Acl cmdlets are available and operate properly" -Tag CI {
It "Get-Acl returns an ACL object" -Pending:(!$IsWindows) {
It "Get-Acl returns an ACL DirectorySecurity object" -Pending:(!$IsWindows) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be better as -Skip if the ACL cmdlets are Windows-specific -- otherwise they may be pending for a long time.

Two other thoughts:

  • I can't remember if there's a mechanism to skip a whole describe, but that might be easier here
  • General thought: we should require some kind of in-code record of why a test is skipped or pending so that we can later re-evaluate

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pester v5 can skip a whole Describe, but there is a lot of work to refactor tests to make things work in there.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the Pester module used here is still not at v5.

Executing all tests in '.\test\powershell\Modules\Microsoft.PowerShell.Security\AclCmdlets.Tests.ps1' with Tags CI', 'Feature

Executing script .\test\powershell\Modules\Microsoft.PowerShell.Security\AclCmdlets.Tests.ps1
  [-] Error occurred in test script '.\test\powershell\Modules\Microsoft.PowerShell.Security\AclCmdlets.Tests.ps1' 0ms
    ParameterBindingException: A parameter cannot be found that matches parameter name 'Skip'.
    at <ScriptBlock>, F:\Source\PowerShell\test\powershell\Modules\Microsoft.PowerShell.Security\AclCmdlets.Tests.ps1: line 3
    at <ScriptBlock>, F:\Source\PowerShell\src\powershell-win-core\bin\Debug\net5.0\win7-x64\publish\Modules\Pester\4.10.1\Pester.psm1: line 1111
    at Invoke-Pester<End>, F:\Source\PowerShell\src\powershell-win-core\bin\Debug\net5.0\win7-x64\publish\Modules\Pester\4.10.1\Pester.psm1: line 1137
Tests completed in 174ms
Tests Passed: 0, Failed: 1, Skipped: 0, Pending: 0, Inconclusive: 0

I installed Pester 5.0.1 version and re-ran the test but the script download a different version of pester and performed the test.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah there's a lot we'd have to update here before we can move to v5 for this repo.

@rjmholt
Copy link
Collaborator

rjmholt commented Jul 9, 2020

@Shriram0908 what remains to bring this PR out of WIP status?

@Shriram0908
Copy link
Contributor Author

@rjmholt, We can bring the PR out of the draft state. I want your opinion on few things. The code that I have changed fixes the issue but I feel that block of code can be refactored a bit. Is it okay to do it in this PR or should I raise a seperate request.

@Shriram0908 Shriram0908 marked this pull request as ready for review July 9, 2020 17:57
@Shriram0908 Shriram0908 changed the title WIP: Fix Get-Acl -LiteralPath "HKLM:Software\Classes\*" behaviour Fix Get-Acl -LiteralPath "HKLM:Software\Classes\*" behaviour Jul 9, 2020
@rjmholt
Copy link
Collaborator

rjmholt commented Jul 9, 2020

Is it okay to do it in this PR or should I raise a seperate request.

Best to do separately I think. Keeps the functional changes separate from the refactoring.

The Get-Acl tests seem to be triggering and failing on *nix though -- do they need to be skipped on those platforms?

@Shriram0908
Copy link
Contributor Author

Best to do separately I think. Keeps the functional changes separate from the refactoring.

Got it. Thanks

The Get-Acl tests seem to be triggering and failing on *nix though -- do they need to be skipped on those platforms?

Yes Get-Acl is only for windows. I will add the -skip. The feature to skip entire describe is not yet added so I tried it to do it differently.

@rjmholt
Copy link
Collaborator

rjmholt commented Jul 9, 2020

I tried it to do it differently.

I think elsewhere a solution I've seen is something like:

BeforeAll {
    $PSDefaultParameterValues["It:Skip"] = -not $IsWindows
}

AfterAll {
    $PSDefaultParameterValues.Remove("It:Skip")
}

@ghost ghost added the Review - Needed The PR is being reviewed label Jul 18, 2020
@ghost
Copy link

ghost commented Jul 18, 2020

This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days.
Maintainer, please provide feedback and/or mark it as Waiting on Author

Copy link

@ANDROID-ZERO-BYTE ANDROID-ZERO-BYTE left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opt.ACL INTEGRATE winsec inv param exec;shell null loop: biassys renew shell param

@rjmholt
Copy link
Collaborator

rjmholt commented Jul 20, 2020

@JamesWTruher this PR could probably use your review

@daxian-dbw
Copy link
Member

@rjmholt @JamesWTruher A gentle ping :) please review the PR when you have time.

@ghost ghost removed the Review - Needed The PR is being reviewed label Jul 30, 2020
@daxian-dbw
Copy link
Member

@PoshChan Please remind me in a day

@PoshChan
Copy link
Collaborator

@daxian-dbw, I do not understand: Please remind me in a day

Commands available in this repo for you:
  • retry <target> this will attempt to retry only the failed jobs for the target pipeline, restart can be used in place of retry
  • rebuild <target> this will perform a complete rebuild of the target pipeline, rerun can be used in place of rebuild Supported values for <target> which can be a comma separated list are: static,windows,macos,linux,ssh,all
  • get failures this will attempt to get the latest failures for all of the target pipelines
  • remind me in <value> <units> this will create a reminder that will be posted after the specified duration <value> is a number, and <units> can be minutes, hours, or days (singular or plural)

@daxian-dbw
Copy link
Member

@PoshChan Please remind me in 1 day

@PoshChan
Copy link
Collaborator

@daxian-dbw, this is the reminder you requested 1 day ago

@daxian-dbw daxian-dbw merged commit 9ceee3e into PowerShell:master Jul 31, 2020
@daxian-dbw daxian-dbw added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label Jul 31, 2020
@daxian-dbw daxian-dbw added this to the 7.1.0-preview.7 milestone Jul 31, 2020
@daxian-dbw daxian-dbw changed the title Fix Get-Acl -LiteralPath "HKLM:Software\Classes\*" behaviour Avoid unnecessary path resolution for Get-Acl -LiteralPath Jul 31, 2020
@daxian-dbw
Copy link
Member

To the maintainer that will work on the change log for the next 7.1 preview:
I updated the commit message when merging but the merging failed. Then I clicked "Try again", and it succeeded, but with the original PR title as the commit message. I have changed the PR title to a better message, which can be used in the change log.

@Shriram0908 Shriram0908 deleted the Get-Acl-#11566 branch August 2, 2020 13:49
@TravisEz13 TravisEz13 modified the milestones: 7.1.0-preview.7, 7.1.0-preview.6 Aug 5, 2020
xtqqczze pushed a commit to xtqqczze/PowerShell that referenced this pull request Aug 8, 2020
…ell#13107)

* Fix PowerShell#11566 bug

Add pester test for Get-Acl cmdlet

* Replace -pending parameter with -skip

* Fix test failing in Linux and MacOS
@ghost
Copy link

ghost commented Aug 17, 2020

🎉v7.1.0-preview.6 has been released which incorporates this pull request.:tada:

Handy links:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Get-Acl -LiteralPath does not find Registry key
7 participants