Skip to content

Commit c395bf9

Browse files
authored
Merge pull request #9548 from v-Ajnava/masterIssue5824
Eventhub: added verification and error message for authorizationrules rights
2 parents 5f930f7 + 4bac6f9 commit c395bf9

File tree

9 files changed

+1263
-1063
lines changed

9 files changed

+1263
-1063
lines changed

src/EventHub/EventHub.Test/ScenarioTests/EventHubs.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,7 @@ public void EventHubsCRUD()
3636
EventHubsController.NewInstance.RunPsTest(_logger, "EventHubsTests");
3737
}
3838

39-
#if NETSTANDARD
40-
[Fact(Skip = "Fails in NetStandard, investigation needed: $namespaceListKeys.PrimaryConnectionString.Contains($updatedAuthRule.PrimaryKey)")]
41-
#else
4239
[Fact]
43-
#endif
4440
[Trait(Category.AcceptanceType, Category.CheckIn)]
4541
public void EventHubsAuthorizationRulesCRUD()
4642
{

src/EventHub/EventHub.Test/ScenarioTests/EventHubsTests.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,8 @@ function EventHubsAuthTests
217217
Write-Debug "Get Eventhub authorizationRules connectionStrings"
218218
$namespaceListKeys = Get-AzEventHubKey -ResourceGroup $resourceGroupName -Namespace $namespaceName -EventHub $eventHubName -Name $authRuleName
219219

220-
Assert-True {$namespaceListKeys.PrimaryConnectionString.Contains($updatedAuthRule.PrimaryKey)}
221-
Assert-True {$namespaceListKeys.SecondaryConnectionString.Contains($updatedAuthRule.SecondaryKey)}
220+
Assert-True {$namespaceListKeys.PrimaryConnectionString -like "*$($updatedAuthRule.PrimaryKey)*"}
221+
Assert-True {$namespaceListKeys.SecondaryConnectionString -like "*$($updatedAuthRule.SecondaryKey)*"}
222222

223223
# Regentrate the Keys
224224
$policyKey = "PrimaryKey"

src/EventHub/EventHub.Test/ScenarioTests/Namespace.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,7 @@ public void NamespaceCRUD()
3636
EventHubsController.NewInstance.RunPsTest(_logger, "NamespaceTests");
3737
}
3838

39-
#if NETSTANDARD
40-
[Fact(Skip = "Fails in NetStandard, investigation needed: $namespaceListKeys.PrimaryConnectionString.Contains($updatedAuthRule.PrimaryKey)")]
41-
#else
4239
[Fact]
43-
#endif
4440
[Trait(Category.AcceptanceType, Category.CheckIn)]
4541
public void NamespaceAuthorizationRulesCRUD()
4642
{

src/EventHub/EventHub.Test/ScenarioTests/NamespaceTests.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ function NamespaceAuthTests
5353

5454
Write-Debug "Create a Namespace Authorization Rule"
5555
Write-Debug "Auth Rule name : $authRuleName"
56-
$result = New-AzEventHubAuthorizationRule -ResourceGroup $resourceGroupName -Namespace $namespaceName -Name $authRuleName -Rights @("Listen","Send")
56+
$result = New-AzEventHubAuthorizationRule -ResourceGroup $resourceGroupName -Namespace $namespaceName -Name $authRuleName -Rights @("Listen", "Send")
5757

5858
Assert-AreEqual $authRuleName $result.Name
5959
Assert-AreEqual 2 $result.Rights.Count
@@ -125,8 +125,8 @@ function NamespaceAuthTests
125125
Write-Debug "Get namespace authorizationRules connectionStrings"
126126
$namespaceListKeys = Get-AzEventHubKey -ResourceGroup $resourceGroupName -Namespace $namespaceName -Name $authRuleName
127127

128-
Assert-True {$namespaceListKeys.PrimaryConnectionString.Contains($updatedAuthRule.PrimaryKey)}
129-
Assert-True {$namespaceListKeys.SecondaryConnectionString.Contains($updatedAuthRule.SecondaryKey)}
128+
Assert-True {$namespaceListKeys.PrimaryConnectionString -like "*$($updatedAuthRule.PrimaryKey)*"}
129+
Assert-True {$namespaceListKeys.SecondaryConnectionString -like "*$($updatedAuthRule.SecondaryKey)*"}
130130

131131
Write-Debug "Regenrate Authorizationrules Keys"
132132
$policyKey = "PrimaryKey"

src/EventHub/EventHub.Test/SessionRecords/Microsoft.Azure.Commands.EventHub.Test.ScenarioTests.EventHubsTests/EventHubsAuthorizationRulesCRUD.json

Lines changed: 557 additions & 496 deletions
Large diffs are not rendered by default.

src/EventHub/EventHub.Test/SessionRecords/Microsoft.Azure.Commands.EventHub.Test.ScenarioTests.NamespaceTests/NamespaceAuthorizationRulesCRUD.json

Lines changed: 676 additions & 554 deletions
Large diffs are not rendered by default.

src/EventHub/EventHub/ChangeLog.md

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

2223
## Version 1.2.0
2324
* Fix for #9231 - Get-AzEventHubNamespace does not return tags

src/EventHub/EventHub/Cmdlets/AuthorizationRule/NewAzureEventhubAuthorizationRules.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
using System.Collections.Generic;
1717
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
1818
using Microsoft.Azure.Commands.EventHub.Models;
19+
using System;
1920

2021
namespace Microsoft.Azure.Commands.EventHub.Commands
2122
{
@@ -59,6 +60,12 @@ public override void ExecuteCmdlet()
5960
PSSharedAccessAuthorizationRuleAttributes sasRule = new PSSharedAccessAuthorizationRuleAttributes();
6061
sasRule.Rights = new List<string>();
6162

63+
if (Array.Exists(Rights, element => element == "Manage") && !Array.Exists(Rights, element => element == "Listen") || !Array.Exists(Rights, element => element == "Send"))
64+
{
65+
Exception exManage = new Exception("Assigning 'Manage' to rights requires ‘Listen and ‘Send' to be included with. e.g. @(\"Manage\",\"Listen\",\"Send\")");
66+
throw exManage;
67+
}
68+
6269
foreach (string right in Rights)
6370
{
6471
sasRule.Rights.Add(right);
@@ -84,6 +91,10 @@ public override void ExecuteCmdlet()
8491
{
8592
WriteError(Eventhub.EventHubsClient.WriteErrorforBadrequest(ex));
8693
}
94+
catch (Exception ex)
95+
{
96+
WriteError(new ErrorRecord(ex, ex.Message, ErrorCategory.OpenError, ex));
97+
}
8798
}
8899
}
89100
}

src/EventHub/EventHub/Cmdlets/AuthorizationRule/SetAzureEventhubAuthorizationRules.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
using System.Management.Automation;
1717
using System.Collections.Generic;
1818
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
19+
using System;
1920

2021
namespace Microsoft.Azure.Commands.EventHub.Commands
2122
{
@@ -71,10 +72,18 @@ public override void ExecuteCmdlet()
7172
{
7273
sasRule.Rights = new List<string>();
7374
if (Rights != null && Rights.Length > 0)
75+
{
76+
if (Array.Exists(Rights, element => element == "Manage") && !Array.Exists(Rights, element => element == "Listen") || !Array.Exists(Rights, element => element == "Send"))
77+
{
78+
Exception exManage = new Exception("Assigning 'Manage' to rights requires ‘Listen and ‘Send' to be included with. e.g. @(\"Manage\",\"Listen\",\"Send\")");
79+
throw exManage;
80+
}
81+
7482
foreach (string right in Rights)
7583
{
7684
sasRule.Rights.Add(right);
7785
}
86+
}
7887
}
7988

8089
try
@@ -116,6 +125,10 @@ public override void ExecuteCmdlet()
116125
{
117126
WriteError(Eventhub.EventHubsClient.WriteErrorforBadrequest(ex));
118127
}
128+
catch (Exception ex)
129+
{
130+
WriteError(new ErrorRecord(ex, ex.Message, ErrorCategory.OpenError, ex));
131+
}
119132
}
120133
}
121134
}

0 commit comments

Comments
 (0)