2626using System ;
2727using System . Collections . Generic ;
2828using System . Collections . ObjectModel ;
29- using System . Diagnostics ;
3029using System . IO ;
3130using System . Linq ;
3231using System . Management . Automation ;
@@ -40,9 +39,9 @@ namespace Microsoft.Azure.Commands.TestFx
4039{
4140 public class EnvironmentSetupHelper
4241 {
43- private const string TestEnvironmentName = "__test -environment" ;
42+ private const string TestFxEnvironmentName = "__testfx -environment" ;
4443
45- private const string TestSubscriptionName = "__test-subscriptions " ;
44+ private const string TestFxSubscriptionName = "__testfx-subscription " ;
4645
4746 private static string PackageDirectoryFromCommon { get ; } = GetConfigDirectory ( ) ;
4847
@@ -134,9 +133,6 @@ public EnvironmentSetupHelper()
134133 // Ignore SSL errors
135134 System . Net . ServicePointManager . ServerCertificateValidationCallback += ( se , cert , chain , sslerror ) => true ;
136135
137- // Set RunningMocked
138- TestMockSupport . RunningMocked = HttpMockServer . GetCurrentMode ( ) == HttpRecorderMode . Playback ;
139-
140136 if ( File . Exists ( Path . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . UserProfile ) , Resources . AzureDirectoryName , "testcredentials.json" ) ) )
141137 {
142138 SetEnvironmentVariableFromCredentialFile ( ) ;
@@ -388,62 +384,67 @@ public void SetupAzureEnvironmentFromEnvironmentVariables(AzureModule mode)
388384 throw new NotSupportedException ( "RDFE environment is not supported in .Net Core" ) ;
389385 }
390386
391- if ( currentEnvironment . UserName == null )
392- {
393- currentEnvironment . UserName = "[email protected] " ; 394- }
395-
396387 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- } ;
424388
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 ) ;
427421 testSubscription . SetDefault ( ) ;
428422 testSubscription . SetStorageAccount ( Environment . GetEnvironmentVariable ( "AZURE_STORAGE_ACCOUNT" ) ) ;
423+ }
429424
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+ }
435430
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 ;
446436 }
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 ) ;
447448 }
448449
449450 private void SetAuthenticationFactory ( TestEnvironment environment )
@@ -457,7 +458,7 @@ private void SetAuthenticationFactory(TestEnvironment environment)
457458 . GetAwaiter ( )
458459 . GetResult ( ) ;
459460
460- AzureSession . Instance . AuthenticationFactory = new MockTokenAuthenticationFactory ( environment . UserName , httpMessage . Headers . Authorization . Parameter ) ;
461+ AzureSession . Instance . AuthenticationFactory = new MockTokenAuthenticationFactory ( environment . UserId , httpMessage . Headers . Authorization . Parameter ) ;
461462 }
462463 }
463464
@@ -524,6 +525,7 @@ public virtual Collection<PSObject> RunPowerShellTest(params string[] scripts)
524525 Collection < PSObject > output = null ;
525526 foreach ( var script in scripts )
526527 {
528+ Console . WriteLine ( $ "Executing test: { script } ") ;
527529 TracingInterceptor ? . Information ( script ) ;
528530 powershell . AddScript ( script ) ;
529531 }
0 commit comments