@@ -65,6 +65,7 @@ public void GetPsVersionFromUserAgent()
65
65
cmdlt . CommandRuntime = commandRuntimeMock ;
66
66
cmdlt . Subscription = "2c224e7e-3ef5-431d-a57b-e71f4662e3a6" ;
67
67
cmdlt . TenantId = "72f988bf-86f1-41af-91ab-2d7cd011db47" ;
68
+ cmdlt . SetParameterSet ( "UserWithSubscriptionId" ) ;
68
69
69
70
cmdlt . InvokeBeginProcessing ( ) ;
70
71
int postProcessingUserAgentCount = AzureSession . Instance . ClientFactory . UserAgents . Length ;
@@ -94,6 +95,7 @@ public void LoginWithSubscriptionAndTenant()
94
95
cmdlt . CommandRuntime = commandRuntimeMock ;
95
96
cmdlt . Subscription = "2c224e7e-3ef5-431d-a57b-e71f4662e3a6" ;
96
97
cmdlt . TenantId = "72f988bf-86f1-41af-91ab-2d7cd011db47" ;
98
+ cmdlt . SetParameterSet ( "UserWithSubscriptionId" ) ;
97
99
98
100
// Act
99
101
cmdlt . InvokeBeginProcessing ( ) ;
@@ -113,6 +115,7 @@ public void LoginWithInvalidSubscriptionAndTenantThrowsCloudException()
113
115
cmdlt . CommandRuntime = commandRuntimeMock ;
114
116
cmdlt . Subscription = "2c224e7e-3ef5-431d-a57b-e71f4662e3a5" ;
115
117
cmdlt . TenantId = "72f988bf-86f1-41af-91ab-2d7cd011db47" ;
118
+ cmdlt . SetParameterSet ( "UserWithSubscriptionId" ) ;
116
119
117
120
// Act
118
121
cmdlt . InvokeBeginProcessing ( ) ;
@@ -128,6 +131,7 @@ public void LoginWithSubscriptionAndNoTenant()
128
131
// Setup
129
132
cmdlt . CommandRuntime = commandRuntimeMock ;
130
133
cmdlt . Subscription = "2c224e7e-3ef5-431d-a57b-e71f4662e3a6" ;
134
+ cmdlt . SetParameterSet ( "UserWithSubscriptionId" ) ;
131
135
132
136
// Act
133
137
cmdlt . InvokeBeginProcessing ( ) ;
@@ -145,6 +149,7 @@ public void LoginWithNoSubscriptionAndNoTenant()
145
149
var cmdlt = new AddAzureRMAccountCommand ( ) ;
146
150
// Setup
147
151
cmdlt . CommandRuntime = commandRuntimeMock ;
152
+ cmdlt . SetParameterSet ( "UserWithSubscriptionId" ) ;
148
153
149
154
// Act
150
155
cmdlt . InvokeBeginProcessing ( ) ;
@@ -163,6 +168,7 @@ public void LoginWithNoSubscriptionAndTenant()
163
168
// Setup
164
169
cmdlt . CommandRuntime = commandRuntimeMock ;
165
170
cmdlt . TenantId = "72f988bf-86f1-41af-91ab-2d7cd011db47" ;
171
+ cmdlt . SetParameterSet ( "UserWithSubscriptionId" ) ;
166
172
167
173
// Act
168
174
cmdlt . InvokeBeginProcessing ( ) ;
@@ -182,6 +188,7 @@ public void LoginWithSubscriptionname()
182
188
cmdlt . CommandRuntime = commandRuntimeMock ;
183
189
cmdlt . TenantId = "72f988bf-86f1-41af-91ab-2d7cd011db47" ;
184
190
cmdlt . Subscription = "Node CLI Test" ;
191
+ cmdlt . SetParameterSet ( "UserWithSubscriptionId" ) ;
185
192
186
193
// Act
187
194
cmdlt . InvokeBeginProcessing ( ) ;
@@ -201,6 +208,7 @@ public void LoginWithRbacTenantOnly()
201
208
// NOTE: Use [email protected] credentials for this test case
202
209
cmdlt . CommandRuntime = commandRuntimeMock ;
203
210
cmdlt . TenantId = "1449d5b7-8a83-47db-ae4c-9b03e888bad0" ;
211
+ cmdlt . SetParameterSet ( "UserWithSubscriptionId" ) ;
204
212
205
213
// Act
206
214
cmdlt . InvokeBeginProcessing ( ) ;
@@ -225,6 +233,7 @@ public void LoginWithRbacSPNAndCertificateOnly()
225
233
cmdlt . TenantId = "54826b22-38d6-4fb2-bad9-b7b93a3e9c5a" ;
226
234
cmdlt . ApplicationId = "99edf981-74c0-4284-bddf-3e9d092ba4e2" ;
227
235
cmdlt . CertificateThumbprint = "F064B7C7EACC942D10662A5115E047E94FA18498" ;
236
+ cmdlt . SetParameterSet ( "ServicePrincipalCertificateWithSubscriptionId" ) ;
228
237
229
238
// Act
230
239
cmdlt . InvokeBeginProcessing ( ) ;
@@ -249,6 +258,7 @@ public void GetMultipleTenantsOnLogin()
249
258
// Setup
250
259
// NOTE: Use account that has at exactly two tenants
251
260
cmdlt . CommandRuntime = commandRuntimeMock ;
261
+ cmdlt . SetParameterSet ( "UserWithSubscriptionId" ) ;
252
262
253
263
// Act
254
264
cmdlt . InvokeBeginProcessing ( ) ;
@@ -270,6 +280,7 @@ public void LoginWithEnvironementName()
270
280
// Setup
271
281
cmdlt . CommandRuntime = commandRuntimeMock ;
272
282
cmdlt . Environment = "AzureUSGovernment" ;
283
+ cmdlt . SetParameterSet ( "UserWithSubscriptionId" ) ;
273
284
274
285
// Act
275
286
cmdlt . InvokeBeginProcessing ( ) ;
@@ -300,6 +311,7 @@ public void LoginWithCredentialParameterAndMSA()
300
311
Array . ForEach ( password . ToCharArray ( ) , securePassword . AppendChar ) ;
301
312
302
313
cmdlt . Credential = new PSCredential ( userName , securePassword ) ;
314
+ cmdlt . SetParameterSet ( "UserWithSubscriptionId" ) ;
303
315
304
316
// Act
305
317
try
@@ -318,6 +330,29 @@ public void LoginWithCredentialParameterAndMSA()
318
330
}
319
331
}
320
332
333
+ [ Fact ]
334
+ [ Trait ( Category . RunType , Category . LiveOnly ) ]
335
+ public void LoginWithAccessToken ( )
336
+ {
337
+ var cmdlt = new AddAzureRMAccountCommand ( ) ;
338
+ // Setup
339
+ cmdlt . CommandRuntime = commandRuntimeMock ;
340
+
341
+ // Obtain an access token by using [Microsoft.Azure.Commands.Common.Authentication.AzureSession]::Instance.TokenCache.ReadItems() in powershell after logging in.
342
+ // Ensure you are using the token with Resource: https://management.core.windows.net/
343
+ string accessTokenEnvironmentVariable = Environment . GetEnvironmentVariable ( "AZURE_TEST_ACCESS_TOKEN" ) ;
344
+
345
+ cmdlt . AccessToken = accessTokenEnvironmentVariable ;
346
+ cmdlt . AccountId = "testAccount" ;
347
+ cmdlt . SetParameterSet ( "AccessTokenWithSubscriptionId" ) ;
348
+
349
+ cmdlt . InvokeBeginProcessing ( ) ;
350
+ cmdlt . ExecuteCmdlet ( ) ;
351
+ cmdlt . InvokeEndProcessing ( ) ;
352
+
353
+ Assert . NotNull ( AzureRmProfileProvider . Instance . Profile . DefaultContext ) ;
354
+ }
355
+
321
356
[ Fact ]
322
357
[ Trait ( Category . AcceptanceType , Category . CheckIn ) ]
323
358
public void ThrowOnUnknownEnvironment ( )
@@ -328,6 +363,7 @@ public void ThrowOnUnknownEnvironment()
328
363
cmdlt . Environment = "unknown" ;
329
364
var testPassed = false ;
330
365
cmdlt . SetBoundParameters ( new Dictionary < string , object > ( ) { { "Environment" , "unknown" } } ) ;
366
+ cmdlt . SetParameterSet ( "UserWithSubscriptionId" ) ;
331
367
332
368
// Act
333
369
try
@@ -344,5 +380,30 @@ public void ThrowOnUnknownEnvironment()
344
380
345
381
Assert . True ( testPassed ) ;
346
382
}
383
+
384
+ [ Fact ]
385
+ [ Trait ( Category . AcceptanceType , Category . CheckIn ) ]
386
+ public void LoginUsingSkipValidation ( )
387
+ {
388
+ var cmdlt = new AddAzureRMAccountCommand ( ) ;
389
+ // Setup
390
+ cmdlt . CommandRuntime = commandRuntimeMock ;
391
+
392
+ cmdlt . AccessToken = "test" ;
393
+ cmdlt . AccessToken = "[email protected] " ;
394
+ cmdlt . SkipValidation = true ;
395
+ cmdlt . TenantId = Guid . NewGuid ( ) . ToString ( ) ;
396
+ cmdlt . Subscription = Guid . NewGuid ( ) . ToString ( ) ;
397
+ cmdlt . SetBoundParameters ( new Dictionary < string , object > ( ) { { "Subscription" , cmdlt . Subscription } } ) ;
398
+ cmdlt . SetParameterSet ( "AccessTokenWithSubscriptionId" ) ;
399
+
400
+ cmdlt . InvokeBeginProcessing ( ) ;
401
+ cmdlt . ExecuteCmdlet ( ) ;
402
+ cmdlt . InvokeEndProcessing ( ) ;
403
+
404
+ Assert . NotNull ( AzureRmProfileProvider . Instance . Profile . DefaultContext ) ;
405
+ Assert . Equal ( AzureRmProfileProvider . Instance . Profile . DefaultContext . Subscription . Id , cmdlt . Subscription ) ;
406
+ Assert . Equal ( AzureRmProfileProvider . Instance . Profile . DefaultContext . Tenant . Id , cmdlt . TenantId ) ;
407
+ }
347
408
}
348
409
}
0 commit comments