Skip to content

Commit 517883e

Browse files
author
Hovsep
committed
Merge pull request #2262 from hovsepm/bugfix
Bugfix for June release
2 parents 7829d04 + 563407d commit 517883e

File tree

20 files changed

+234
-24
lines changed

20 files changed

+234
-24
lines changed

src/Common/Commands.Common/Properties/Resources.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Common/Commands.Common/Properties/Resources.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1544,4 +1544,7 @@ Select Y to enable data collection [Y/N]:</value>
15441544
<data name="NoCurrentContextForDataCmdlet" xml:space="preserve">
15451545
<value>"There is no current context, please log in using Login-AzureRmAccount for Azure Resource Manager or Add-AzureAccount for Azure Service Management."</value>
15461546
</data>
1547+
<data name="NoSubscriptionFoundForTenant" xml:space="preserve">
1548+
<value>No subscriptions are associated with the logged in account in Azure Service Management (RDFE). This means that the logged in user is not an administrator or co-administrator for any account.\r\nDid you mean to execute Login-AzureRmAccount?</value>
1549+
</data>
15471550
</root>

src/ResourceManager/Cdn/Commands.Cdn.Test/ScenarioTests/CustomDomainTests.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,26 @@ namespace Microsoft.Azure.Commands.Cdn.Test.ScenarioTests.ScenarioTest
1919
{
2020
public class CustomDomainTests
2121
{
22+
private ServiceManagemenet.Common.Models.XunitTracingInterceptor _logger;
23+
2224
public CustomDomainTests(Xunit.Abstractions.ITestOutputHelper output)
2325
{
24-
ServiceManagemenet.Common.Models.XunitTracingInterceptor.AddToContext(new ServiceManagemenet.Common.Models.XunitTracingInterceptor(output));
26+
_logger = new ServiceManagemenet.Common.Models.XunitTracingInterceptor(output);
27+
ServiceManagemenet.Common.Models.XunitTracingInterceptor.AddToContext(_logger);
2528
}
2629

2730
[Fact]
2831
[Trait(Category.AcceptanceType, Category.CheckIn)]
2932
public void TestCustomDomainGetRemoveWithRunningEndpoint()
3033
{
31-
TestController.NewInstance.RunPowerShellTest("Test-CustomDomainGetRemoveWithRunningEndpoint");
34+
TestController.NewInstance.RunPowerShellTest(_logger, "Test-CustomDomainGetRemoveWithRunningEndpoint");
3235
}
3336

3437
[Fact]
3538
[Trait(Category.AcceptanceType, Category.CheckIn)]
3639
public void TestCustomDomainGetRemoveWithStoppedEndpoint()
3740
{
38-
TestController.NewInstance.RunPowerShellTest("Test-CustomDomainGetRemoveWithStoppedEndpoint");
41+
TestController.NewInstance.RunPowerShellTest(_logger, "Test-CustomDomainGetRemoveWithStoppedEndpoint");
3942
}
4043
}
4144
}

src/ResourceManager/Cdn/Commands.Cdn.Test/ScenarioTests/EndpointTests.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,37 +19,40 @@ namespace Microsoft.Azure.Commands.Cdn.Test.ScenarioTests.ScenarioTest
1919
{
2020
public class EndpointTests
2121
{
22+
private ServiceManagemenet.Common.Models.XunitTracingInterceptor _logger;
23+
2224
public EndpointTests(Xunit.Abstractions.ITestOutputHelper output)
2325
{
24-
ServiceManagemenet.Common.Models.XunitTracingInterceptor.AddToContext(new ServiceManagemenet.Common.Models.XunitTracingInterceptor(output));
26+
_logger = new ServiceManagemenet.Common.Models.XunitTracingInterceptor(output);
27+
ServiceManagemenet.Common.Models.XunitTracingInterceptor.AddToContext(_logger);
2528
}
2629

2730
[Fact]
2831
[Trait(Category.AcceptanceType, Category.CheckIn)]
2932
public void TestEndpointCrudAndAction()
3033
{
31-
TestController.NewInstance.RunPowerShellTest("Test-EndpointCrudAndAction");
34+
TestController.NewInstance.RunPowerShellTest(_logger, "Test-EndpointCrudAndAction");
3235
}
3336

3437
[Fact]
3538
[Trait(Category.AcceptanceType, Category.CheckIn)]
3639
public void TestEndpointCrudAndActionWithPiping()
3740
{
38-
TestController.NewInstance.RunPowerShellTest("Test-EndpointCrudAndActionWithPiping");
41+
TestController.NewInstance.RunPowerShellTest(_logger, "Test-EndpointCrudAndActionWithPiping");
3942
}
4043

4144
[Fact]
4245
[Trait(Category.AcceptanceType, Category.CheckIn)]
4346
public void TestEndpointCrudAndActionWithAllProperties()
4447
{
45-
TestController.NewInstance.RunPowerShellTest("Test-EndpointCrudAndActionWithAllProperties");
48+
TestController.NewInstance.RunPowerShellTest(_logger, "Test-EndpointCrudAndActionWithAllProperties");
4649
}
4750

4851
[Fact]
4952
[Trait(Category.AcceptanceType, Category.CheckIn)]
5053
public void TestEndpointCrudAndActionWithAllPropertiesWithPiping()
5154
{
52-
TestController.NewInstance.RunPowerShellTest("Test-EndpointCrudAndActionWithAllPropertiesWithPiping");
55+
TestController.NewInstance.RunPowerShellTest(_logger, "Test-EndpointCrudAndActionWithAllPropertiesWithPiping");
5356
}
5457
}
5558
}

src/ResourceManager/Cdn/Commands.Cdn.Test/ScenarioTests/OriginTests.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,30 +19,33 @@ namespace Microsoft.Azure.Commands.Cdn.Test.ScenarioTests.ScenarioTest
1919
{
2020
public class OriginTests
2121
{
22+
private ServiceManagemenet.Common.Models.XunitTracingInterceptor _logger;
23+
2224
public OriginTests(Xunit.Abstractions.ITestOutputHelper output)
2325
{
24-
ServiceManagemenet.Common.Models.XunitTracingInterceptor.AddToContext(new ServiceManagemenet.Common.Models.XunitTracingInterceptor(output));
26+
_logger = new ServiceManagemenet.Common.Models.XunitTracingInterceptor(output);
27+
ServiceManagemenet.Common.Models.XunitTracingInterceptor.AddToContext(_logger);
2528
}
2629

2730
[Fact]
2831
[Trait(Category.AcceptanceType, Category.CheckIn)]
2932
public void TestOriginGetSetWithRunningEndpoint()
3033
{
31-
TestController.NewInstance.RunPowerShellTest("Test-OriginGetSetWithRunningEndpoint");
34+
TestController.NewInstance.RunPowerShellTest(_logger, "Test-OriginGetSetWithRunningEndpoint");
3235
}
3336

3437
[Fact]
3538
[Trait(Category.AcceptanceType, Category.CheckIn)]
3639
public void TestOriginGetSetWithStoppedEndpoint()
3740
{
38-
TestController.NewInstance.RunPowerShellTest("Test-OriginGetSetWithStoppedEndpoint");
41+
TestController.NewInstance.RunPowerShellTest(_logger, "Test-OriginGetSetWithStoppedEndpoint");
3942
}
4043

4144
[Fact]
4245
[Trait(Category.AcceptanceType, Category.CheckIn)]
4346
public void TestOriginGetSetWhenEndpointDoesnotExist()
4447
{
45-
TestController.NewInstance.RunPowerShellTest("Test-OriginGetSetWhenEndpointDoesnotExist");
48+
TestController.NewInstance.RunPowerShellTest(_logger, "Test-OriginGetSetWhenEndpointDoesnotExist");
4649
}
4750
}
4851
}

src/ResourceManager/Cdn/Commands.Cdn.Test/ScenarioTests/ProfileTests.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,26 @@ namespace Microsoft.Azure.Commands.Cdn.Test.ScenarioTests.ScenarioTest
1919
{
2020
public class ProfileTests
2121
{
22+
private ServiceManagemenet.Common.Models.XunitTracingInterceptor _logger;
23+
2224
public ProfileTests(Xunit.Abstractions.ITestOutputHelper output)
2325
{
24-
ServiceManagemenet.Common.Models.XunitTracingInterceptor.AddToContext(new ServiceManagemenet.Common.Models.XunitTracingInterceptor(output));
26+
_logger = new ServiceManagemenet.Common.Models.XunitTracingInterceptor(output);
27+
ServiceManagemenet.Common.Models.XunitTracingInterceptor.AddToContext(_logger);
2528
}
2629

2730
[Fact]
2831
[Trait(Category.AcceptanceType, Category.CheckIn)]
2932
public void TestProfileCrud()
3033
{
31-
TestController.NewInstance.RunPowerShellTest("Test-ProfileCrud");
34+
TestController.NewInstance.RunPowerShellTest(_logger, "Test-ProfileCrud");
3235
}
3336

3437
[Fact]
3538
[Trait(Category.AcceptanceType, Category.CheckIn)]
3639
public void TestProfileCrudWithPiping()
3740
{
38-
TestController.NewInstance.RunPowerShellTest("Test-ProfileDeleteAndSsoWithPiping");
41+
TestController.NewInstance.RunPowerShellTest(_logger, "Test-ProfileDeleteAndSsoWithPiping");
3942
}
4043
}
4144
}

src/ResourceManager/Cdn/Commands.Cdn.Test/ScenarioTests/TestController.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,12 @@ protected void SetupManagementClients(MockContext context)
7878
CdnManagementClient);
7979
}
8080

81-
public void RunPowerShellTest(params string[] scripts)
81+
public void RunPowerShellTest(ServiceManagemenet.Common.Models.XunitTracingInterceptor logger, params string[] scripts)
8282
{
8383
var callingClassType = TestUtilities.GetCallingClass(2);
8484
var mockName = TestUtilities.GetCurrentMethodName(2);
8585

86+
_helper.TracingInterceptor = logger;
8687
RunPsTestWorkflow(
8788
() => scripts,
8889
// no custom initializer
@@ -136,7 +137,6 @@ public void RunPsTestWorkflow(
136137
_helper.RMProfileModule,
137138
_helper.RMResourceModule,
138139
@"AzureRM.Cdn.psd1");
139-
140140
try
141141
{
142142
if (scriptBuilder != null)

src/ResourceManager/Cdn/Commands.Cdn/CustomDomain/NewAzureRmCdnCustomDomain.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public void OnImport()
9999
System.Management.Automation.PowerShell invoker = null;
100100
invoker = System.Management.Automation.PowerShell.Create(RunspaceMode.CurrentRunspace);
101101
invoker.AddScript(File.ReadAllText(FileUtilities.GetContentFilePath(
102-
Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
102+
Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory),
103103
"CdnStartup.ps1")));
104104
invoker.Invoke();
105105
}

src/ResourceManager/Profile/Commands.Profile.Test/ProfileCmdletTests.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
using Microsoft.WindowsAzure.Commands.Utilities.Common;
2424
using System;
2525
using System.Linq;
26+
using System.Management.Automation;
2627
using Xunit;
2728
using Xunit.Abstractions;
2829

@@ -76,6 +77,21 @@ public void SelectAzureProfileNull()
7677
cmdlt.InvokeEndProcessing();
7778
}
7879

80+
81+
[Fact]
82+
[Trait(Category.AcceptanceType, Category.CheckIn)]
83+
public void SelectAzureProfileBadPath()
84+
{
85+
SelectAzureRMProfileCommand cmdlt = new SelectAzureRMProfileCommand();
86+
cmdlt.Path = "z:\non-existent-path\non-existent-file.ext";
87+
// Setup
88+
cmdlt.CommandRuntime = commandRuntimeMock;
89+
90+
// Act
91+
cmdlt.InvokeBeginProcessing();
92+
Assert.Throws<PSArgumentException>(() => cmdlt.ExecuteCmdlet());
93+
}
94+
7995
[Fact]
8096
[Trait(Category.AcceptanceType, Category.CheckIn)]
8197
public void SelectAzureProfileFromDisk()

src/ResourceManager/Profile/Commands.Profile/Microsoft.Azure.Commands.Profile.format.ps1xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
<Label>SubscriptionId</Label>
2727
<ScriptBlock>$_.Context.Subscription.ToString()</ScriptBlock>
2828
</ListItem>
29+
<ListItem>
30+
<Label>SubscriptionName</Label>
31+
<ScriptBlock>$_.Context.Subscription.SubscriptionName.ToString()</ScriptBlock>
32+
</ListItem>
2933
<ListItem>
3034
<Label>CurrentStorageAccount</Label>
3135
<ScriptBlock>if ($_.Context.Subscription -ne $null -and $_.Context.Subscription.CurrentStorageAccountName -ne $null) {$_.Context.Subscription.CurrentStorageAccountName} else {$null} </ScriptBlock>
@@ -58,6 +62,10 @@
5862
<Label>SubscriptionId</Label>
5963
<ScriptBlock>$_.Subscription.ToString()</ScriptBlock>
6064
</ListItem>
65+
<ListItem>
66+
<Label>SubscriptionName</Label>
67+
<ScriptBlock>$_.Subscription.SubscriptionName.ToString()</ScriptBlock>
68+
</ListItem>
6169
<ListItem>
6270
<Label>CurrentStorageAccount</Label>
6371
<ScriptBlock>if ($_.Subscription -ne $null -and $_.Subscription.CurrentStorageAccountName -ne $null) {$_.Subscription.CurrentStorageAccountName} else {$null} </ScriptBlock>

src/ResourceManager/Profile/Commands.Profile/Profile/SelectAzureRMProfile.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ public override void ExecuteCmdlet()
4646
{
4747
if (!string.IsNullOrEmpty(Path))
4848
{
49+
if(!Common.Authentication.AzureSession.DataStore.FileExists(Path))
50+
{
51+
throw new PSArgumentException(string.Format(
52+
Microsoft.Azure.Commands.Profile.Properties.Resources.FileNotFound,
53+
Path));
54+
}
55+
4956
AzureRmProfileProvider.Instance.Profile = new AzureRMProfile(Path);
5057
}
5158
else

src/ResourceManager/Profile/Commands.Profile/Properties/Resources.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ResourceManager/Profile/Commands.Profile/Properties/Resources.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@
138138
<data name="CurrentTenantInUse" xml:space="preserve">
139139
<value>Current tenant with Id '{0}' will be used.</value>
140140
</data>
141+
<data name="FileNotFound" xml:space="preserve">
142+
<value>Cannot find file '{0}'</value>
143+
</data>
141144
<data name="InvalidSubscriptionId" xml:space="preserve">
142145
<value>The provided subscription ID "{0}" is not a valid Guid.</value>
143146
</data>

src/ServiceManagement/Common/Commands.ServiceManagement.Common/ProfileClient.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,11 @@ public AzureAccount AddAccountAndLoadSubscriptions(AzureAccount account, AzureEn
322322
password,
323323
password == null ? ShowDialog.Always : ShowDialog.Never).ToList();
324324

325+
if (subscriptionsFromServer == null ||
326+
subscriptionsFromServer.Count ==0 )
327+
{
328+
throw new ArgumentException(Resources.NoSubscriptionFoundForTenant);
329+
}
325330
// If account id is null the login failed
326331
if (account.Id != null)
327332
{

src/ServiceManagement/Profile/Commands.Profile/Subscription/SetAzureSubscription.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,10 @@
2727

2828
namespace Microsoft.WindowsAzure.Commands.Profile
2929
{
30-
31-
3230
/// <summary>
3331
/// Sets an azure subscription.
3432
/// </summary>
35-
[Cmdlet(VerbsCommon.Set, "AzureSubscription"), OutputType(typeof(AzureSubscription))]
33+
[Cmdlet(VerbsCommon.Set, "AzureSubscription", DefaultParameterSetName = UpdateSubscriptionByIdParameterSet), OutputType(typeof(AzureSubscription))]
3634
public class SetAzureSubscriptionCommand : SubscriptionCmdletBase, IStorageContextProvider
3735
{
3836
private const string UpdateSubscriptionByIdParameterSet = "UpdateSubscriptionByIdParameterSetName";
@@ -60,11 +58,11 @@ public SetAzureSubscriptionCommand() : base(true)
6058
public string SubscriptionId { get; set; }
6159

6260
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true,
63-
HelpMessage = "Account subscription ID.", ParameterSetName = AddSubscriptionParameterSet)]
61+
HelpMessage = "X509 Certificate.", ParameterSetName = AddSubscriptionParameterSet)]
6462
[Parameter(ValueFromPipelineByPropertyName = true,
65-
HelpMessage = "Account subscription ID.", ParameterSetName = UpdateSubscriptionByIdParameterSet)]
63+
HelpMessage = "X509 Certificate.", ParameterSetName = UpdateSubscriptionByIdParameterSet)]
6664
[Parameter(Position = 0, ValueFromPipelineByPropertyName = true,
67-
HelpMessage = "Name of the subscription.", ParameterSetName = UpdateSubscriptionByNameParameterSet)]
65+
HelpMessage = "X509 Certificate.", ParameterSetName = UpdateSubscriptionByNameParameterSet)]
6866
public X509Certificate2 Certificate { get; set; }
6967

7068
[Parameter(ValueFromPipelineByPropertyName = true, HelpMessage = "Service endpoint.")]

src/ServiceManagement/Services/Commands.Test/Commands.Test.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,9 @@
414414
<None Include="SessionRecords\Microsoft.Azure.Commands.Test.Profile.NewAzureProfileTests\TestMakeRdfeCallWithCreatedProfile.json">
415415
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
416416
</None>
417+
<None Include="SessionRecords\Microsoft.Azure.Commands.Test.Profile.SelectAzureSubscriptionTests\GetSubscriptionPipeToSetSubscription.json">
418+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
419+
</None>
417420
<None Include="SessionRecords\Microsoft.Azure.Commands.Test.Profile.SelectAzureSubscriptionTests\StorageAccountIsNotCleaned.json">
418421
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
419422
</None>

src/ServiceManagement/Services/Commands.Test/Profile/ProfileCmdltsTests.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -979,6 +979,35 @@ public void CanAddAccountToCustomProfile()
979979
Assert.Equal(profile.Context.Subscription.Id, rdfeSubscription);
980980
}
981981

982+
[Fact]
983+
[Trait(Category.AcceptanceType, Category.CheckIn)]
984+
public void AddAzureAccountThrowsForEmptySubscriptions()
985+
{
986+
var cmdlet = new AddAzureAccount();
987+
var csmSubscription = Guid.NewGuid();
988+
var rdfeSubscription = Guid.NewGuid();
989+
var credential = GenerateCredential("mySillyPassword");
990+
var profile = new AzureSMProfile();
991+
var client = new ProfileClient(profile);
992+
cmdlet.Credential = credential;
993+
cmdlet.Profile = profile;
994+
cmdlet.SetParameterSet("User");
995+
996+
AzureSession.ClientFactory =
997+
new MockClientFactory(
998+
new List<object>
999+
{
1000+
ProfileClientHelper.CreateRdfeSubscriptionClient(rdfeSubscription),
1001+
ProfileClientHelper.CreateCsmSubscriptionClient(new List<string>(),
1002+
new List<string>{csmSubscription.ToString(), rdfeSubscription.ToString()})
1003+
}, true);
1004+
AzureSession.AuthenticationFactory = new MockTokenAuthenticationFactory(credential.UserName,
1005+
Guid.NewGuid().ToString());
1006+
cmdlet.CommandRuntime = commandRuntimeMock;
1007+
cmdlet.InvokeBeginProcessing();
1008+
Assert.Throws<ArgumentException>(() => cmdlet.ExecuteCmdlet());
1009+
}
1010+
9821011
[Fact]
9831012
[Trait(Category.AcceptanceType, Category.CheckIn)]
9841013
public void CanCreateProfieWithSPAuth()

src/ServiceManagement/Services/Commands.Test/Profile/SelectAzureSubscriptionTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,12 @@ public void StorageAccountIsNotCleaned()
5151
{
5252
ProfileTestController.NewRdfeInstance.RunPsTest("Test-StorageAccountIsNotCleaned");
5353
}
54+
55+
[Fact]
56+
[Trait(Category.AcceptanceType, Category.CheckIn)]
57+
public void GetSubscriptionPipeToSetSubscription()
58+
{
59+
ProfileTestController.NewRdfeInstance.RunPsTest("Test-GetSubscriptionPipeToSetSubscription");
60+
}
5461
}
5562
}

0 commit comments

Comments
 (0)