Skip to content

Eventhub: added verification and error message for authorizationrules rights #9548

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

Merged
merged 1 commit into from
Jul 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 0 additions & 4 deletions src/EventHub/EventHub.Test/ScenarioTests/EventHubs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,7 @@ public void EventHubsCRUD()
EventHubsController.NewInstance.RunPsTest(_logger, "EventHubsTests");
}

#if NETSTANDARD
[Fact(Skip = "Fails in NetStandard, investigation needed: $namespaceListKeys.PrimaryConnectionString.Contains($updatedAuthRule.PrimaryKey)")]
#else
[Fact]
#endif
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void EventHubsAuthorizationRulesCRUD()
{
Expand Down
4 changes: 2 additions & 2 deletions src/EventHub/EventHub.Test/ScenarioTests/EventHubsTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,8 @@ function EventHubsAuthTests
Write-Debug "Get Eventhub authorizationRules connectionStrings"
$namespaceListKeys = Get-AzEventHubKey -ResourceGroup $resourceGroupName -Namespace $namespaceName -EventHub $eventHubName -Name $authRuleName

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

# Regentrate the Keys
$policyKey = "PrimaryKey"
Expand Down
4 changes: 0 additions & 4 deletions src/EventHub/EventHub.Test/ScenarioTests/Namespace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,7 @@ public void NamespaceCRUD()
EventHubsController.NewInstance.RunPsTest(_logger, "NamespaceTests");
}

#if NETSTANDARD
[Fact(Skip = "Fails in NetStandard, investigation needed: $namespaceListKeys.PrimaryConnectionString.Contains($updatedAuthRule.PrimaryKey)")]
#else
[Fact]
#endif
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void NamespaceAuthorizationRulesCRUD()
{
Expand Down
6 changes: 3 additions & 3 deletions src/EventHub/EventHub.Test/ScenarioTests/NamespaceTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function NamespaceAuthTests

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

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

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

Write-Debug "Regenrate Authorizationrules Keys"
$policyKey = "PrimaryKey"
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/EventHub/EventHub/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- Additional information about change #1
-->
## Upcoming Release
* added verification and error message for authorizationrules rights if only 'Manage' is assigned

## Version 1.2.0
* Fix for #9231 - Get-AzEventHubNamespace does not return tags
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using System.Collections.Generic;
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
using Microsoft.Azure.Commands.EventHub.Models;
using System;

namespace Microsoft.Azure.Commands.EventHub.Commands
{
Expand Down Expand Up @@ -59,6 +60,12 @@ public override void ExecuteCmdlet()
PSSharedAccessAuthorizationRuleAttributes sasRule = new PSSharedAccessAuthorizationRuleAttributes();
sasRule.Rights = new List<string>();

if (Array.Exists(Rights, element => element == "Manage") && !Array.Exists(Rights, element => element == "Listen") || !Array.Exists(Rights, element => element == "Send"))
{
Exception exManage = new Exception("Assigning 'Manage' to rights requires ‘Listen and ‘Send' to be included with. e.g. @(\"Manage\",\"Listen\",\"Send\")");
throw exManage;
}

foreach (string right in Rights)
{
sasRule.Rights.Add(right);
Expand All @@ -84,6 +91,10 @@ public override void ExecuteCmdlet()
{
WriteError(Eventhub.EventHubsClient.WriteErrorforBadrequest(ex));
}
catch (Exception ex)
{
WriteError(new ErrorRecord(ex, ex.Message, ErrorCategory.OpenError, ex));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using System.Management.Automation;
using System.Collections.Generic;
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
using System;

namespace Microsoft.Azure.Commands.EventHub.Commands
{
Expand Down Expand Up @@ -71,10 +72,18 @@ public override void ExecuteCmdlet()
{
sasRule.Rights = new List<string>();
if (Rights != null && Rights.Length > 0)
{
if (Array.Exists(Rights, element => element == "Manage") && !Array.Exists(Rights, element => element == "Listen") || !Array.Exists(Rights, element => element == "Send"))
{
Exception exManage = new Exception("Assigning 'Manage' to rights requires ‘Listen and ‘Send' to be included with. e.g. @(\"Manage\",\"Listen\",\"Send\")");
throw exManage;
}

foreach (string right in Rights)
{
sasRule.Rights.Add(right);
}
}
}

try
Expand Down Expand Up @@ -116,6 +125,10 @@ public override void ExecuteCmdlet()
{
WriteError(Eventhub.EventHubsClient.WriteErrorforBadrequest(ex));
}
catch (Exception ex)
{
WriteError(new ErrorRecord(ex, ex.Message, ErrorCategory.OpenError, ex));
}
}
}
}