Skip to content

Commit 6f0bfa1

Browse files
committed
Add LiveOnly test for Microsoft Account and Credential parameter
1 parent e2e47f2 commit 6f0bfa1

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
using System.Collections.Generic;
2727
using System.Net.Http.Headers;
2828
using System.Diagnostics;
29+
using System;
30+
using System.Security;
2931

3032
namespace Microsoft.Azure.Commands.Profile.Test
3133
{
@@ -292,6 +294,43 @@ public void LoginWithEnvironementName()
292294
Assert.Equal("AzureUSGovernment", AzureRmProfileProvider.Instance.Profile.Context.Environment.Name);
293295
}
294296

297+
[Fact]
298+
[Trait(Category.RunType, Category.LiveOnly)]
299+
public void LoginWithCredentialParameterAndMSA()
300+
{
301+
var cmdlt = new AddAzureRMAccountCommand();
302+
// Setup
303+
cmdlt.CommandRuntime = commandRuntimeMock;
304+
305+
// Example of environment variable: TEST_AZURE_CREDENTIALS=<subscription-id-value>;<[email protected]>;<email-password>"
306+
string credsEnvironmentVariable = Environment.GetEnvironmentVariable("TEST_AZURE_CREDENTIALS");
307+
string[] creds = credsEnvironmentVariable.Split(';');
308+
309+
string userName = creds[1];
310+
string password = creds[2];
311+
312+
var securePassword = new SecureString();
313+
Array.ForEach(password.ToCharArray(), securePassword.AppendChar);
314+
315+
cmdlt.Credential = new PSCredential(userName, securePassword);
316+
317+
// Act
318+
try
319+
{
320+
cmdlt.InvokeBeginProcessing();
321+
cmdlt.ExecuteCmdlet();
322+
cmdlt.InvokeEndProcessing();
323+
}
324+
catch (AadAuthenticationFailedException ex)
325+
{
326+
Assert.NotNull(ex);
327+
Assert.Equal("-Credential parameter can only be used with Organization ID credentials. " +
328+
"For more information, please refer to http://go.microsoft.com/fwlink/?linkid=331007&clcid=0x409 " +
329+
"for more information about the difference between an organizational account and a Microsoft account.",
330+
ex.Message);
331+
}
332+
}
333+
295334
[Fact]
296335
[Trait(Category.AcceptanceType, Category.CheckIn)]
297336
public void ThrowOnUnknownEnvironment()

0 commit comments

Comments
 (0)