Skip to content

Commit

Permalink
Fix access error when subscripiton has no Tags property
Browse files Browse the repository at this point in the history
- Fix the issue Azure#15425
- Add related test cases
  • Loading branch information
msJinLei committed Jul 14, 2021
1 parent 7bbe2a5 commit 50014f9
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 22 deletions.
65 changes: 65 additions & 0 deletions src/Accounts/Accounts.Test/UnitTest/PSAzureSubscriptionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,70 @@ public void NewPSAzureSubscription()
Assert.Equal(psAzureSubscription.SubscriptionPolicies.QuotaId, quotaId);
Assert.Equal(psAzureSubscription.SubscriptionPolicies.SpendingLimit, spendingLimit.ToString());
}


[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void ConvertAzureSubscripitonToPSAzureSubscriptionWithTags()
{
string tenants = new Guid().ToString(), homeTenant = new Guid().ToString();
var subscription = new AzureSubscription()
{
Id = new Guid().ToString(),
Name = "Playground-01",
State = "Enabled",
ExtendedProperties =
{
{ "SubscriptionPolices", @"{""locationPlacementId"":""Internal_2014-09-01"",""quotaId"":""Internal_2014-09-01"",""spendingLimit"":""Off""}" },
{ "Environment", "AzureCloud" },
{ "AuthorizationSource", "RoleBased" },
{ "Account", "[email protected]" },
{ "ManagedByTenants", tenants },
{ "Tenants", tenants },
{ "Tags", @"{""CigdemTestTag"":""Enabled""}" },
{ "HomeTenant", homeTenant }
}
};

var psSubscription = new PSAzureSubscription(subscription);
Assert.Equal(subscription.Id, psSubscription.Id);
Assert.Equal(subscription.Name, psSubscription.Name);
Assert.Equal(subscription.State, psSubscription.State);
Assert.Equal(homeTenant, psSubscription.TenantId);
Assert.Equal(homeTenant, psSubscription.HomeTenantId);
Assert.Equal("Internal_2014-09-01", psSubscription.SubscriptionPolicies.LocationPlacementId);
Assert.Single(psSubscription.Tags);
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void ConvertAzureSubscripitonToPSAzureSubscriptionWithoutTags()
{
string tenants = new Guid().ToString(), homeTenant = new Guid().ToString();
var subscription = new AzureSubscription()
{
Id = new Guid().ToString(),
Name = "Playground-01",
State = "Enabled",
ExtendedProperties =
{
{ "SubscriptionPolices", @"{""locationPlacementId"":""Internal_2014-09-01"",""quotaId"":""Internal_2014-09-01"",""spendingLimit"":""Off""}" },
{ "AuthorizationSource", "RoleBased" },
{ "Account", "[email protected]" },
{ "ManagedByTenants", tenants },
{ "Tenants", tenants },
{ "HomeTenant", homeTenant }
}
};

var psSubscription = new PSAzureSubscription(subscription);
Assert.Equal(subscription.Id, psSubscription.Id);
Assert.Equal(subscription.Name, psSubscription.Name);
Assert.Equal(subscription.State, psSubscription.State);
Assert.Equal(homeTenant, psSubscription.TenantId);
Assert.Equal(homeTenant, psSubscription.HomeTenantId);
Assert.Equal("Internal_2014-09-01", psSubscription.SubscriptionPolicies.LocationPlacementId);
Assert.Null(psSubscription.Tags);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,7 @@ public Dictionary<string, string> Tags
{
get
{
if (!string.IsNullOrEmpty(this.GetProperty(AzureSubscription.Property.Tags)))
{
return this.GetTags();
}
return null;
return this.GetTags();
}
}
}
Expand Down
34 changes: 17 additions & 17 deletions tools/Common.Netcore.Dependencies.targets
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@
<ItemGroup>
<PackageReference Include="Microsoft.Rest.ClientRuntime" Version="2.3.23"/>
<PackageReference Include="Microsoft.Rest.ClientRuntime.Azure" Version="3.3.19"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Aks" Version="1.3.40-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Authentication.Abstractions" Version="1.3.40-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Authorization" Version="1.3.40-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Common" Version="1.3.40-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Compute" Version="1.3.40-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Graph.Rbac" Version="1.3.40-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.KeyVault" Version="1.3.40-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Monitor" Version="1.3.40-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Network" Version="1.3.40-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.PolicyInsights" Version="1.3.40-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.ResourceManager" Version="1.3.40-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Storage" Version="1.3.40-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Storage.Management" Version="1.3.40-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Strategies" Version="1.3.40-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Websites" Version="1.3.40-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Common.Share" Version="1.3.40-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Aks" Version="1.3.41-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Authentication.Abstractions" Version="1.3.41-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Authorization" Version="1.3.41-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Common" Version="1.3.41-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Compute" Version="1.3.41-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Graph.Rbac" Version="1.3.41-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.KeyVault" Version="1.3.41-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Monitor" Version="1.3.41-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Network" Version="1.3.41-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.PolicyInsights" Version="1.3.41-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.ResourceManager" Version="1.3.41-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Storage" Version="1.3.41-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Storage.Management" Version="1.3.41-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Strategies" Version="1.3.41-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Websites" Version="1.3.41-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Common.Share" Version="1.3.41-preview"/>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Azure.Core" Version="1.14.0"/>
Expand All @@ -36,7 +36,7 @@
<PackageReference Include="PowerShellStandard.Library" Version="5.1.0" PrivateAssets="All" />
</ItemGroup>
<PropertyGroup>
<StorageToolsPath>$(NugetPackageRoot)\microsoft.azure.powershell.storage\1.3.40-preview\tools\</StorageToolsPath>
<StorageToolsPath>$(NugetPackageRoot)\microsoft.azure.powershell.storage\1.3.41-preview\tools\</StorageToolsPath>
</PropertyGroup>
<ItemGroup Condition="'$(OmitJsonPackage)' != 'true'">
<PackageReference Include="Newtonsoft.Json" Version="10.0.3"/>
Expand Down
1 change: 1 addition & 0 deletions tools/Test/SmokeTest/RmCoreSmokeTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ $resourceTestCommands = @(
@{Name = "Az.Storage [Management]"; Command = {New-AzStorageAccount -Name $storageAccountName -SkuName Standard_LRS -Location westus -ResourceGroupName $resourceGroupName -ErrorAction Stop}},
@{Name = "Az.Storage [Data]"; Command = {New-AzStorageContext -StorageAccountName $storageAccountName -StorageAccountKey 12345678 -ErrorAction Stop}},
@{Name = "Az.Accounts"; Command = {Get-AzDomain -ErrorAction Stop}},
@{Name = "Az.Accounts"; Command = {Get-AzSubscription -DefaultProfile (Get-AzContext)}},
@{Name = "Az.Advisor"; Command = {Get-AzAdvisorConfiguration -ErrorAction Stop}},
@{Name = "Az.Aks"; Command = {Get-AzAksCluster -ErrorAction Stop}},
@{Name = "Az.AnalysisServices"; Command = {Get-AzAnalysisServicesServer -ErrorAction Stop}},
Expand Down

0 comments on commit 50014f9

Please sign in to comment.