@@ -86,19 +86,19 @@ Describe 'Set-SqlDscServerPermission' -Tag 'Public' {
8686 $parameterInfo.Attributes.Mandatory | Should - BeTrue
8787 }
8888
89- It ' Should have Grant parameter accept pipeline input' {
89+ It ' Should have Grant parameter not accept pipeline input' {
9090 $parameterInfo = (Get-Command - Name ' Set-SqlDscServerPermission' ).Parameters[' Grant' ]
9191
9292 $parameterInfo.Attributes.ValueFromPipeline | Should - BeFalse
9393 }
9494
95- It ' Should have GrantWithGrant parameter accept pipeline input' {
95+ It ' Should have GrantWithGrant parameter not accept pipeline input' {
9696 $parameterInfo = (Get-Command - Name ' Set-SqlDscServerPermission' ).Parameters[' GrantWithGrant' ]
9797
9898 $parameterInfo.Attributes.ValueFromPipeline | Should - BeFalse
9999 }
100100
101- It ' Should have Deny parameter accept pipeline input' {
101+ It ' Should have Deny parameter not accept pipeline input' {
102102 $parameterInfo = (Get-Command - Name ' Set-SqlDscServerPermission' ).Parameters[' Deny' ]
103103
104104 $parameterInfo.Attributes.ValueFromPipeline | Should - BeFalse
@@ -492,6 +492,60 @@ Describe 'Set-SqlDscServerPermission' -Tag 'Public' {
492492 Should - Invoke - CommandName Grant-SqlDscServerPermission - Exactly - Times 1 - Scope It
493493 }
494494 }
495+
496+ Context ' When revoking permissions' {
497+ BeforeAll {
498+ $mockServerObject = New-Object - TypeName ' Microsoft.SqlServer.Management.Smo.Server'
499+ $mockServerObject.InstanceName = ' MockInstance'
500+
501+ $mockServerRoleObject = New-Object - TypeName ' Microsoft.SqlServer.Management.Smo.ServerRole' - ArgumentList @ ($mockServerObject , ' MyServerRole' )
502+
503+ # Create mock ServerPermissionInfo objects
504+ $mockServerPermissionInfo = @ (
505+ New-Object - TypeName ' Microsoft.SqlServer.Management.Smo.ServerPermissionInfo'
506+ )
507+
508+ Mock - CommandName Get-SqlDscServerPermission - MockWith {
509+ return $mockServerPermissionInfo
510+ }
511+
512+ Mock - CommandName ConvertTo-SqlDscServerPermission - MockWith {
513+ return InModuleScope - ScriptBlock {
514+ @ (
515+ [ServerPermission ]@ {
516+ State = ' Grant'
517+ Permission = @ (' ConnectSql' )
518+ }
519+ [ServerPermission ]@ {
520+ State = ' GrantWithGrant'
521+ Permission = @ ()
522+ }
523+ [ServerPermission ]@ {
524+ State = ' Deny'
525+ Permission = @ ()
526+ }
527+ )
528+ }
529+ }
530+
531+ Mock - CommandName Grant-SqlDscServerPermission
532+ Mock - CommandName Deny-SqlDscServerPermission
533+ Mock - CommandName Revoke-SqlDscServerPermission
534+ }
535+
536+ It ' Should revoke all permissions when empty Grant array is specified' {
537+ Set-SqlDscServerPermission - ServerRole $mockServerRoleObject - Grant @ () - Force
538+
539+ Should - Invoke - CommandName Get-SqlDscServerPermission - Exactly - Times 1 - Scope It
540+
541+ # Should revoke ConnectSql
542+ Should - Invoke - CommandName Revoke-SqlDscServerPermission - ParameterFilter {
543+ $Permission -contains ' ConnectSql'
544+ } - Exactly - Times 1 - Scope It
545+
546+ Should - Invoke - CommandName Grant-SqlDscServerPermission - Exactly - Times 0 - Scope It
547+ }
548+ }
495549 }
496550
497551 Context ' When setting multiple permission states at once' {
0 commit comments