Skip to content

[EventHub] TrustedServiceAccess bug fix. #18128

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 2 commits into from
May 13, 2022
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
32 changes: 29 additions & 3 deletions src/EventHub/EventHub.Test/ScenarioTests/NetworkRuleSetTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,43 @@ function NetworkRuleSetTests
Assert-AreEqual $setResult2.IpRules.Count 3 "Set - IPRules count did not matched"
Assert-AreEqual $setResult2.PublicNetworkAccess "Enabled"
Assert-AreEqual $setResult2.DefaultAction "Allow"
Assert-True {$setResult.TrustedServiceAccessEnabled}
Assert-True {$setResult2.TrustedServiceAccessEnabled}

$setResult2 = Set-AzEventHubNetworkRuleSet -ResourceGroup $resourceGroupName -Name $namespaceName2 -PublicNetworkAccess "Disabled"
Assert-AreEqual $setResult2.VirtualNetworkRules.Count 3 "Set -VirtualNetworkRules count did not matched"
Assert-AreEqual $setResult2.IpRules.Count 3 "Set - IPRules count did not matched"
Assert-AreEqual $setResult2.PublicNetworkAccess "Disabled"
Assert-AreEqual $setResult2.DefaultAction "Allow"

$setResult2 = Set-AzEventHubNetworkRuleSet -ResourceGroup $resourceGroupName -Name $namespaceName2 -PublicNetworkAccess "Enabled"
Assert-AreEqual $setResult2.VirtualNetworkRules.Count 3 "Set -VirtualNetworkRules count did not matched"
Assert-AreEqual $setResult2.IpRules.Count 3 "Set - IPRules count did not matched"
Assert-AreEqual $setResult2.PublicNetworkAccess "Enabled"
Assert-AreEqual $setResult2.DefaultAction "Allow"

$setResult2 = Set-AzEventHubNetworkRuleSet -ResourceGroup $resourceGroupName -Name $namespaceName2 -TrustedServiceAccessEnabled
Assert-AreEqual $setResult2.VirtualNetworkRules.Count 3 "Set -VirtualNetworkRules count did not matched"
Assert-AreEqual $setResult2.IpRules.Count 3 "Set - IPRules count did not matched"
Assert-AreEqual $setResult2.PublicNetworkAccess "Enabled"
Assert-AreEqual $setResult2.DefaultAction "Allow"
Assert-True {$setResult2.TrustedServiceAccessEnabled}

$setResult2 = Set-AzEventHubNetworkRuleSet -ResourceGroup $resourceGroupName -Name $namespaceName2 -TrustedServiceAccessEnabled:$false
Assert-AreEqual $setResult2.VirtualNetworkRules.Count 3 "Set -VirtualNetworkRules count did not matched"
Assert-AreEqual $setResult2.IpRules.Count 3 "Set - IPRules count did not matched"
Assert-AreEqual $setResult2.PublicNetworkAccess "Enabled"
Assert-AreEqual $setResult2.DefaultAction "Allow"
Assert-AreEqual $setResult2.TrustedServiceAccessEnabled $null

$a, $b, $c = $setResult2.IpRules
$setResult2.IpRules = $c = [Microsoft.Azure.Commands.EventHub.Models.PSNWRuleSetIpRulesAttributes[]]@($a, $b)
$setResult2.IpRules = [Microsoft.Azure.Commands.EventHub.Models.PSNWRuleSetIpRulesAttributes[]]@($a, $b)

$setResult2 = Set-AzEventHubNetworkRuleSet -ResourceGroup $resourceGroupName -Name $namespaceName2 -IPRule $setResult2.IpRules
Assert-AreEqual $setResult2.VirtualNetworkRules.Count 3 "Set -VirtualNetworkRules count did not matched"
Assert-AreEqual $setResult2.IpRules.Count 2 "Set - IPRules count did not matched"
Assert-AreEqual $setResult2.PublicNetworkAccess "Enabled"
Assert-AreEqual $setResult2.DefaultAction "Allow"
Assert-True {$setResult.TrustedServiceAccessEnabled}
Assert-AreEqual $setResult2.TrustedServiceAccessEnabled $null

Write-Debug "Add a new VirtualNetworkRule to the default NetworkRuleSet"
$result = Remove-AzEventHubVirtualNetworkRule -ResourceGroup $resourceGroupName -Name $namespaceName -SubnetId "/subscriptions/326100e2-f69d-4268-8503-075374f62b6e/resourcegroups/v-ajnavtest/providers/Microsoft.Network/virtualNetworks/sbehvnettest1/subnets/default"
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
using Microsoft.Azure.Commands.ResourceManager.Common.Tags;
using Microsoft.Azure.Management.Internal.Resources.Utilities.Models;
using Microsoft.WindowsAzure.Commands.Utilities.Common;
using System.Linq;
using System.Management.Automation;

Expand Down Expand Up @@ -81,10 +82,17 @@ public override void ExecuteCmdlet()
{
if (ParameterSetName.Equals(NetwrokruleSetPropertiesParameterSet))
{
bool? trustedServiceAccessEnabled = null;

if(this.IsParameterBound(c => c.TrustedServiceAccessEnabled) == true)
{
trustedServiceAccessEnabled = TrustedServiceAccessEnabled.IsPresent;
}

WriteObject(Client.UpdateNetworkRuleSet(resourceGroupName: ResourceGroupName,
namespaceName: Name,
publicNetworkAccess: PublicNetworkAccess,
trustedServiceAccessEnabled: TrustedServiceAccessEnabled,
trustedServiceAccessEnabled: trustedServiceAccessEnabled,
defaultAction: DefaultAction,
iPRule: IPRule,
virtualNetworkRule: VirtualNetworkRule));
Expand Down
1 change: 0 additions & 1 deletion src/EventHub/EventHub/Models/PSNetworkRuleSetAttributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public PSNetworkRuleSetAttributes(NetworkRuleSet networkRuleSet)
Name = networkRuleSet.Name;
Type = networkRuleSet.Type;
PublicNetworkAccess = networkRuleSet?.PublicNetworkAccess;
TrustedServiceAccessEnabled = networkRuleSet?.TrustedServiceAccessEnabled;
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/EventHub/EventHub/Utilities/EventHubsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,7 @@ public PSNetworkRuleSetAttributes UpdateNetworkRuleSet(string resourceGroupName,
networkRuleSet.PublicNetworkAccess = publicNetworkAccess;
}

if (trustedServiceAccessEnabled == true)
if (trustedServiceAccessEnabled != null)
{
networkRuleSet.TrustedServiceAccessEnabled = trustedServiceAccessEnabled;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,37 @@ function NetworkRuleSetTests {
Assert-AreEqual $setResult.DefaultAction "Allow"
Assert-True {$setResult.TrustedServiceAccessEnabled}

$a, $b, $c = $setResult.IpRules
$setResult.IpRules = [Microsoft.Azure.Commands.ServiceBus.Models.PSNWRuleSetIpRulesAttributes[]]@($a, $b)

$setResult2 = Set-AzServiceBusNetworkRuleSet -ResourceGroup $resourceGroupName -Name $namespaceName2 -IPRule $setResult.IpRules
Assert-AreEqual $setResult2.VirtualNetworkRules.Count 3 "Set -VirtualNetworkRules count did not matched"
Assert-AreEqual $setResult2.IpRules.Count 2 "Set - IPRules count did not matched"
Assert-AreEqual $setResult2.PublicNetworkAccess "Disabled"
Assert-AreEqual $setResult2.DefaultAction "Allow"
Assert-True {$setResult2.TrustedServiceAccessEnabled}

$setResult2 = Set-AzServiceBusNetworkRuleSet -ResourceGroup $resourceGroupName -Name $namespaceName2 -TrustedServiceAccessEnabled:$false
Assert-AreEqual $setResult2.VirtualNetworkRules.Count 3 "Set -VirtualNetworkRules count did not matched"
Assert-AreEqual $setResult2.IpRules.Count 2 "Set - IPRules count did not matched"
Assert-AreEqual $setResult2.PublicNetworkAccess "Disabled"
Assert-AreEqual $setResult2.DefaultAction "Allow"
Assert-AreEqual $setResult2.TrustedServiceAccessEnabled $null

$setResult2 = Set-AzServiceBusNetworkRuleSet -ResourceGroup $resourceGroupName -Name $namespaceName2 -PublicNetworkAccess "Enabled"
Assert-AreEqual $setResult2.VirtualNetworkRules.Count 3 "Set -VirtualNetworkRules count did not matched"
Assert-AreEqual $setResult2.IpRules.Count 2 "Set - IPRules count did not matched"
Assert-AreEqual $setResult2.PublicNetworkAccess "Enabled"
Assert-AreEqual $setResult2.DefaultAction "Allow"
Assert-AreEqual $setResult2.TrustedServiceAccessEnabled $null

$setResult2 = Set-AzServiceBusNetworkRuleSet -ResourceGroup $resourceGroupName -Name $namespaceName2 -TrustedServiceAccessEnabled
Assert-AreEqual $setResult2.VirtualNetworkRules.Count 3 "Set -VirtualNetworkRules count did not matched"
Assert-AreEqual $setResult2.IpRules.Count 2 "Set - IPRules count did not matched"
Assert-AreEqual $setResult2.PublicNetworkAccess "Enabled"
Assert-AreEqual $setResult2.DefaultAction "Allow"
Assert-True {$setResult2.TrustedServiceAccessEnabled}

# Set-AzServiceBusNetworkRuleSet with Resource ID
$setResult1 = Set-AzServiceBusNetworkRuleSet -ResourceGroup $resourceGroupName -Name $namespaceName2 -ResourceId $getResult.Id
Assert-AreEqual $setResult1.IpRules.Count 2 "Set1 - IPRules count did not matched after deleting one IPRule"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ function MSITest{
Assert-AreEqual $namespace.IdentityType "SystemAssignedUserAssigned"
Assert-True { $namespace.IdentityId.Count -eq 2 }

$namespace = Set-AzServiceBusNamespace -ResourceGroupName $resourceGroupName -Name $namespace1 -IdentityType "None"
$namespace = Set-AzServiceBusNamespace -ResourceGroupName $resourceGroupName -Name $namespace1 -IdentityType "None" -IdentityId @()
Assert-AreEqual $namespace.Name $namespace1
Assert-AreEqual $namespace.Sku.Name "Standard"
Assert-Null $namespace.Identity
Expand Down

Large diffs are not rendered by default.

7 changes: 0 additions & 7 deletions src/ServiceBus/ServiceBus.sln
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestFx", "..\..\tools\TestF
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "KeyVault", "..\KeyVault\KeyVault\KeyVault.csproj", "{17E839DC-E8A6-4F76-A944-4D5D78750A14}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ManagedServiceIdentity", "..\ManagedServiceIdentity\Az.ManagedServiceIdentity.csproj", "{F74BF6BC-707A-4009-8966-C6DD0FD366C9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -66,18 +64,13 @@ Global
{17E839DC-E8A6-4F76-A944-4D5D78750A14}.Debug|Any CPU.Build.0 = Debug|Any CPU
{17E839DC-E8A6-4F76-A944-4D5D78750A14}.Release|Any CPU.ActiveCfg = Release|Any CPU
{17E839DC-E8A6-4F76-A944-4D5D78750A14}.Release|Any CPU.Build.0 = Release|Any CPU
{F74BF6BC-707A-4009-8966-C6DD0FD366C9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F74BF6BC-707A-4009-8966-C6DD0FD366C9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F74BF6BC-707A-4009-8966-C6DD0FD366C9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F74BF6BC-707A-4009-8966-C6DD0FD366C9}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{B36F96EC-A9C1-4C86-B406-472FF4458C9E} = {95C16AED-FD57-42A0-86C3-2CF4300A4817}
{17E839DC-E8A6-4F76-A944-4D5D78750A14} = {95C16AED-FD57-42A0-86C3-2CF4300A4817}
{F74BF6BC-707A-4009-8966-C6DD0FD366C9} = {95C16AED-FD57-42A0-86C3-2CF4300A4817}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {17506674-1FDE-4F1D-A97F-2C565FA7198D}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using Microsoft.Azure.Management.Internal.Resources.Utilities.Models;
using System.Linq;
using System.Management.Automation;
using Microsoft.WindowsAzure.Commands.Utilities.Common;

namespace Microsoft.Azure.Commands.ServiceBus.Commands.NetworkruleSet
{
Expand Down Expand Up @@ -79,10 +80,18 @@ public override void ExecuteCmdlet()

if (ParameterSetName.Equals(NetworkRuleSetPropertiesParameterSet))
{
bool? trustedServiceAccessEnabled = null;

if (this.IsParameterBound(c => c.TrustedServiceAccessEnabled) == true)
{
trustedServiceAccessEnabled = TrustedServiceAccessEnabled.IsPresent;
}


WriteObject(Client.UpdateNetworkRuleSet(resourceGroupName: ResourceGroupName,
namespaceName: Name,
publicNetworkAccess: PublicNetworkAccess,
trustedServiceAccessEnabled: TrustedServiceAccessEnabled,
trustedServiceAccessEnabled: trustedServiceAccessEnabled,
defaultAction: DefaultAction,
iPRule: IPRule,
virtualNetworkRule: VirtualNetworkRule));
Expand Down
4 changes: 2 additions & 2 deletions src/ServiceBus/ServiceBus/Utilities/ServiceBusClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ public PSNetworkRuleSetAttributes CreateOrUpdateNetworkRuleSet(string resourceGr
return new PSNetworkRuleSetAttributes(response);
}

public PSNetworkRuleSetAttributes UpdateNetworkRuleSet(string resourceGroupName, string namespaceName, string publicNetworkAccess, bool trustedServiceAccessEnabled, string defaultAction, PSNWRuleSetIpRulesAttributes[] iPRule, PSNWRuleSetVirtualNetworkRulesAttributes[] virtualNetworkRule)
public PSNetworkRuleSetAttributes UpdateNetworkRuleSet(string resourceGroupName, string namespaceName, string publicNetworkAccess, bool? trustedServiceAccessEnabled, string defaultAction, PSNWRuleSetIpRulesAttributes[] iPRule, PSNWRuleSetVirtualNetworkRulesAttributes[] virtualNetworkRule)
{
NetworkRuleSet networkRuleSet = Client.Namespaces.GetNetworkRuleSet(resourceGroupName, namespaceName);

Expand All @@ -378,7 +378,7 @@ public PSNetworkRuleSetAttributes UpdateNetworkRuleSet(string resourceGroupName,
networkRuleSet.PublicNetworkAccess = publicNetworkAccess;
}

if (trustedServiceAccessEnabled == true)
if (trustedServiceAccessEnabled != null)
{
networkRuleSet.TrustedServiceAccessEnabled = trustedServiceAccessEnabled;
}
Expand Down