26
26
using System ;
27
27
using System . Collections . Generic ;
28
28
using System . Collections . ObjectModel ;
29
- using System . Diagnostics ;
30
29
using System . IO ;
31
30
using System . Linq ;
32
31
using System . Management . Automation ;
@@ -40,9 +39,9 @@ namespace Microsoft.Azure.Commands.TestFx
40
39
{
41
40
public class EnvironmentSetupHelper
42
41
{
43
- private const string TestEnvironmentName = "__test -environment" ;
42
+ private const string TestFxEnvironmentName = "__testfx -environment" ;
44
43
45
- private const string TestSubscriptionName = "__test-subscriptions " ;
44
+ private const string TestFxSubscriptionName = "__testfx-subscription " ;
46
45
47
46
private static string PackageDirectoryFromCommon { get ; } = GetConfigDirectory ( ) ;
48
47
@@ -134,9 +133,6 @@ public EnvironmentSetupHelper()
134
133
// Ignore SSL errors
135
134
System . Net . ServicePointManager . ServerCertificateValidationCallback += ( se , cert , chain , sslerror ) => true ;
136
135
137
- // Set RunningMocked
138
- TestMockSupport . RunningMocked = HttpMockServer . GetCurrentMode ( ) == HttpRecorderMode . Playback ;
139
-
140
136
if ( File . Exists ( Path . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . UserProfile ) , Resources . AzureDirectoryName , "testcredentials.json" ) ) )
141
137
{
142
138
SetEnvironmentVariableFromCredentialFile ( ) ;
@@ -388,62 +384,67 @@ public void SetupAzureEnvironmentFromEnvironmentVariables(AzureModule mode)
388
384
throw new NotSupportedException ( "RDFE environment is not supported in .Net Core" ) ;
389
385
}
390
386
391
- if ( currentEnvironment . UserName == null )
392
- {
393
- currentEnvironment . UserName = "[email protected] " ;
394
- }
395
-
396
387
SetAuthenticationFactory ( currentEnvironment ) ;
397
- AzureEnvironment environment = new AzureEnvironment { Name = TestEnvironmentName } ;
398
- Debug . Assert ( currentEnvironment != null ) ;
399
- environment . ActiveDirectoryAuthority = currentEnvironment . Endpoints . AADAuthUri . AbsoluteUri ;
400
- environment . GalleryUrl = currentEnvironment . Endpoints . GalleryUri ? . AbsoluteUri ;
401
- environment . ServiceManagementUrl = currentEnvironment . BaseUri . AbsoluteUri ;
402
- environment . ResourceManagerUrl = currentEnvironment . Endpoints . ResourceManagementUri . AbsoluteUri ;
403
- environment . GraphUrl = currentEnvironment . Endpoints . GraphUri . AbsoluteUri ;
404
- environment . AzureDataLakeAnalyticsCatalogAndJobEndpointSuffix = currentEnvironment . Endpoints . DataLakeAnalyticsJobAndCatalogServiceUri . OriginalString . Replace ( "https://" , "" ) ; // because it is just a sufix
405
- environment . AzureDataLakeStoreFileSystemEndpointSuffix = currentEnvironment . Endpoints . DataLakeStoreServiceUri . OriginalString . Replace ( "https://" , "" ) ; // because it is just a sufix
406
- environment . StorageEndpointSuffix = AzureEnvironmentConstants . AzureStorageEndpointSuffix ;
407
- environment . AzureKeyVaultDnsSuffix = AzureEnvironmentConstants . AzureKeyVaultDnsSuffix ;
408
- environment . AzureKeyVaultServiceEndpointResourceId = AzureEnvironmentConstants . AzureKeyVaultServiceEndpointResourceId ;
409
- environment . ExtendedProperties . SetProperty ( AzureEnvironment . ExtendedEndpoint . MicrosoftGraphUrl , currentEnvironment . Endpoints . GraphUri . AbsoluteUri ) ;
410
- environment . ExtendedProperties . SetProperty ( AzureEnvironment . ExtendedEndpoint . OperationalInsightsEndpoint , "https://api.loganalytics.io/v1" ) ;
411
- environment . ExtendedProperties . SetProperty ( AzureEnvironment . ExtendedEndpoint . OperationalInsightsEndpointResourceId , "https://api.loganalytics.io" ) ;
412
- if ( ! AzureRmProfileProvider . Instance . GetProfile < AzureRmProfile > ( ) . EnvironmentTable . ContainsKey ( TestEnvironmentName ) )
413
- {
414
- AzureRmProfileProvider . Instance . GetProfile < AzureRmProfile > ( ) . EnvironmentTable [ TestEnvironmentName ] = environment ;
415
- }
416
-
417
- if ( currentEnvironment . SubscriptionId != null )
418
- {
419
- var testSubscription = new AzureSubscription
420
- {
421
- Id = currentEnvironment . SubscriptionId ,
422
- Name = TestSubscriptionName ,
423
- } ;
424
388
425
- testSubscription . SetEnvironment ( TestEnvironmentName ) ;
426
- testSubscription . SetAccount ( currentEnvironment . UserName ) ;
389
+ AzureEnvironment testEnvironment = new AzureEnvironment
390
+ {
391
+ Name = TestFxEnvironmentName ,
392
+ ActiveDirectoryAuthority = currentEnvironment . Endpoints . AADAuthUri . AbsoluteUri ,
393
+ ActiveDirectoryServiceEndpointResourceId = currentEnvironment . Endpoints . AADTokenAudienceUri . AbsoluteUri ,
394
+ GraphUrl = currentEnvironment . Endpoints . GraphUri . AbsoluteUri ,
395
+ GraphEndpointResourceId = currentEnvironment . Endpoints . GraphTokenAudienceUri . AbsoluteUri ,
396
+ ResourceManagerUrl = currentEnvironment . Endpoints . ResourceManagementUri . AbsoluteUri ,
397
+ ServiceManagementUrl = currentEnvironment . Endpoints . ServiceManagementUri . AbsoluteUri ,
398
+ GalleryUrl = currentEnvironment . Endpoints . GalleryUri ? . AbsoluteUri ,
399
+ AzureDataLakeAnalyticsCatalogAndJobEndpointSuffix = currentEnvironment . Endpoints . DataLakeAnalyticsJobAndCatalogServiceUri . OriginalString . Replace ( "https://" , "" ) , // because it is just a sufix
400
+ AzureDataLakeStoreFileSystemEndpointSuffix = currentEnvironment . Endpoints . DataLakeStoreServiceUri . OriginalString . Replace ( "https://" , "" ) , // because it is just a sufix
401
+ StorageEndpointSuffix = AzureEnvironmentConstants . AzureStorageEndpointSuffix ,
402
+ AzureKeyVaultDnsSuffix = AzureEnvironmentConstants . AzureKeyVaultDnsSuffix ,
403
+ AzureKeyVaultServiceEndpointResourceId = AzureEnvironmentConstants . AzureKeyVaultServiceEndpointResourceId
404
+ } ;
405
+ testEnvironment . ExtendedProperties . SetProperty ( AzureEnvironment . ExtendedEndpoint . MicrosoftGraphUrl , currentEnvironment . Endpoints . GraphUri . AbsoluteUri ) ;
406
+ testEnvironment . ExtendedProperties . SetProperty ( AzureEnvironment . ExtendedEndpoint . OperationalInsightsEndpoint , "https://api.loganalytics.io/v1" ) ;
407
+ testEnvironment . ExtendedProperties . SetProperty ( AzureEnvironment . ExtendedEndpoint . OperationalInsightsEndpointResourceId , "https://api.loganalytics.io" ) ;
408
+ if ( ! AzureRmProfileProvider . Instance . GetProfile < AzureRmProfile > ( ) . EnvironmentTable . ContainsKey ( TestFxEnvironmentName ) )
409
+ {
410
+ AzureRmProfileProvider . Instance . GetProfile < AzureRmProfile > ( ) . EnvironmentTable [ TestFxEnvironmentName ] = testEnvironment ;
411
+ }
412
+
413
+ AzureSubscription testSubscription = new AzureSubscription ( ) ;
414
+ if ( ! string . IsNullOrEmpty ( currentEnvironment . SubscriptionId ) )
415
+ {
416
+ testSubscription . Id = currentEnvironment . SubscriptionId ;
417
+ testSubscription . Name = TestFxSubscriptionName ;
418
+ testSubscription . SetEnvironment ( TestFxEnvironmentName ) ;
419
+ testSubscription . SetTenant ( currentEnvironment . TenantId ) ;
420
+ testSubscription . SetAccount ( currentEnvironment . UserId ) ;
427
421
testSubscription . SetDefault ( ) ;
428
422
testSubscription . SetStorageAccount ( Environment . GetEnvironmentVariable ( "AZURE_STORAGE_ACCOUNT" ) ) ;
423
+ }
429
424
430
- var testAccount = new AzureAccount ( )
431
- {
432
- Id = currentEnvironment . UserName ,
433
- Type = AzureAccount . AccountType . User ,
434
- } ;
425
+ AzureTenant testTenant = new AzureTenant ( ) ;
426
+ if ( ! string . IsNullOrEmpty ( currentEnvironment . TenantId ) )
427
+ {
428
+ testTenant . Id = currentEnvironment . TenantId ;
429
+ }
435
430
436
- testAccount . SetSubscriptions ( currentEnvironment . SubscriptionId ) ;
437
- var testTenant = new AzureTenant ( ) { Id = Guid . NewGuid ( ) . ToString ( ) } ;
438
- if ( ! string . IsNullOrEmpty ( currentEnvironment . TenantId ) )
439
- {
440
- if ( Guid . TryParse ( currentEnvironment . TenantId , out _ ) )
441
- {
442
- testTenant . Id = currentEnvironment . TenantId ;
443
- }
444
- }
445
- AzureRmProfileProvider . Instance . Profile . DefaultContext = new AzureContext ( testSubscription , testAccount , environment , testTenant ) ;
431
+ AzureAccount testAccount = new AzureAccount ( ) ;
432
+ if ( ! string . IsNullOrEmpty ( currentEnvironment . UserId ) )
433
+ {
434
+ testAccount . Id = currentEnvironment . UserId ;
435
+ testAccount . Type = AzureAccount . AccountType . User ;
446
436
}
437
+ else if ( ! string . IsNullOrEmpty ( currentEnvironment . ServicePrincipalClientId ) && ! string . IsNullOrEmpty ( currentEnvironment . ServicePrincipalSecret ) )
438
+ {
439
+ testAccount . Id = currentEnvironment . ServicePrincipalClientId ;
440
+ testAccount . Type = AzureAccount . AccountType . ServicePrincipal ;
441
+ }
442
+
443
+ testAccount . SetAccessToken ( string . Empty ) ;
444
+ testAccount . SetSubscriptions ( currentEnvironment . SubscriptionId ) ;
445
+ testAccount . SetTenants ( currentEnvironment . TenantId ) ;
446
+
447
+ AzureRmProfileProvider . Instance . Profile . DefaultContext = new AzureContext ( testSubscription , testAccount , testEnvironment , testTenant ) ;
447
448
}
448
449
449
450
private void SetAuthenticationFactory ( TestEnvironment environment )
@@ -457,7 +458,7 @@ private void SetAuthenticationFactory(TestEnvironment environment)
457
458
. GetAwaiter ( )
458
459
. GetResult ( ) ;
459
460
460
- AzureSession . Instance . AuthenticationFactory = new MockTokenAuthenticationFactory ( environment . UserName , httpMessage . Headers . Authorization . Parameter ) ;
461
+ AzureSession . Instance . AuthenticationFactory = new MockTokenAuthenticationFactory ( environment . UserId , httpMessage . Headers . Authorization . Parameter ) ;
461
462
}
462
463
}
463
464
@@ -524,6 +525,7 @@ public virtual Collection<PSObject> RunPowerShellTest(params string[] scripts)
524
525
Collection < PSObject > output = null ;
525
526
foreach ( var script in scripts )
526
527
{
528
+ Console . WriteLine ( $ "Executing test: { script } ") ;
527
529
TracingInterceptor ? . Information ( script ) ;
528
530
powershell . AddScript ( script ) ;
529
531
}
0 commit comments