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

ServiceBus: Fix for issue #9786 : cannot create a rule with Listen only rights #9822

Merged
merged 2 commits into from
Aug 18, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ function ServiceBusQueueAuthTests
$namespaceName = getAssetName "Namespace-"
$queueName = getAssetName "Queue-"
$authRuleName = getAssetName "authorule-"
$authRuleNameListen = getAssetName "authorule-"
$authRuleNameSend = getAssetName "authorule-"
$authRuleNameAll = getAssetName "authorule-"

# Create ResourceGroup
Write-Debug " Create resource group"
Expand Down Expand Up @@ -133,6 +136,22 @@ function ServiceBusQueueAuthTests
Assert-True { $result.Rights -Contains "Listen" }
Assert-True { $result.Rights -Contains "Send" }

$resultListen = New-AzServiceBusAuthorizationRule -ResourceGroupName $resourceGroupName -Namespace $namespaceName -Queue $queueName -Name $authRuleNameListen -Rights @("Listen")
Assert-AreEqual $authRuleNameListen $resultListen.Name
Assert-AreEqual 1 $resultListen.Rights.Count
Assert-True { $resultListen.Rights -Contains "Listen" }

$resultSend = New-AzServiceBusAuthorizationRule -ResourceGroupName $resourceGroupName -Namespace $namespaceName -Queue $queueName -Name $authRuleNameSend -Rights @("Send")
Assert-AreEqual $authRuleNameSend $resultSend.Name
Assert-AreEqual 1 $resultSend.Rights.Count
Assert-True { $resultSend.Rights -Contains "Send" }

$resultAll3 = New-AzServiceBusAuthorizationRule -ResourceGroupName $resourceGroupName -Namespace $namespaceName -Queue $queueName -Name $authRuleNameAll -Rights @("Listen","Send","Manage")
Assert-AreEqual $authRuleNameAll $resultAll3.Name
Assert-AreEqual 3 $resultAll3.Rights.Count
Assert-True { $resultAll3.Rights -Contains "Send" }
Assert-True { $resultAll3.Rights -Contains "Listen" }
Assert-True { $resultAll3.Rights -Contains "Manage" }

cormacpayne marked this conversation as resolved.
Show resolved Hide resolved
# Get Created Queue Authorization Rule
Write-Debug "Get created authorizationRule"
Expand All @@ -148,10 +167,7 @@ function ServiceBusQueueAuthTests
Write-Debug "Get All Queue AuthorizationRule"
$result = Get-AzServiceBusAuthorizationRule -ResourceGroupName $resourceGroupName -Namespace $namespaceName -Queue $queueName
# Assert
Assert-AreEqual $result.Name $authRuleName
Assert-AreEqual 2 $result.Rights.Count
Assert-True { $result.Rights -Contains "Listen" }
Assert-True { $result.Rights -Contains "Send" }
Assert-True {$result.Count -ge 2}

# Update the Queue Authorization Rule
Write-Debug "Update Queue AuthorizationRule"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ function ServiceBusNameSpaceAuthTests
$resourceGroupName = getAssetName "RGName-"
$namespaceName = getAssetName "Namespace-"
$authRuleName = getAssetName "authorule-"
$authRuleNameListen = getAssetName "authorule-"
$authRuleNameSend = getAssetName "authorule-"
$authRuleNameAll = getAssetName "authorule-"
$defaultNamespaceAuthRule = "RootManageSharedAccessKey"

Write-Debug " Create resource group"
Expand All @@ -103,6 +106,22 @@ function ServiceBusNameSpaceAuthTests
Assert-True { $result.Rights -Contains "Listen" }
Assert-True { $result.Rights -Contains "Send" }

$resultListen = New-AzServiceBusAuthorizationRule -ResourceGroupName $resourceGroupName -Namespace $namespaceName -Name $authRuleNameListen -Rights @("Listen")
Assert-AreEqual $authRuleNameListen $resultListen.Name
Assert-AreEqual 1 $resultListen.Rights.Count
Assert-True { $resultListen.Rights -Contains "Listen" }

$resultSend = New-AzServiceBusAuthorizationRule -ResourceGroupName $resourceGroupName -Namespace $namespaceName -Name $authRuleNameSend -Rights @("Send")
Assert-AreEqual $authRuleNameSend $resultSend.Name
Assert-AreEqual 1 $resultSend.Rights.Count
Assert-True { $resultSend.Rights -Contains "Send" }

$resultAll3 = New-AzServiceBusAuthorizationRule -ResourceGroupName $resourceGroupName -Namespace $namespaceName -Name $authRuleNameAll -Rights @("Listen","Send","Manage")
Assert-AreEqual $authRuleNameAll $resultAll3.Name
Assert-AreEqual 3 $resultAll3.Rights.Count
Assert-True { $resultAll3.Rights -Contains "Send" }
Assert-True { $resultAll3.Rights -Contains "Listen" }
Assert-True { $resultAll3.Rights -Contains "Manage" }

Write-Debug "Create a Namespace Authorization Rule"
Write-Debug "Auth Rule name : $authRuleName"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ function ServiceBusTopicAuthTests
$namespaceName = getAssetName "Namespace-"
$TopicName = getAssetName "Topic-"
$authRuleName = getAssetName "authorule-"
$authRuleNameListen = getAssetName "authorule-"
$authRuleNameSend = getAssetName "authorule-"
$authRuleNameAll = getAssetName "authorule-"

# Create ResourceGroup
Write-Debug " Create resource group"
Expand Down Expand Up @@ -120,7 +123,24 @@ function ServiceBusTopicAuthTests
Assert-AreEqual $result.Name $authRuleName "New-AzServiceBusAuthorizationRule: Created Authorizationrule not found"
Assert-AreEqual 2 $result.Rights.Count "New-AzServiceBusAuthorizationRule: Rights count dont match"
Assert-True { $result.Rights -Contains "Listen" }
Assert-True { $result.Rights -Contains "Send" }
Assert-True { $result.Rights -Contains "Send" }

$resultListen = New-AzServiceBusAuthorizationRule -ResourceGroupName $resourceGroupName -Namespace $namespaceName -Topic $TopicName -Name $authRuleNameListen -Rights @("Listen")
Assert-AreEqual $authRuleNameListen $resultListen.Name
Assert-AreEqual 1 $resultListen.Rights.Count
Assert-True { $resultListen.Rights -Contains "Listen" }

$resultSend = New-AzServiceBusAuthorizationRule -ResourceGroupName $resourceGroupName -Namespace $namespaceName -Topic $TopicName -Name $authRuleNameSend -Rights @("Send")
Assert-AreEqual $authRuleNameSend $resultSend.Name
Assert-AreEqual 1 $resultSend.Rights.Count
Assert-True { $resultSend.Rights -Contains "Send" }

$resultAll3 = New-AzServiceBusAuthorizationRule -ResourceGroupName $resourceGroupName -Namespace $namespaceName -Topic $TopicName -Name $authRuleNameAll -Rights @("Listen","Send","Manage")
Assert-AreEqual $authRuleNameAll $resultAll3.Name
Assert-AreEqual 3 $resultAll3.Rights.Count
Assert-True { $resultAll3.Rights -Contains "Send" }
Assert-True { $resultAll3.Rights -Contains "Listen" }
Assert-True { $resultAll3.Rights -Contains "Manage" }

# Get Created Topic Authorization Rule
Write-Debug "Get created authorizationRule"
Expand All @@ -132,16 +152,7 @@ function ServiceBusTopicAuthTests
Assert-True { $createdAuthRule.Rights -Contains "Listen" }
Assert-True { $createdAuthRule.Rights -Contains "Send" }

# Get all Topic Authorization Rules
Write-Debug "Get All Topic AuthorizationRule"
$result = Get-AzServiceBusAuthorizationRule -ResourceGroupName $resourceGroupName -Namespace $namespaceName -Topic $TopicName
# Assert

Assert-AreEqual $result.Name $authRuleName "Topic AuthorizationRule created earlier is not found."
Assert-AreEqual 2 $result.Rights.Count
Assert-True { $result.Rights -Contains "Listen" }
Assert-True { $result.Rights -Contains "Send" }


# Update the Topic Authorization Rule
Write-Debug "Update Topic AuthorizationRule"
$createdAuthRule.Rights.Add("Manage")
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/ServiceBus/ServiceBus/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
## Upcoming Release
* Fixed miscellaneous typos across module
* Fix for issue #9658 : Typo VirtualNetworkRule parameter in Set-AzServiceBusNetworkRuleSet
* Fix for issue #9786 : cannot create a rule with Listen only rights

## Version 1.3.0
* Added new cmmdlet added for generating SAS token : New-AzServiceBusAuthorizationRuleSASToken
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public override void ExecuteCmdlet()
PSSharedAccessAuthorizationRuleAttributes sasRule = new PSSharedAccessAuthorizationRuleAttributes();
sasRule.Rights = new List<AccessRights?>();

if (Array.Exists(Rights, element => element == "Manage") && !Array.Exists(Rights, element => element == "Listen") || !Array.Exists(Rights, element => element == "Send"))
if (Array.Exists(Rights, element => element == "Manage") && (!Array.Exists(Rights, element => element == "Listen") || !Array.Exists(Rights, element => element == "Send")))
{
cormacpayne marked this conversation as resolved.
Show resolved Hide resolved
Exception exManage = new Exception("Assigning 'Manage' to rights requires ‘Listen and ‘Send' to be included with. e.g. @(\"Manage\",\"Listen\",\"Send\")");
throw exManage;
Expand Down