|
26 | 26 | using System.Collections.Generic;
|
27 | 27 | using System.Net.Http.Headers;
|
28 | 28 | using System.Diagnostics;
|
| 29 | +using System; |
| 30 | +using System.Security; |
29 | 31 |
|
30 | 32 | namespace Microsoft.Azure.Commands.Profile.Test
|
31 | 33 | {
|
@@ -292,6 +294,43 @@ public void LoginWithEnvironementName()
|
292 | 294 | Assert.Equal("AzureUSGovernment", AzureRmProfileProvider.Instance.Profile.Context.Environment.Name);
|
293 | 295 | }
|
294 | 296 |
|
| 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 | + |
295 | 334 | [Fact]
|
296 | 335 | [Trait(Category.AcceptanceType, Category.CheckIn)]
|
297 | 336 | public void ThrowOnUnknownEnvironment()
|
|
0 commit comments