Skip to content

Commit 2a93135

Browse files
author
Ajit Navasare (MINDTREE LIMITED)
committed
added verification and error message for authorizationrules rights
1 parent dd75640 commit 2a93135

File tree

12 files changed

+2428
-2151
lines changed

12 files changed

+2428
-2151
lines changed

src/ServiceBus/ServiceBus.Test/ScenarioTests/ServiceBusQueueTests.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,7 @@ public void ServiceBusQueue_CURD()
3636
ServiceBusController.NewInstance.RunPsTest(_logger, "ServiceBusQueueTests");
3737
}
3838

39-
#if NETSTANDARD
40-
[Fact(Skip = "Failed assertion: $namespaceListKeys.PrimaryConnectionString.Contains($updatedAuthRule.PrimaryKey)")]
41-
[Trait(Category.RunType, Category.DesktopOnly)]
42-
#else
4339
[Fact]
44-
#endif
4540
[Trait(Category.AcceptanceType, Category.CheckIn)]
4641
public void ServiceBusQueueAuth_CURD()
4742
{

src/ServiceBus/ServiceBus.Test/ScenarioTests/ServiceBusQueueTests.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,8 @@ function ServiceBusQueueAuthTests
179179
Write-Debug "Get Queue authorizationRules connectionStrings"
180180
$namespaceListKeys = Get-AzServiceBusKey -ResourceGroupName $resourceGroupName -Namespace $namespaceName -Queue $queueName -Name $authRuleName
181181

182-
Assert-True {$namespaceListKeys.PrimaryConnectionString.Contains($updatedAuthRule.PrimaryKey)}
183-
Assert-True {$namespaceListKeys.SecondaryConnectionString.Contains($updatedAuthRule.SecondaryKey)}
182+
Assert-True {$namespaceListKeys.PrimaryConnectionString -like "*$($updatedAuthRule.PrimaryKey)*"}
183+
Assert-True {$namespaceListKeys.SecondaryConnectionString -like "*$($updatedAuthRule.SecondaryKey)*"}
184184

185185
# Regentrate the Keys
186186
$policyKey = "PrimaryKey"

src/ServiceBus/ServiceBus.Test/ScenarioTests/ServiceBusServiceTests.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,7 @@ public void ServiceBusNameSpace_CURD_Tests()
3636
ServiceBusController.NewInstance.RunPsTest(_logger, "ServiceBusTests");
3737
}
3838

39-
#if NETSTANDARD
40-
[Fact(Skip = "Failed assertion: $namespaceListKeys.PrimaryConnectionString.Contains($updatedAuthRule.PrimaryKey)")]
41-
[Trait(Category.RunType, Category.DesktopOnly)]
42-
#else
4339
[Fact]
44-
#endif
4540
[Trait(Category.AcceptanceType, Category.CheckIn)]
4641
public void ServiceBusNameSpaceAuth_CURD_Tests()
4742
{

src/ServiceBus/ServiceBus.Test/ScenarioTests/ServiceBusServiceTests.ps1

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,16 @@ function ServiceBusNameSpaceAuthTests
9494
$createdNamespace = Get-AzServiceBusNamespace -ResourceGroupName $resourceGroupName -Name $namespaceName
9595
Assert-AreEqual $createdNamespace.Name $namespaceName
9696

97+
Write-Debug "Create a Namespace Authorization Rule"
98+
Write-Debug "Auth Rule name : $authRuleName"
99+
$result = New-AzServiceBusAuthorizationRule -ResourceGroupName $resourceGroupName -Namespace $namespaceName -Name $authRuleName -Rights @("Listen","Send")
100+
101+
Assert-AreEqual $authRuleName $result.Name
102+
Assert-AreEqual 2 $result.Rights.Count
103+
Assert-True { $result.Rights -Contains "Listen" }
104+
Assert-True { $result.Rights -Contains "Send" }
105+
106+
97107
Write-Debug "Create a Namespace Authorization Rule"
98108
Write-Debug "Auth Rule name : $authRuleName"
99109
$result = New-AzServiceBusAuthorizationRule -ResourceGroupName $resourceGroupName -Namespace $namespaceName -Name $authRuleName -Rights @("Listen","Send")
@@ -170,8 +180,8 @@ function ServiceBusNameSpaceAuthTests
170180
Write-Debug "Get namespace authorizationRules connectionStrings"
171181
$namespaceListKeys = Get-AzServiceBusKey -ResourceGroupName $resourceGroupName -Namespace $namespaceName -Name $authRuleName
172182

173-
Assert-True {$namespaceListKeys.PrimaryConnectionString.Contains($updatedAuthRule.PrimaryKey)}
174-
Assert-True {$namespaceListKeys.SecondaryConnectionString.Contains($updatedAuthRule.SecondaryKey)}
183+
Assert-True {$namespaceListKeys.PrimaryConnectionString -like "*$($updatedAuthRule.PrimaryKey)*"}
184+
Assert-True {$namespaceListKeys.SecondaryConnectionString -like "*$($updatedAuthRule.SecondaryKey)*"}
175185

176186
$policyKey = "PrimaryKey"
177187

src/ServiceBus/ServiceBus.Test/ScenarioTests/ServiceBusTopicTests.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,7 @@ public void ServiceBusTopic_CURD()
3636
ServiceBusController.NewInstance.RunPsTest(_logger, "ServiceBusTopicTests");
3737
}
3838

39-
#if NETSTANDARD
40-
[Fact(Skip = "Failed assertion: $namespaceListKeys.PrimaryConnectionString.Contains($updatedAuthRule.PrimaryKey)")]
41-
[Trait(Category.RunType, Category.DesktopOnly)]
42-
#else
4339
[Fact]
44-
#endif
4540
[Trait(Category.AcceptanceType, Category.CheckIn)]
4641
public void ServiceBusTopicAuth_CURD()
4742
{

src/ServiceBus/ServiceBus.Test/ScenarioTests/ServiceBusTopicTests.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,8 @@ function ServiceBusTopicAuthTests
168168
Write-Debug "Get Topic authorizationRules connectionStrings"
169169
$namespaceListKeys = Get-AzServiceBusKey -ResourceGroupName $resourceGroupName -Namespace $namespaceName -Topic $TopicName -Name $authRuleName
170170

171-
Assert-True {$namespaceListKeys.PrimaryConnectionString.Contains($updatedAuthRule.PrimaryKey)}
172-
Assert-True {$namespaceListKeys.SecondaryConnectionString.Contains($updatedAuthRule.SecondaryKey)}
171+
Assert-True {$namespaceListKeys.PrimaryConnectionString -like "*$($updatedAuthRule.PrimaryKey)*"}
172+
Assert-True {$namespaceListKeys.SecondaryConnectionString -like "*$($updatedAuthRule.SecondaryKey)*"}
173173

174174
# Regentrate the Keys
175175
$policyKey = "PrimaryKey"

src/ServiceBus/ServiceBus.Test/SessionRecords/Microsoft.Azure.Commands.ServiceBus.Test.ScenarioTests.ServiceBusQueueTests/ServiceBusQueueAuth_CURD.json

Lines changed: 867 additions & 806 deletions
Large diffs are not rendered by default.

src/ServiceBus/ServiceBus.Test/SessionRecords/Microsoft.Azure.Commands.ServiceBus.Test.ScenarioTests.ServiceBusServiceTests/ServiceBusNameSpaceAuth_CURD_Tests.json

Lines changed: 689 additions & 555 deletions
Large diffs are not rendered by default.

src/ServiceBus/ServiceBus.Test/SessionRecords/Microsoft.Azure.Commands.ServiceBus.Test.ScenarioTests.ServiceBusTopicTests/ServiceBusTopicAuth_CURD.json

Lines changed: 830 additions & 769 deletions
Large diffs are not rendered by default.

src/ServiceBus/ServiceBus/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
- Additional information about change #1
2020
-->
2121
## Upcoming Release
22+
* added verification and error message for authorizationrules rights if only 'Manage' is assigned
2223

2324
## Version 1.2.1
2425
* Fix for issue #4938 - New-AzureRmServiceBusQueue returns BadRequest when setting MaxSizeInMegabytes

src/ServiceBus/ServiceBus/Cmdlets/AuthorizationRule/NewAzureServiceBusAuthorizationRule.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
using System.Collections.Generic;
1818
using Microsoft.Azure.Management.ServiceBus.Models;
1919
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
20+
using System;
2021

2122
namespace Microsoft.Azure.Commands.ServiceBus.Commands
2223
{
@@ -64,6 +65,12 @@ public override void ExecuteCmdlet()
6465
PSSharedAccessAuthorizationRuleAttributes sasRule = new PSSharedAccessAuthorizationRuleAttributes();
6566
sasRule.Rights = new List<AccessRights?>();
6667

68+
if (Array.Exists(Rights, element => element == "Manage") && !Array.Exists(Rights, element => element == "Listen") || !Array.Exists(Rights, element => element == "Send"))
69+
{
70+
Exception exManage = new Exception("Assigning 'Manage' to rights requires ‘Listen and ‘Send' to be included with. e.g. @(\"Manage\",\"Listen\",\"Send\")");
71+
throw exManage;
72+
}
73+
6774
foreach (string test in Rights)
6875
{
6976
sasRule.Rights.Add(ParseAccessRights(test));
@@ -100,6 +107,10 @@ public override void ExecuteCmdlet()
100107
{
101108
WriteError(ServiceBusClient.WriteErrorforBadrequest(ex));
102109
}
110+
catch (Exception ex)
111+
{
112+
WriteError(new ErrorRecord(ex, ex.Message, ErrorCategory.OpenError, ex));
113+
}
103114

104115
}
105116
}

src/ServiceBus/ServiceBus/Cmdlets/AuthorizationRule/SetAzureServiceBusAuthorizationRule.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15+
using System;
1516
using Microsoft.Azure.Commands.ServiceBus.Models;
1617
using Microsoft.Azure.Management.ServiceBus.Models;
1718
using System.Management.Automation;
@@ -82,10 +83,19 @@ public override void ExecuteCmdlet()
8283
{
8384
sasRule.Rights = new List<AccessRights?>();
8485
if (Rights != null && Rights.Length > 0)
86+
{
87+
if (Array.Exists(Rights, element => element == "Manage") && !Array.Exists(Rights, element => element == "Listen") || !Array.Exists(Rights, element => element == "Send"))
88+
{
89+
Exception exManage = new Exception("Assigning 'Manage' to rights requires ‘Listen and ‘Send' to be included with. e.g. @(\"Manage\",\"Listen\",\"Send\")");
90+
throw exManage;
91+
}
92+
8593
foreach (string test in Rights)
8694
{
8795
sasRule.Rights.Add(ParseAccessRights(test));
8896
}
97+
}
98+
8999
}
90100

91101
if (ParameterSetName.Equals(AuthoRuleInputObjectParameterSet))
@@ -145,6 +155,10 @@ public override void ExecuteCmdlet()
145155
{
146156
WriteError(ServiceBusClient.WriteErrorforBadrequest(ex));
147157
}
158+
catch (Exception ex)
159+
{
160+
WriteError(new ErrorRecord(ex, ex.Message, ErrorCategory.OpenError, ex));
161+
}
148162
}
149163
}
150164
}

0 commit comments

Comments
 (0)