public void AFDEndpointCreateTest() { var handler1 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; var handler2 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; using (MockContext context = MockContext.Start(this.GetType())) { // Create clients var cdnMgmtClient = CdnTestUtilities.GetCdnManagementClient(context, handler1); var resourcesClient = CdnTestUtilities.GetResourceManagementClient(context, handler2); // Create resource group var resourceGroupName = CdnTestUtilities.CreateResourceGroup(resourcesClient); try { // Create a standard Azure frontdoor profile string profileName = TestUtilities.GenerateName("profile"); Profile createParameters = new Profile { Location = "WestUs", Sku = new Sku { Name = SkuName.StandardAzureFrontDoor }, Tags = new Dictionary <string, string> { { "key1", "value1" }, { "key2", "value2" } } }; var profile = cdnMgmtClient.Profiles.Create(resourceGroupName, profileName, createParameters); // Create a standard Azure frontdoor endpoint string endpointName = TestUtilities.GenerateName("endpointName"); var endpointCreateParameters = new AFDEndpoint("WestUs") { EnabledState = "Enabled", OriginResponseTimeoutSeconds = 60, Tags = new Dictionary <string, string> { { "key1", "value1" }, { "key2", "value2" } } }; var endpoint = cdnMgmtClient.AFDEndpoints.Create(resourceGroupName, profileName, endpointName, endpointCreateParameters); VerifyEndpointCreated(endpointName, endpointCreateParameters, endpoint); } finally { // Delete resource group _ = CdnTestUtilities.DeleteResourceGroupAsync(resourcesClient, resourceGroupName); } } }
public void AFDRuleSetGetListTest() { var handler1 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; var handler2 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; using (MockContext context = MockContext.Start(this.GetType())) { // Create clients var cdnMgmtClient = CdnTestUtilities.GetCdnManagementClient(context, handler1); var resourcesClient = CdnTestUtilities.GetResourceManagementClient(context, handler2); // Create resource group var resourceGroupName = CdnTestUtilities.CreateResourceGroup(resourcesClient); try { // Create a standard Azure frontdoor profile string profileName = TestUtilities.GenerateName("profile"); Profile createParameters = new Profile { Location = "WestUs", Sku = new Sku { Name = SkuName.StandardAzureFrontDoor }, Tags = new Dictionary <string, string> { { "key1", "value1" }, { "key2", "value2" } } }; var profile = cdnMgmtClient.Profiles.Create(resourceGroupName, profileName, createParameters); string ruleSetName = TestUtilities.GenerateName("ruleSetName"); var ruleSet = cdnMgmtClient.RuleSets.Create(resourceGroupName, profileName, ruleSetName); Assert.NotNull(ruleSet); Assert.Equal(ruleSetName, ruleSet.Name); var getRuleSet = cdnMgmtClient.RuleSets.Get(resourceGroupName, profileName, ruleSetName); Assert.NotNull(getRuleSet); Assert.Equal(ruleSetName, getRuleSet.Name); var ruleSetList = cdnMgmtClient.RuleSets.ListByProfile(resourceGroupName, profileName); Assert.NotNull(ruleSetList); Assert.Single(ruleSetList); Assert.Equal(ruleSetName, ruleSetList.First().Name); } finally { // Delete resource group _ = CdnTestUtilities.DeleteResourceGroupAsync(resourcesClient, resourceGroupName); } } }
public void AFDSecretDeleteTest() { var handler1 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; var handler2 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; using (MockContext context = MockContext.Start(this.GetType())) { // Create clients var cdnMgmtClient = CdnTestUtilities.GetCdnManagementClient(context, handler1); var resourcesClient = CdnTestUtilities.GetResourceManagementClient(context, handler2); // Create resource group var resourceGroupName = CdnTestUtilities.CreateResourceGroup(resourcesClient); try { // Create a standard Azure frontdoor profile string profileName = TestUtilities.GenerateName("profile"); Profile createParameters = new Profile { Location = "WestUs", Sku = new Sku { Name = SkuName.StandardAzureFrontDoor }, Tags = new Dictionary <string, string> { { "key1", "value1" }, { "key2", "value2" } } }; var profile = cdnMgmtClient.Profiles.Create(resourceGroupName, profileName, createParameters); // Create a standard Azure frontdoor profile string secretName = TestUtilities.GenerateName("secretName"); var secretSource = new ResourceReference("/subscriptions/d7cfdb98-c118-458d-8bdf-246be66b1f5e/resourceGroups/cdn-powershell-test/providers/Microsoft.KeyVault/vaults/cdn-powershell-test-kv/certificates/cdn-powershell-test-cer"); CustomerCertificateParameters parameters = new CustomerCertificateParameters(secretSource) { UseLatestVersion = true, SubjectAlternativeNames = new List <string>(), }; var secret = cdnMgmtClient.Secrets.Create(resourceGroupName, profileName, secretName, parameters); cdnMgmtClient.Secrets.Delete(resourceGroupName, profileName, secretName); } finally { // Delete resource group _ = CdnTestUtilities.DeleteResourceGroupAsync(resourcesClient, resourceGroupName); } } }
public void AFDOriginGroupListResourceUsageTest() { var handler1 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; var handler2 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; using (MockContext context = MockContext.Start(this.GetType())) { // Create clients var cdnMgmtClient = CdnTestUtilities.GetCdnManagementClient(context, handler1); var resourcesClient = CdnTestUtilities.GetResourceManagementClient(context, handler2); // Create resource group var resourceGroupName = CdnTestUtilities.CreateResourceGroup(resourcesClient); try { // Create a standard Azure frontdoor profile string profileName = TestUtilities.GenerateName("profile"); Profile createParameters = new Profile { Location = "WestUs", Sku = new Sku { Name = SkuName.StandardAzureFrontDoor }, Tags = new Dictionary <string, string> { { "key1", "value1" }, { "key2", "value2" } } }; var profile = cdnMgmtClient.Profiles.Create(resourceGroupName, profileName, createParameters); string originGroupName = TestUtilities.GenerateName("originGroupName"); var originGroupCreateParameters = new AFDOriginGroup(name: originGroupName) { }; var originGroup = cdnMgmtClient.AFDOriginGroups.Create(resourceGroupName, profileName, originGroupName, originGroupCreateParameters); var usageList = cdnMgmtClient.AFDOriginGroups.ListResourceUsage(resourceGroupName, profileName, originGroupName); Assert.Single(usageList); var usage = usageList.First(); Assert.Equal(MaximumAfdOriginCountPerOriginGroup, usage.Limit); Assert.Equal(0, usage.CurrentValue); } finally { // Delete resource group _ = CdnTestUtilities.DeleteResourceGroupAsync(resourcesClient, resourceGroupName); } } }
public void AFDOriginGetListTest() { var handler1 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; var handler2 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; using (MockContext context = MockContext.Start(this.GetType())) { // Create clients var cdnMgmtClient = CdnTestUtilities.GetCdnManagementClient(context, handler1); var resourcesClient = CdnTestUtilities.GetResourceManagementClient(context, handler2); // Create resource group var resourceGroupName = CdnTestUtilities.CreateResourceGroup(resourcesClient); try { // Create a standard Azure frontdoor profile string profileName = TestUtilities.GenerateName("profile"); Profile createParameters = new Profile { Location = "WestUs", Sku = new Sku { Name = SkuName.StandardAzureFrontDoor }, Tags = new Dictionary <string, string> { { "key1", "value1" }, { "key2", "value2" } } }; var profile = cdnMgmtClient.Profiles.Create(resourceGroupName, profileName, createParameters); // Create a standard Azure frontdoor endpoint string endpointName = TestUtilities.GenerateName("endpointName"); var endpointCreateParameters = new AFDEndpoint("WestUs") { EnabledState = "Enabled", OriginResponseTimeoutSeconds = 60, Tags = new Dictionary <string, string> { { "key1", "value1" }, { "key2", "value2" } } }; var endpoint = cdnMgmtClient.AFDEndpoints.Create(resourceGroupName, profileName, endpointName, endpointCreateParameters); // Create a standard Azure frontdoor security policy string securityPolicyName = TestUtilities.GenerateName("securityPolicy"); var policyCreateParameters = new SecurityPolicyWebApplicationFirewallParameters { Associations = new List <SecurityPolicyWebApplicationFirewallAssociation> { new SecurityPolicyWebApplicationFirewallAssociation { Domains = new List <ResourceReference> { new ResourceReference(endpoint.Id), }, PatternsToMatch = new List <string> { "/*" }, } }, WafPolicy = new ResourceReference(id: "/subscriptions/d7cfdb98-c118-458d-8bdf-246be66b1f5e/resourcegroups/chengll-test3632/providers/Microsoft.Network/frontdoorwebapplicationfirewallpolicies/hellowaf"), }; var securityPolicy = cdnMgmtClient.SecurityPolicies.Create(resourceGroupName, profileName, securityPolicyName, policyCreateParameters); Assert.NotNull(securityPolicy); Assert.NotNull(securityPolicy.ProvisioningState); Assert.NotNull(securityPolicy.Parameters); var getSecurityPolicy = cdnMgmtClient.SecurityPolicies.Get(resourceGroupName, profileName, securityPolicyName); Assert.NotNull(getSecurityPolicy); Assert.NotNull(getSecurityPolicy.ProvisioningState); Assert.NotNull(getSecurityPolicy.Parameters); var listSecurityPolicy = cdnMgmtClient.SecurityPolicies.ListByProfile(resourceGroupName, profileName); Assert.NotNull(listSecurityPolicy); Assert.Single(listSecurityPolicy); cdnMgmtClient.SecurityPolicies.Delete(resourceGroupName, profileName, securityPolicyName); listSecurityPolicy = cdnMgmtClient.SecurityPolicies.ListByProfile(resourceGroupName, profileName); Assert.NotNull(listSecurityPolicy); Assert.Empty(listSecurityPolicy); } finally { // Delete resource group _ = CdnTestUtilities.DeleteResourceGroupAsync(resourcesClient, resourceGroupName); } } }
public void AFDRouteGetListTest() { var handler1 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; var handler2 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; using (MockContext context = MockContext.Start(this.GetType())) { // Create clients var cdnMgmtClient = CdnTestUtilities.GetCdnManagementClient(context, handler1); var resourcesClient = CdnTestUtilities.GetResourceManagementClient(context, handler2); // Create resource group var resourceGroupName = CdnTestUtilities.CreateResourceGroup(resourcesClient); try { // Create a standard Azure frontdoor profile string profileName = TestUtilities.GenerateName("profile"); Profile createParameters = new Profile { Location = "WestUs", Sku = new Sku { Name = SkuName.StandardAzureFrontDoor }, Tags = new Dictionary <string, string> { { "key1", "value1" }, { "key2", "value2" } } }; var profile = cdnMgmtClient.Profiles.Create(resourceGroupName, profileName, createParameters); // Create a standard Azure frontdoor endpoint string endpointName = TestUtilities.GenerateName("endpointName"); var endpointCreateParameters = new AFDEndpoint("WestUs") { EnabledState = "Enabled", OriginResponseTimeoutSeconds = 60, Tags = new Dictionary <string, string> { { "key1", "value1" }, { "key2", "value2" } } }; var endpoint = cdnMgmtClient.AFDEndpoints.Create(resourceGroupName, profileName, endpointName, endpointCreateParameters); // Create a standard Azure frontdoor originGroup string originGroupName = TestUtilities.GenerateName("originGroupName"); var originGroupCreateParameters = new AFDOriginGroup(name: originGroupName) { LoadBalancingSettings = new LoadBalancingSettingsParameters { SampleSize = 5, SuccessfulSamplesRequired = 4, AdditionalLatencyInMilliseconds = 200, }, HealthProbeSettings = new HealthProbeParameters { ProbeIntervalInSeconds = 1, ProbePath = "/", ProbeProtocol = ProbeProtocol.Https, ProbeRequestType = HealthProbeRequestType.GET }, }; var originGroup = cdnMgmtClient.AFDOriginGroups.Create(resourceGroupName, profileName, originGroupName, originGroupCreateParameters); // Create a standard Azure frontdoor origin string originName = TestUtilities.GenerateName("originName"); var hostName = "en.wikipedia.org"; var originCreateParameters = new AFDOrigin(hostName: hostName) { OriginHostHeader = hostName, HttpPort = 80, HttpsPort = 443, Priority = 1, Weight = 1000, }; var origin = cdnMgmtClient.AFDOrigins.Create(resourceGroupName, profileName, originGroupName, originName, originCreateParameters); // Create a standard Azure frontdoor ruleSet string ruleSetName = TestUtilities.GenerateName("ruleSetName"); var ruleSet = cdnMgmtClient.RuleSets.Create(resourceGroupName, profileName, ruleSetName); // Create a standard Azure frontdoor rule string ruleName = TestUtilities.GenerateName("ruleName"); var ruleGroupCreateParameters = new Rule { Conditions = new List <DeliveryRuleCondition>() { new DeliveryRuleRequestUriCondition() { Parameters = new RequestUriMatchConditionParameters() { OperatorProperty = "Any" } } }, Actions = new List <DeliveryRuleAction> { new DeliveryRuleCacheExpirationAction() { Parameters = new CacheExpirationActionParameters() { CacheBehavior = "Override", CacheDuration = "00:00:20" } } } }; var rule = cdnMgmtClient.Rules.Create(resourceGroupName, profileName, ruleSetName, ruleName, ruleGroupCreateParameters); // Create a standard Azure frontdoor route string routeName = TestUtilities.GenerateName("routeName"); var routeCreateParameters = new Route { OriginGroup = new ResourceReference(originGroup.Id), RuleSets = new List <ResourceReference>() { new ResourceReference(ruleSet.Id), }, PatternsToMatch = new List <string>() { "/*" }, LinkToDefaultDomain = "Enabled", EnabledState = "Enabled", }; var route = cdnMgmtClient.Routes.Create(resourceGroupName, profileName, endpointName, routeName, routeCreateParameters); Assert.NotNull(route); Assert.Equal(routeName, route.Name); var getRoute = cdnMgmtClient.Routes.Get(resourceGroupName, profileName, endpointName, routeName); Assert.NotNull(getRoute); Assert.Equal(routeName, getRoute.Name); var routList = cdnMgmtClient.Routes.ListByEndpoint(resourceGroupName, profileName, endpointName); Assert.NotNull(routList); Assert.Single(routList); cdnMgmtClient.Routes.Delete(resourceGroupName, profileName, endpointName, routeName); routList = cdnMgmtClient.Routes.ListByEndpoint(resourceGroupName, profileName, endpointName); Assert.NotNull(routList); Assert.Empty(routList); } finally { // Delete resource group _ = CdnTestUtilities.DeleteResourceGroupAsync(resourcesClient, resourceGroupName); } } }
public void GetLogAnalyticsRankingsTest() { var handler1 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; var handler2 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; using (MockContext context = MockContext.Start(this.GetType())) { // Create clients var cdnMgmtClient = CdnTestUtilities.GetCdnManagementClient(context, handler1); var resourcesClient = CdnTestUtilities.GetResourceManagementClient(context, handler2); // Create resource group var resourceGroupName = CdnTestUtilities.CreateResourceGroup(resourcesClient); try { // Create a standard Azure frontdoor profile string profileName = TestUtilities.GenerateName("profile"); Profile createParameters = new Profile { Location = "WestUs", Sku = new Sku { Name = SkuName.StandardAzureFrontDoor }, Tags = new Dictionary <string, string> { { "key1", "value1" }, { "key2", "value2" } } }; var profile = cdnMgmtClient.Profiles.Create(resourceGroupName, profileName, createParameters); // Create a standard Azure frontdoor endpoint string endpointName = TestUtilities.GenerateName("endpointName"); var endpointCreateParameters = new AFDEndpoint("WestUs") { EnabledState = "Enabled", OriginResponseTimeoutSeconds = 60, Tags = new Dictionary <string, string> { { "key1", "value1" }, { "key2", "value2" } } }; var endpoint = cdnMgmtClient.AFDEndpoints.Create(resourceGroupName, profileName, endpointName, endpointCreateParameters); IList <string> rankings = new List <string>() { "url" }; IList <string> metrics = new List <string>() { "clientRequestCount" }; int maxRanking = 50; DateTime dateTimeBegin = new DateTime(2021, 1, 27, 0, 0, 0); DateTime dateTimeEnd = new DateTime(2021, 1, 27, 0, 0, 1); RankingsResponse response = cdnMgmtClient.LogAnalytics.GetLogAnalyticsRankings(resourceGroupName, profileName, rankings, metrics, maxRanking, dateTimeBegin, dateTimeEnd); Assert.NotNull(response); } finally { // Delete resource group _ = CdnTestUtilities.DeleteResourceGroupAsync(resourcesClient, resourceGroupName); } } }
public void AFDOriginUpdateTest() { var handler1 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; var handler2 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; using (MockContext context = MockContext.Start(this.GetType())) { // Create clients var cdnMgmtClient = CdnTestUtilities.GetCdnManagementClient(context, handler1); var resourcesClient = CdnTestUtilities.GetResourceManagementClient(context, handler2); // Create resource group var resourceGroupName = CdnTestUtilities.CreateResourceGroup(resourcesClient); try { // Create a standard Azure frontdoor profile string profileName = TestUtilities.GenerateName("profile"); Profile createParameters = new Profile { Location = "WestUs", Sku = new Sku { Name = SkuName.StandardAzureFrontDoor }, Tags = new Dictionary <string, string> { { "key1", "value1" }, { "key2", "value2" } } }; var profile = cdnMgmtClient.Profiles.Create(resourceGroupName, profileName, createParameters); string originGroupName = TestUtilities.GenerateName("originGroupName"); var originGroupCreateParameters = new AFDOriginGroup(name: originGroupName) { LoadBalancingSettings = new LoadBalancingSettingsParameters { SampleSize = 5, SuccessfulSamplesRequired = 4, AdditionalLatencyInMilliseconds = 200, }, HealthProbeSettings = new HealthProbeParameters { ProbeIntervalInSeconds = 1, ProbePath = "/", ProbeProtocol = ProbeProtocol.Https, ProbeRequestType = HealthProbeRequestType.GET }, }; var originGroup = cdnMgmtClient.AFDOriginGroups.Create(resourceGroupName, profileName, originGroupName, originGroupCreateParameters); Assert.NotNull(originGroup); Assert.Equal(originGroupName, originGroup.Name); string originName = TestUtilities.GenerateName("originName"); var hostName = "en.wikipedia.org"; var originCreateParameters = new AFDOrigin(hostName: hostName) { OriginHostHeader = hostName, HttpPort = 80, HttpsPort = 443, Priority = 1, Weight = 1000, }; var origin = cdnMgmtClient.AFDOrigins.Create(resourceGroupName, profileName, originGroupName, originName, originCreateParameters); VerifyOriginCreated(originName, originCreateParameters, origin); var originUpdateProperties = new AFDOriginUpdateParameters { HostName = "update." + hostName, OriginHostHeader = "update." + hostName, HttpPort = 81, HttpsPort = 443, Priority = 2, Weight = 100, }; var updatedOrigin = cdnMgmtClient.AFDOrigins.Update(resourceGroupName, profileName, originGroupName, originName, originUpdateProperties); VerifyOriginUpdated(originUpdateProperties, updatedOrigin); } finally { // Delete resource group _ = CdnTestUtilities.DeleteResourceGroupAsync(resourcesClient, resourceGroupName); } } }
public void GetWafLogAnalyticsMetricsTest() { var handler1 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; var handler2 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; using (MockContext context = MockContext.Start(this.GetType())) { // Create clients var cdnMgmtClient = CdnTestUtilities.GetCdnManagementClient(context, handler1); var resourcesClient = CdnTestUtilities.GetResourceManagementClient(context, handler2); // Create resource group var resourceGroupName = CdnTestUtilities.CreateResourceGroup(resourcesClient); try { // Create a premium Azure frontdoor profile string profileName = TestUtilities.GenerateName("profile"); Profile createParameters = new Profile { Location = "WestUs", Sku = new Sku { Name = SkuName.PremiumAzureFrontDoor }, Tags = new Dictionary <string, string> { { "key1", "value1" }, { "key2", "value2" } } }; var profile = cdnMgmtClient.Profiles.Create(resourceGroupName, profileName, createParameters); // Create a standard Azure frontdoor endpoint string endpointName = TestUtilities.GenerateName("endpointName"); var endpointCreateParameters = new AFDEndpoint("WestUs") { EnabledState = "Enabled", OriginResponseTimeoutSeconds = 60, Tags = new Dictionary <string, string> { { "key1", "value1" }, { "key2", "value2" } } }; var endpoint = cdnMgmtClient.AFDEndpoints.Create(resourceGroupName, profileName, endpointName, endpointCreateParameters); var domain = $"{endpointName}.z01.azurefd.net"; IList <string> metrics = new List <string>() { LogMetric.ClientRequestCount }; DateTime dateTimeBegin = new DateTime(2021, 1, 27, 0, 0, 0); DateTime dateTimeEnd = new DateTime(2021, 1, 27, 0, 0, 1); string granularity = LogMetricsGranularity.PT5M; WafMetricsResponse response = cdnMgmtClient.LogAnalytics.GetWafLogAnalyticsMetrics(resourceGroupName, profileName, metrics, dateTimeBegin, dateTimeEnd, granularity); Assert.NotNull(response); Assert.NotNull(response.Series); Assert.Equal(dateTimeBegin, response.DateTimeBegin); Assert.Equal(dateTimeEnd, response.DateTimeEnd); Assert.Equal(granularity, response.Granularity); } finally { // Delete resource group _ = CdnTestUtilities.DeleteResourceGroupAsync(resourcesClient, resourceGroupName); } } }
public void AFDCustomDomainUpdateTest() { var handler1 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; var handler2 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; using (MockContext context = MockContext.Start(this.GetType())) { // Create clients var cdnMgmtClient = CdnTestUtilities.GetCdnManagementClient(context, handler1); var resourcesClient = CdnTestUtilities.GetResourceManagementClient(context, handler2); // Create resource group var resourceGroupName = CdnTestUtilities.CreateResourceGroup(resourcesClient); try { // Create a standard Azure frontdoor profile string profileName = TestUtilities.GenerateName("profile"); Profile createParameters = new Profile { Location = "WestUs", Sku = new Sku { Name = SkuName.StandardAzureFrontDoor }, Tags = new Dictionary <string, string> { { "key1", "value1" }, { "key2", "value2" } } }; var profile = cdnMgmtClient.Profiles.Create(resourceGroupName, profileName, createParameters); // Create a standard Azure frontdoor profile secret string secretName = TestUtilities.GenerateName("secretName"); var secretSource = new ResourceReference("/subscriptions/d7cfdb98-c118-458d-8bdf-246be66b1f5e/resourceGroups/cdn-powershell-test/providers/Microsoft.KeyVault/vaults/cdn-powershell-test-kv/certificates/cdn-powershell-test-cer"); CustomerCertificateParameters parameters = new CustomerCertificateParameters(secretSource) { UseLatestVersion = true, SubjectAlternativeNames = new List <string>(), }; var secret = cdnMgmtClient.Secrets.Create(resourceGroupName, profileName, secretName, parameters); // Create a standard Azure frontdoor profile customDomain string customDomainName = TestUtilities.GenerateName("customDomainName"); var hostName = "csharpsdk.dev.cdn.azure.cn"; AFDDomain afdDomainCreateParameters = new AFDDomain() { HostName = hostName, TlsSettings = new AFDDomainHttpsParameters { CertificateType = "CustomerCertificate", MinimumTlsVersion = AfdMinimumTlsVersion.TLS12, Secret = new ResourceReference(secret.Id) }, }; //Need manualy add dns txt record var afdDomain = cdnMgmtClient.AFDCustomDomains.Create(resourceGroupName, profileName, customDomainName, afdDomainCreateParameters); Assert.NotNull(afdDomain); Assert.Equal("Approved", afdDomain.DomainValidationState); var updateTlsSettingsParams = new AFDDomainHttpsParameters { CertificateType = "CustomerCertificate", MinimumTlsVersion = AfdMinimumTlsVersion.TLS10, Secret = new ResourceReference(secret.Id) }; var updatedAfdDomain = cdnMgmtClient.AFDCustomDomains.Update(resourceGroupName, profileName, customDomainName, updateTlsSettingsParams); Assert.NotNull(updateTlsSettingsParams); Assert.Equal("Approved", updatedAfdDomain.DomainValidationState); Assert.Equal(updateTlsSettingsParams.MinimumTlsVersion, updatedAfdDomain.TlsSettings.MinimumTlsVersion); } finally { // Delete resource group _ = CdnTestUtilities.DeleteResourceGroupAsync(resourcesClient, resourceGroupName); } } }
public void AFDRuleUpdateTest() { var handler1 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; var handler2 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; using (MockContext context = MockContext.Start(this.GetType())) { // Create clients var cdnMgmtClient = CdnTestUtilities.GetCdnManagementClient(context, handler1); var resourcesClient = CdnTestUtilities.GetResourceManagementClient(context, handler2); // Create resource group var resourceGroupName = CdnTestUtilities.CreateResourceGroup(resourcesClient); try { // Create a standard Azure frontdoor profile string profileName = TestUtilities.GenerateName("profile"); Profile createParameters = new Profile { Location = "WestUs", Sku = new Sku { Name = SkuName.StandardAzureFrontDoor }, Tags = new Dictionary <string, string> { { "key1", "value1" }, { "key2", "value2" } } }; var profile = cdnMgmtClient.Profiles.Create(resourceGroupName, profileName, createParameters); string ruleSetName = TestUtilities.GenerateName("ruleSetName"); var ruleSet = cdnMgmtClient.RuleSets.Create(resourceGroupName, profileName, ruleSetName); Assert.NotNull(ruleSet); Assert.Equal(ruleSetName, ruleSet.Name); // Create a standard Azure frontdoor rule string ruleName = TestUtilities.GenerateName("ruleName"); var ruleGroupCreateParameters = new Rule { Conditions = new List <DeliveryRuleCondition>() { new DeliveryRuleRequestUriCondition() { Parameters = new RequestUriMatchConditionParameters() { OperatorProperty = "Any" } } }, Actions = new List <DeliveryRuleAction> { new DeliveryRuleCacheExpirationAction() { Parameters = new CacheExpirationActionParameters() { CacheBehavior = "Override", CacheDuration = "00:00:20" } } } }; var rule = cdnMgmtClient.Rules.Create(resourceGroupName, profileName, ruleSetName, ruleName, ruleGroupCreateParameters); Assert.NotNull(rule); Assert.Equal(ruleName, rule.Name); Assert.Equal(ruleGroupCreateParameters.Conditions.Count, rule.Conditions.Count); Assert.Equal(ruleGroupCreateParameters.Actions.Count, rule.Actions.Count); RuleUpdateParameters ruleUpdateProperties = new RuleUpdateParameters() { Conditions = new List <DeliveryRuleCondition>() { }, Actions = new List <DeliveryRuleAction> { new DeliveryRuleCacheExpirationAction() { Parameters = new CacheExpirationActionParameters() { CacheBehavior = "Override", CacheDuration = "00:00:20" } } } }; var updatedRule = cdnMgmtClient.Rules.Update(resourceGroupName, profileName, ruleSetName, ruleName, ruleUpdateProperties); Assert.NotNull(updatedRule); Assert.Equal(ruleName, updatedRule.Name); Assert.Equal(ruleUpdateProperties.Conditions.Count, updatedRule.Conditions.Count); Assert.Equal(ruleUpdateProperties.Actions.Count, updatedRule.Actions.Count); } finally { // Delete resource group _ = CdnTestUtilities.DeleteResourceGroupAsync(resourcesClient, resourceGroupName); } } }
public void AFDProfileCheckHostNameAvailabilityTest() { var handler1 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; var handler2 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; using (MockContext context = MockContext.Start(this.GetType())) { // Create clients var cdnMgmtClient = CdnTestUtilities.GetCdnManagementClient(context, handler1); var resourcesClient = CdnTestUtilities.GetResourceManagementClient(context, handler2); // Create resource group var resourceGroupName = CdnTestUtilities.CreateResourceGroup(resourcesClient); try { // Create a standard Azure frontdoor profile string profileName = TestUtilities.GenerateName("profile"); Profile createParameters = new Profile { Location = "WestUs", Sku = new Sku { Name = SkuName.StandardAzureFrontDoor }, Tags = new Dictionary <string, string> { { "key1", "value1" }, { "key2", "value2" } } }; var profile = cdnMgmtClient.Profiles.Create(resourceGroupName, profileName, createParameters); // Generate new endpoint name string endpointName = TestUtilities.GenerateName("endpoint-unique"); var hostName = "host1.hello.com"; // CheckNameAvailability should return true var output = cdnMgmtClient.AFDProfiles.CheckHostNameAvailability(resourceGroupName, profileName, hostName); Assert.True(output.CustomDomainValidated); // Create a standard cdn profile string afdEndpointName = TestUtilities.GenerateName("host1-hello-com"); // Create endpoint with that name then CheckNameAvailability again // Create endpoint with this name var endpointCreateParameters = new AFDEndpoint { Location = "WestUs", }; var endpoint = cdnMgmtClient.AFDEndpoints.Create(resourceGroupName, profileName, endpointName, endpointCreateParameters); // CheckNameAvailability after endpoint was created should return false output = cdnMgmtClient.AFDProfiles.CheckHostNameAvailability(resourceGroupName, profileName, hostName); Assert.False(output.CustomDomainValidated); } finally { // Delete resource group _ = CdnTestUtilities.DeleteResourceGroupAsync(resourcesClient, resourceGroupName); } } }