Skip to content
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

Fix access error when subscripiton has no Tags property #15446

Merged
merged 2 commits into from
Jul 15, 2021
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
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 [DefaultProfile]"; 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