Closed markaugust closed 6 months ago
Thanks for submitting this issue and the detailed run down. Your suggested fix looks good. Do you have time to send in a PR with the fix?
@johlju I created a pull request. I was able to test in my environment, and that seemed to work, but if you have access to a more robust testing environment, by all means, I'd love some additional eyes on it. I also added an Insert permission object in the unit test. Let me know if that was not appropriate/needed, and I can remove it. The other tasks in the Task List didn't seem appropriate here, but let me know if you disagree and I can make further updates.
Looks good, I made a review and would be great to change the mock according to my comment.
@johlju Fixed the mock and got the unit tests to pass
Problem description
When you are only granting INSERT permissions on a table, if INSERT is the only permission on the table, everything works as expected. However, when there are permissions on the table other than INSERT (such as SELECT/GRANT/UPDATE), the testing of the resource will always show
InDesiredState = False
Here is a screenshot showing with just INSERT it works as expected:
Here is a screenshot showing that even though both the DELETE and INSERT permissions have been set, it's stating that the permissions are not in a desired state:
I believe it has something to do with this line in the code.
if ($true -in $currentObjectPermissions.PermissionType.$currentPermissionProperty)
If I test that code outside of this module, we see that the
if ($true -in $currentObjectPermissions.PermissionType.$currentPermissionProperty)
block doesn't actually work with INSERTPulling the
if
block test out by itself, we get:And looking at just
CurrentObjectPermissions.PermissionType.Insert
we get the following:Verbose logs
DSC configuration
Suggested solution
My proposed solution is this:
If we wrap the
if ($true -in $currentObjectPermissions.PermissionType.$currentPermissionProperty)
block in it's own foreach loop, then it seems to work.This is because when you have multiple permissions, the
$currentObjectPermissions
is an array and has theInsert
as anIList
method.But if you look at an individual item in the array, then the
Insert
is actually a property as expectedSQL Server edition and version
SQL Server PowerShell modules
Operating system
PowerShell version
SqlServerDsc version