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 12, 2021
1 parent 7bbe2a5 commit bfce9fa
Show file tree
Hide file tree
Showing 35 changed files with 83 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.0.0-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Authentication.Abstractions" Version="1.0.0-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Authorization" Version="1.0.0-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Common" Version="1.0.0-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Compute" Version="1.0.0-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Graph.Rbac" Version="1.0.0-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.KeyVault" Version="1.0.0-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Monitor" Version="1.0.0-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Network" Version="1.0.0-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.PolicyInsights" Version="1.0.0-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.ResourceManager" Version="1.0.0-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Storage" Version="1.0.0-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Storage.Management" Version="1.0.0-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Strategies" Version="1.0.0-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Websites" Version="1.0.0-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Common.Share" Version="1.0.0-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.0.0-preview\tools\</StorageToolsPath>
</PropertyGroup>
<ItemGroup Condition="'$(OmitJsonPackage)' != 'true'">
<PackageReference Include="Newtonsoft.Json" Version="10.0.3"/>
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit bfce9fa

Please sign in to comment.