protected GraphRbacManagementClient GetGraphClient() { var testFactory = new CSMTestEnvironmentFactory(); var environment = testFactory.GetTestEnvironment(); string tenantId = Guid.Empty.ToString(); if (HttpMockServer.Mode == HttpRecorderMode.Record) { tenantId = environment.AuthorizationContext.TenantId; UserDomain = environment.AuthorizationContext.UserDomain; HttpMockServer.Variables[TenantIdKey] = tenantId; HttpMockServer.Variables[DomainKey] = UserDomain; } else if (HttpMockServer.Mode == HttpRecorderMode.Playback) { if (HttpMockServer.Variables.ContainsKey(TenantIdKey)) { tenantId = HttpMockServer.Variables[TenantIdKey]; AzureRmProfileProvider.Instance.Profile.Context.Tenant.Id = new Guid(tenantId); } if (HttpMockServer.Variables.ContainsKey(DomainKey)) { UserDomain = HttpMockServer.Variables[DomainKey]; AzureRmProfileProvider.Instance.Profile.Context.Tenant.Domain = UserDomain; } } return(TestBase.GetGraphServiceClient <GraphRbacManagementClient>(testFactory, tenantId)); }
public GraphTestBase() { var testFactory = new CSMTestEnvironmentFactory(); TestEnvironment environment = testFactory.GetTestEnvironment(); string tenantId = null; if (HttpMockServer.Mode == HttpRecorderMode.Record) { tenantId = environment.AuthorizationContext.TenantId; Domain = environment.AuthorizationContext.UserId .Split(new [] { "@" }, StringSplitOptions.RemoveEmptyEntries) .Last(); HttpMockServer.Variables[TenantIdKey] = tenantId; HttpMockServer.Variables[DomainKey] = Domain; } else if (HttpMockServer.Mode == HttpRecorderMode.Playback) { tenantId = HttpMockServer.Variables[TenantIdKey]; Domain = HttpMockServer.Variables[DomainKey]; } GraphClient = TestBase.GetGraphServiceClient <GraphRbacManagementClient>(testFactory, tenantId); }
public void ResetPreCreatedVault() { if (HttpMockServer.Mode == HttpRecorderMode.Record) { var testFactory = new CSMTestEnvironmentFactory(); var testEnv = testFactory.GetTestEnvironment(); var resourcesClient = TestBase.GetServiceClient <ResourceManagementClient>(testFactory); var mgmtClient = TestBase.GetServiceClient <KeyVaultManagementClient>(testFactory); var tenantId = Guid.Parse(testEnv.AuthorizationContext.TenantId); var policies = new AccessPolicyEntry[] { }; mgmtClient.Vaults.CreateOrUpdate( resourceGroupName: resourceGroupName, vaultName: preCreatedVault, parameters: new VaultCreateOrUpdateParameters { Location = location, Tags = new Dictionary <string, string> { { tagName, tagValue } }, Properties = new VaultProperties { EnabledForDeployment = false, Sku = new Sku { Family = "A", Name = "Premium" }, TenantId = tenantId, VaultUri = "", AccessPolicies = policies } } ); } }
public void Initialize(string className) { if (initialized) { return; } if (HttpMockServer.GetCurrentMode() == HttpRecorderMode.Record) { var testFactory = new CSMTestEnvironmentFactory(); var testEnv = testFactory.GetTestEnvironment(); var resourcesClient = TestBase.GetServiceClient <ResourceManagementClient>(testFactory); var mgmtClient = TestBase.GetServiceClient <KeyVaultManagementClient>(testFactory); var tenantId = testEnv.AuthorizationContext.TenantId; //Figure out which locations are available for Key Vault location = GetKeyVaultLocation(resourcesClient); //Create a resource group in that location preCreatedVault = TestUtilities.GenerateName("pshtestvault"); resourceGroupName = TestUtilities.GenerateName("pshtestrg"); resourcesClient.ResourceGroups.CreateOrUpdate(resourceGroupName, new ResourceGroup { Location = location }); var createResponse = CreateVault(mgmtClient, location, tenantId); } initialized = true; }
public void Initialize(string className) { if (initialized) return; if (HttpMockServer.GetCurrentMode() == HttpRecorderMode.Record) { var testFactory = new CSMTestEnvironmentFactory(); var testEnv = testFactory.GetTestEnvironment(); var resourcesClient = TestBase.GetServiceClient<ResourceManagementClient>(testFactory); var mgmtClient = TestBase.GetServiceClient<KeyVaultManagementClient>(testFactory); var tenantId = testEnv.AuthorizationContext.TenantId; //Figure out which locations are available for Key Vault location = GetKeyVaultLocation(resourcesClient); //Create a resource group in that location preCreatedVault = TestUtilities.GenerateName("pshtestvault"); resourceGroupName = TestUtilities.GenerateName("pshtestrg"); resourcesClient.ResourceGroups.CreateOrUpdate(resourceGroupName, new ResourceGroup { Location = location }); var createResponse = CreateVault(mgmtClient, location, tenantId); } initialized = true; }
public static SearchServiceClient GetSearchServiceClient(this SearchServiceFixture fixture) { var factory = new CSMTestEnvironmentFactory(); TestEnvironment currentEnvironment = factory.GetTestEnvironment(); Uri baseUri = currentEnvironment.GetBaseSearchUri(ExecutionMode.CSM, fixture.SearchServiceName); SearchServiceClient client = new SearchServiceClient(new SearchCredentials(fixture.PrimaryApiKey), baseUri); return TestBaseCopy.AddMockHandler<SearchServiceClient>(ref client); }
public static SearchServiceClient GetSearchServiceClient(this SearchServiceFixture fixture) { var factory = new CSMTestEnvironmentFactory(); TestEnvironment currentEnvironment = factory.GetTestEnvironment(); Uri baseUri = currentEnvironment.GetBaseSearchUri(ExecutionMode.CSM, fixture.SearchServiceName); SearchServiceClient client = new SearchServiceClient(new SearchCredentials(fixture.PrimaryApiKey), baseUri); return(TestBaseCopy.AddMockHandler <SearchServiceClient>(ref client)); }
protected virtual void Dispose(bool disposing) { if (disposing) { if (HttpMockServer.Mode == HttpRecorderMode.Record && initialized) { var testFactory = new CSMTestEnvironmentFactory(); var testEnv = testFactory.GetTestEnvironment(); var resourcesClient = TestBase.GetServiceClient <ResourceManagementClient>(testFactory); resourcesClient.ResourceGroups.Delete(resourceGroupName); } } }
private SearchIndexClient GetSearchIndexClientForKey(string indexName, string apiKey) { var factory = new CSMTestEnvironmentFactory(); TestEnvironment currentEnvironment = factory.GetTestEnvironment(); Uri baseUri = new Uri( currentEnvironment.GetBaseSearchUri(ExecutionMode.CSM, SearchServiceName), String.Format("indexes/{0}/", indexName)); SearchIndexClient client = new SearchIndexClient(new SearchCredentials(apiKey), baseUri); return(TestBaseCopy.AddMockHandler <SearchIndexClient>(ref client)); }
public void Dispose() { if (HttpMockServer.Mode == HttpRecorderMode.Record && !fromConfig) { var testFactory = new CSMTestEnvironmentFactory(); var testEnv = testFactory.GetTestEnvironment(); var mgmtClient = TestBase.GetServiceClient <KeyVaultManagementClient>(testFactory); var resourcesClient = TestBase.GetServiceClient <ResourceManagementClient>(testFactory); var tenantId = testEnv.AuthorizationContext.TenatId; var graphClient = TestBase.GetGraphServiceClient <GraphRbacManagementClient>(testFactory, tenantId); mgmtClient.Vaults.Delete(rgName, vaultName); graphClient.Application.Delete(appObjectId); resourcesClient.ResourceGroups.Delete(rgName); } }
public KeyVaultTestBase() { var testFactory = new CSMTestEnvironmentFactory(); var testEnv = testFactory.GetTestEnvironment(); this.client = GetServiceClient <KeyVaultManagementClient>(testFactory); this.resourcesClient = GetServiceClient <ResourceManagementClient>(testFactory); if (HttpMockServer.Mode == HttpRecorderMode.Record) { this.tenantId = testEnv.AuthorizationContext.TenantId; this.subscriptionId = testEnv.SubscriptionId; var graphClient = GetGraphServiceClient <GraphRbacManagementClient>(testFactory, tenantId); this.objectId = graphClient.User.Get(testEnv.AuthorizationContext.UserId).User.ObjectId; this.applicationId = Guid.NewGuid().ToString(); HttpMockServer.Variables[TenantIdKey] = tenantId; HttpMockServer.Variables[ObjectIdKey] = objectId; HttpMockServer.Variables[SubIdKey] = subscriptionId; HttpMockServer.Variables[ApplicationIdKey] = applicationId; } else if (HttpMockServer.Mode == HttpRecorderMode.Playback) { tenantId = HttpMockServer.Variables[TenantIdKey]; objectId = HttpMockServer.Variables[ObjectIdKey]; subscriptionId = HttpMockServer.Variables[SubIdKey]; applicationId = HttpMockServer.Variables[ApplicationIdKey]; } var providers = resourcesClient.Providers.Get("Microsoft.KeyVault"); this.location = providers.Provider.ResourceTypes.Where( (resType) => { if (resType.Name == "vaults") { return(true); } else { return(false); } } ).First().Locations.FirstOrDefault(); }
public void Initialize(string className) { if (initialized) { return; } HttpMockServer server; try { server = HttpMockServer.CreateInstance(); } catch (ApplicationException) { // mock server has never been initialized, we will need to initialize it. HttpMockServer.Initialize(className, "InitialCreation"); server = HttpMockServer.CreateInstance(); } if (HttpMockServer.Mode == HttpRecorderMode.Record) { var testFactory = new CSMTestEnvironmentFactory(); var testEnv = testFactory.GetTestEnvironment(); var resourcesClient = TestBase.GetServiceClient <ResourceManagementClient>(testFactory); var mgmtClient = TestBase.GetServiceClient <KeyVaultManagementClient>(testFactory); var tenantId = testEnv.AuthorizationContext.TenantId; //Figure out which locations are available for Key Vault location = GetKeyVaultLocation(resourcesClient); //Create a resource group in that location preCreatedVault = TestUtilities.GenerateName("pshtestvault"); resourceGroupName = TestUtilities.GenerateName("pshtestrg"); resourcesClient.ResourceGroups.CreateOrUpdate(resourceGroupName, new ResourceGroup { Location = location }); var createResponse = CreateVault(mgmtClient, location, tenantId); } initialized = true; }
public KeyVaultTestBase() { var testFactory = new CSMTestEnvironmentFactory(); var testEnv = testFactory.GetTestEnvironment(); this.client = GetServiceClient<KeyVaultManagementClient>(testFactory); this.resourcesClient = GetServiceClient<ResourceManagementClient>(testFactory); if (HttpMockServer.Mode == HttpRecorderMode.Record) { this.tenantId = testEnv.AuthorizationContext.TenatId; this.subscriptionId = testEnv.SubscriptionId; var graphClient = GetGraphServiceClient<GraphRbacManagementClient>(testFactory, tenantId); this.objectId = graphClient.User.Get(testEnv.AuthorizationContext.UserId).User.ObjectId; this.applicationId = Guid.NewGuid().ToString(); HttpMockServer.Variables[TenantIdKey] = tenantId; HttpMockServer.Variables[ObjectIdKey] = objectId; HttpMockServer.Variables[SubIdKey] = subscriptionId; HttpMockServer.Variables[ApplicationIdKey] = applicationId; } else if (HttpMockServer.Mode == HttpRecorderMode.Playback) { tenantId = HttpMockServer.Variables[TenantIdKey]; objectId = HttpMockServer.Variables[ObjectIdKey]; subscriptionId = HttpMockServer.Variables[SubIdKey]; applicationId = HttpMockServer.Variables[ApplicationIdKey]; } var providers = resourcesClient.Providers.Get("Microsoft.KeyVault"); this.location = providers.Provider.ResourceTypes.Where( (resType) => { if (resType.Name == "vaults") return true; else return false; } ).First().Locations.FirstOrDefault(); }
public void Initialize(string className) { if (initialized) return; HttpMockServer server; try { server = HttpMockServer.CreateInstance(); } catch (ApplicationException) { // mock server has never been initialized, we will need to initialize it. HttpMockServer.Initialize(className, "InitialCreation"); server = HttpMockServer.CreateInstance(); } if (HttpMockServer.Mode == HttpRecorderMode.Record) { var testFactory = new CSMTestEnvironmentFactory(); var testEnv = testFactory.GetTestEnvironment(); var resourcesClient = TestBase.GetServiceClient<ResourceManagementClient>(testFactory); var mgmtClient = TestBase.GetServiceClient<KeyVaultManagementClient>(testFactory); var tenantId = testEnv.AuthorizationContext.TenantId; //Figure out which locations are available for Key Vault location = GetKeyVaultLocation(resourcesClient); //Create a resource group in that location preCreatedVault = TestUtilities.GenerateName("pshtestvault"); resourceGroupName = TestUtilities.GenerateName("pshtestrg"); resourcesClient.ResourceGroups.CreateOrUpdate(resourceGroupName, new ResourceGroup { Location = location }); var createResponse = CreateVault(mgmtClient, location, tenantId); } initialized = true; }
public GraphTestBase() { var testFactory = new CSMTestEnvironmentFactory(); TestEnvironment environment = testFactory.GetTestEnvironment(); string tenantId = null; if (HttpMockServer.Mode == HttpRecorderMode.Record) { tenantId = environment.AuthorizationContext.TenantId; Domain = environment.AuthorizationContext.UserId .Split(new [] {"@"}, StringSplitOptions.RemoveEmptyEntries) .Last(); HttpMockServer.Variables[TenantIdKey] = tenantId; HttpMockServer.Variables[DomainKey] = Domain; } else if (HttpMockServer.Mode == HttpRecorderMode.Playback) { tenantId = HttpMockServer.Variables[TenantIdKey]; Domain = HttpMockServer.Variables[DomainKey]; } GraphClient = TestBase.GetGraphServiceClient<GraphRbacManagementClient>(testFactory, tenantId); }
private SearchIndexClient GetSearchIndexClientForKey(string indexName, string apiKey) { var factory = new CSMTestEnvironmentFactory(); TestEnvironment currentEnvironment = factory.GetTestEnvironment(); Uri baseUri = new Uri( currentEnvironment.GetBaseSearchUri(ExecutionMode.CSM, SearchServiceName), String.Format("indexes/{0}/", indexName)); SearchIndexClient client = new SearchIndexClient(new SearchCredentials(apiKey), baseUri); return TestBaseCopy.AddMockHandler<SearchIndexClient>(ref client); }
public void Initialize(string className) { if (initialized) return; HttpMockServer server; try { server = HttpMockServer.CreateInstance(); } catch (ApplicationException) { // mock server has never been initialized, we will need to initialize it. HttpMockServer.Initialize(className, "InitialCreation"); server = HttpMockServer.CreateInstance(); } if (HttpMockServer.Mode == HttpRecorderMode.Record) { fromConfig = FromConfiguration(); if (!fromConfig) { var testFactory = new CSMTestEnvironmentFactory(); var testEnv = testFactory.GetTestEnvironment(); var secret = Guid.NewGuid().ToString(); var mgmtClient = TestBase.GetServiceClient<KeyVaultManagementClient>(testFactory); var resourcesClient = TestBase.GetServiceClient<ResourceManagementClient>(testFactory); var tenantId = testEnv.AuthorizationContext.TenantId; var graphClient = TestBase.GetGraphServiceClient<GraphRbacManagementClient>(testFactory, tenantId); var appDisplayName = TestUtilities.GenerateName("sdktestapp"); //Setup things in AAD //Create an application var app = CreateApplication(graphClient, appDisplayName, secret); appObjectId = app.Application.ObjectId; //Create a corresponding service principal var servicePrincipal = CreateServicePrincipal(app, graphClient); //Figure out which locations are available for Key Vault var location = GetKeyVaultLocation(resourcesClient); //Create a resource group in that location vaultName = TestUtilities.GenerateName("sdktestvault"); rgName = TestUtilities.GenerateName("sdktestrg"); resourcesClient.ResourceGroups.CreateOrUpdate(rgName, new ResourceGroup {Location = location}); //Create a key vault in that resource group var createResponse = CreateVault(mgmtClient, location, tenantId, servicePrincipal); vaultAddress = createResponse.Vault.Properties.VaultUri; _ClientCredential = new ClientCredential(app.Application.AppId, secret); //Wait a few seconds before trying to authenticate TestUtilities.Wait(TimeSpan.FromSeconds(30)); } } initialized = true; }
protected virtual void Dispose(bool disposing) { if (disposing) { if (HttpMockServer.Mode == HttpRecorderMode.Record && initialized) { var testFactory = new CSMTestEnvironmentFactory(); var testEnv = testFactory.GetTestEnvironment(); var resourcesClient = TestBase.GetServiceClient<ResourceManagementClient>(testFactory); resourcesClient.ResourceGroups.Delete(resourceGroupName); } } }
protected GraphRbacManagementClient GetGraphClient() { var testFactory = new CSMTestEnvironmentFactory(); var environment = testFactory.GetTestEnvironment(); string tenantId = Guid.Empty.ToString(); if (HttpMockServer.Mode == HttpRecorderMode.Record) { tenantId = environment.AuthorizationContext.TenantId; UserDomain = environment.AuthorizationContext.UserDomain; HttpMockServer.Variables[TenantIdKey] = tenantId; HttpMockServer.Variables[DomainKey] = UserDomain; } else if (HttpMockServer.Mode == HttpRecorderMode.Playback) { if (HttpMockServer.Variables.ContainsKey(TenantIdKey)) { tenantId = HttpMockServer.Variables[TenantIdKey]; AzureRmProfileProvider.Instance.Profile.Context.Tenant.Id = new Guid(tenantId); } if (HttpMockServer.Variables.ContainsKey(DomainKey)) { UserDomain = HttpMockServer.Variables[DomainKey]; AzureRmProfileProvider.Instance.Profile.Context.Tenant.Domain = UserDomain; } } return TestBase.GetGraphServiceClient<GraphRbacManagementClient>(testFactory, tenantId); }
public void ResetPreCreatedVault() { if (HttpMockServer.Mode == HttpRecorderMode.Record) { var testFactory = new CSMTestEnvironmentFactory(); var testEnv = testFactory.GetTestEnvironment(); var resourcesClient = TestBase.GetServiceClient<ResourceManagementClient>(testFactory); var mgmtClient = TestBase.GetServiceClient<KeyVaultManagementClient>(testFactory); var tenantId = Guid.Parse(testEnv.AuthorizationContext.TenantId); var policies = new AccessPolicyEntry[] { }; mgmtClient.Vaults.CreateOrUpdate( resourceGroupName: resourceGroupName, vaultName: preCreatedVault, parameters: new VaultCreateOrUpdateParameters { Location = location, Tags = new Dictionary<string, string> { { tagName, tagValue } }, Properties = new VaultProperties { EnabledForDeployment = false, Sku = new Sku { Family = "A", Name = "Premium" }, TenantId = tenantId, VaultUri = "", AccessPolicies = policies } } ); } }
public void Initialize(string className) { if (initialized) { return; } HttpMockServer server; try { server = HttpMockServer.CreateInstance(); } catch (ApplicationException) { // mock server has never been initialized, we will need to initialize it. HttpMockServer.Initialize(className, "InitialCreation"); server = HttpMockServer.CreateInstance(); } if (HttpMockServer.Mode == HttpRecorderMode.Record) { fromConfig = FromConfiguration(); if (!fromConfig) { var testFactory = new CSMTestEnvironmentFactory(); var testEnv = testFactory.GetTestEnvironment(); var secret = Guid.NewGuid().ToString(); var mgmtClient = TestBase.GetServiceClient <KeyVaultManagementClient>(testFactory); var resourcesClient = TestBase.GetServiceClient <ResourceManagementClient>(testFactory); var tenantId = testEnv.AuthorizationContext.TenatId; var graphClient = TestBase.GetGraphServiceClient <GraphRbacManagementClient>(testFactory, tenantId); var appDisplayName = TestUtilities.GenerateName("sdktestapp"); //Setup things in AAD //Create an application var app = CreateApplication(graphClient, appDisplayName, secret); appObjectId = app.Application.ObjectId; //Create a corresponding service principal var servicePrincipal = CreateServicePrincipal(app, graphClient); //Figure out which locations are available for Key Vault var location = GetKeyVaultLocation(resourcesClient); //Create a resource group in that location vaultName = TestUtilities.GenerateName("sdktestvault"); rgName = TestUtilities.GenerateName("sdktestrg"); resourcesClient.ResourceGroups.CreateOrUpdate(rgName, new ResourceGroup { Location = location }); //Create a key vault in that resource group var createResponse = CreateVault(mgmtClient, location, tenantId, servicePrincipal); vaultAddress = createResponse.Vault.Properties.VaultUri; _ClientCredential = new ClientCredential(app.Application.AppId, secret); //Wait a few seconds before trying to authenticate TestUtilities.Wait(TimeSpan.FromSeconds(30)); } } initialized = true; }
public void Dispose() { if (HttpMockServer.Mode == HttpRecorderMode.Record && !fromConfig) { var testFactory = new CSMTestEnvironmentFactory(); var testEnv = testFactory.GetTestEnvironment(); var mgmtClient = TestBase.GetServiceClient<KeyVaultManagementClient>(testFactory); var resourcesClient = TestBase.GetServiceClient<ResourceManagementClient>(testFactory); var tenantId = testEnv.AuthorizationContext.TenantId; var graphClient = TestBase.GetGraphServiceClient<GraphRbacManagementClient>(testFactory, tenantId); mgmtClient.Vaults.Delete(rgName, vaultName); graphClient.Application.Delete(appObjectId); resourcesClient.ResourceGroups.Delete(rgName); } }