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

Fix : windows_firewall_rule fails to validate more than 1 rule depending on how it's executed #5502

Merged
merged 1 commit into from
May 5, 2021

Conversation

Vasu1105
Copy link
Contributor

@Vasu1105 Vasu1105 commented May 4, 2021

Signed-off-by: Vasu1105 vasundhara.jagdale@chef.io

Description

windows_firewall_rule is using Remove-TypeData System.Array as a workaround for PS bug here: https://bit.ly/2SRMQ8M,
Remove-TypeData Deletes extended types from the current session.Ref So when we are executing more that one rules using different describe blocks as we have already deleted the extended type in the same session when next describe was getting called that command was giving error. due to which the cmd output was coming blank due to which the result was empty for next set of rules.

Following is the output of executing the Remove-TypeData in same Poweshell window(same session)

PS C:\Users\Vasundhara> Get-TypeData -TypeName System.Array

TypeName     Members
--------     -------
System.Array {[Count, System.Management.Automation.Runspaces.AliasPropertyData]}


PS C:\Users\Vasundhara> Remove-TypeData -TypeName System.Array
PS C:\Users\Vasundhara> Remove-TypeData -TypeName System.Array
Remove-TypeData : Error in TypeData "System.Array": The type "System.Array" was not found. The type name value must be
the full name of the type. Verify the type name and run the command again.
At line:1 char:1
+ Remove-TypeData -TypeName System.Array
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Remove-TypeData], RuntimeException
    + FullyQualifiedErrorId : TypesDynamicRemoveException,Microsoft.PowerShell.Commands.RemoveTypeDataCommand

PS C:\Users\Vasundhara>

So as a solution we are using Get-TypeData command to get extended type in current session and pipe it to the Remove-TypeData so if there is not System.Array in current session then it will not cause any issue. REF : https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/get-typedata?view=powershell-7.1

Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

PS C:\Users\Vasundhara> Get-TypeData -TypeName System.Array

TypeName     Members
--------     -------
System.Array {[Count, System.Management.Automation.Runspaces.AliasPropertyData]}


PS C:\Users\Vasundhara> Get-TypeData -TypeName System.Array | Remove-TypeData
PS C:\Users\Vasundhara> Get-TypeData -TypeName System.Array

Related Issue

Fix #5464

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New content (non-breaking change)
  • Breaking change (a content change which would break existing functionality or processes)

Checklist:

  • I have read the CONTRIBUTING document.

… session which was resulting into windows_firewall_rule was not working correctly locally when we have more than one describe block for windows_firewall_rule resource

Signed-off-by: Vasu1105 <vasundhara.jagdale@chef.io>
@Vasu1105 Vasu1105 requested a review from a team as a code owner May 4, 2021 09:35
@netlify
Copy link

netlify bot commented May 4, 2021

Deploy preview for chef-inspec canceled.

Built with commit 95656f9

https://app.netlify.com/sites/chef-inspec/deploys/6091154e5edf06000771c60b

@Vasu1105
Copy link
Contributor Author

Vasu1105 commented May 4, 2021

@clintoncwolfe : I think currently I can't add test case for this as this needs that command to be executed on real system and currently I haven't found any test cases written for windows_firewall_rule. So may be we can add the test cases once we have our kitchen test environment ready for testing . But for now this fixes the issue.

@Vasu1105
Copy link
Contributor Author

Vasu1105 commented May 4, 2021

Local output before fix
Screenshot from 2021-05-04 15-14-03

Local output after fix
Screenshot from 2021-05-04 15-14-44

@clintoncwolfe clintoncwolfe added Type: Bug Feature not working as expected Component: Core Resources Resources shipped with InSpec. Platform: Windows Windows-specific issues labels May 5, 2021
@clintoncwolfe clintoncwolfe merged commit 82bfc9f into master May 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Core Resources Resources shipped with InSpec. Platform: Windows Windows-specific issues Type: Bug Feature not working as expected
Projects
None yet
Development

Successfully merging this pull request may close these issues.

windows_firewall_rule fails to validate more than 1 rule depending on how it's executed
2 participants