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 GetEdgeNodeTest() { const int minPrefixLength = 0; const int maxIpv4PrefixLength = 32; const int maxIpv6PrefixLength = 128; var expectedEdgeNodeNames = new List <string> { "Standard_Verizon", "Premium_Verizon", "Custom_Verizon" }; 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); var edgeNodes = cdnMgmtClient.EdgeNodes.List().GetEnumerator().ToIEnumerable <EdgeNode>().ToList(); Assert.Empty(edgeNodes.Select(e => e.Name).Except(expectedEdgeNodeNames)); Assert.Empty(expectedEdgeNodeNames.Except(edgeNodes.Select(e => e.Name))); foreach (var edgeNode in edgeNodes) { Assert.True(edgeNode.IpAddressGroups.Count > 0); foreach (var ipAddressGroup in edgeNode.IpAddressGroups) { Assert.False(string.IsNullOrWhiteSpace(ipAddressGroup.DeliveryRegion)); Assert.True(ipAddressGroup.Ipv4Addresses.Count > 0); foreach (var cidrIpAddress in ipAddressGroup.Ipv4Addresses) { Assert.False(string.IsNullOrWhiteSpace(cidrIpAddress.BaseIpAddress)); Assert.True(cidrIpAddress.PrefixLength >= minPrefixLength && cidrIpAddress.PrefixLength <= maxIpv4PrefixLength); } Assert.True(ipAddressGroup.Ipv6Addresses.Count > 0); foreach (var cidrIpAddress in ipAddressGroup.Ipv6Addresses) { Assert.False(string.IsNullOrWhiteSpace(cidrIpAddress.BaseIpAddress)); Assert.True(cidrIpAddress.PrefixLength >= minPrefixLength && cidrIpAddress.PrefixLength <= maxIpv6PrefixLength); } } } } }
public void ValidateProbePathTest() { var handler1 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; var handler2 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; using (MockContext context = MockContext.Start(this.GetType())) { // Create client var cdnMgmtClient = CdnTestUtilities.GetCdnManagementClient(context, handler1); //1. Validate probe with invalid URL should fail. Assert.ThrowsAny <ErrorResponseException>(() => { cdnMgmtClient.ValidateProbe("www.withoutHttp.com"); }); //2. Validate probe with valid but non-existing URL should return false. var output = cdnMgmtClient.ValidateProbe("https://www.notexist.com/notexist/notexist.txt"); Assert.NotNull(output.IsValid); Assert.False(output.IsValid); //3. Validate probe with a valid and existing URL should return true. output = cdnMgmtClient.ValidateProbe("https://azurecdn-files.azureedge.net/dsa-test/probe-v.txt"); Assert.NotNull(output.IsValid); Assert.True(output.IsValid); //4. Validate probe with invalid ip address as host should fail. Assert.ThrowsAny <ErrorResponseException>(() => { cdnMgmtClient.ValidateProbe("http://999.999.999.999/nonexist.txt"); }); //5. Validate probe with valid but non-exist url, when host is an ip address, should return false. output = cdnMgmtClient.ValidateProbe("http://192.168.1.1/nonexist.aspx"); Assert.NotNull(output.IsValid); Assert.False(output.IsValid); //6. Validate probe with valid and exist url, when host is an ip address, should return true. //TODO: The IP address is from a client. Replace it with a valid IP that we own. output = cdnMgmtClient.ValidateProbe("http://137.117.34.31/contact/contact.aspx"); Assert.NotNull(output.IsValid); Assert.True(output.IsValid); } }
public void GetSupportedOptimizationTypes() { 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); // Create a standard cdn profile string profileName = TestUtilities.GenerateName("profile"); Profile createParameters = new Profile { Location = "WestUs", Sku = new Sku { Name = SkuName.StandardVerizon }, Tags = new Dictionary <string, string> { { "key1", "value1" }, { "key2", "value2" } } }; var profile = cdnMgmtClient.Profiles.Create(resourceGroupName, profileName, createParameters); VerifyProfileCreated(profile, createParameters); // Get the supported optimization types for the created profile should succeed var supportedOptimizationTypesResult = cdnMgmtClient.Profiles.ListSupportedOptimizationTypes(resourceGroupName, profileName); Assert.NotNull(supportedOptimizationTypesResult); Assert.NotNull(supportedOptimizationTypesResult.SupportedOptimizationTypes); Assert.NotEmpty(supportedOptimizationTypesResult.SupportedOptimizationTypes); // Delete resource group CdnTestUtilities.DeleteResourceGroup(resourcesClient, resourceGroupName); } }
public void WafPolicyGetListTest() { 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); // List WAF policies should return none var policies = cdnMgmtClient.Policies.List(resourceGroupName.ToUpperInvariant()); Assert.Empty(policies); // Create a minimal CDN WAF policy var policyName = TestUtilities.GenerateName("policy"); var policy = cdnMgmtClient.Policies.CreateOrUpdate(resourceGroupName, policyName, new CdnWebApplicationFirewallPolicy { Sku = new Sku(SkuName.StandardMicrosoft), Location = "Global", }); // Get WAF policies returns the created policy var existingPolicy = cdnMgmtClient.Policies.Get(resourceGroupName, policyName); Assert.NotNull(existingPolicy); Assert.Equal(existingPolicy.ResourceState, PolicyResourceState.Enabled); // List WAF policies should return one policy policies = cdnMgmtClient.Policies.List(resourceGroupName.ToUpperInvariant()); Assert.Single(policies); // Delete resource group CdnTestUtilities.DeleteResourceGroup(resourcesClient, resourceGroupName); } }
public void ListOperationsTest() { var handler1 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; var handler2 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; using (MockContext context = MockContext.Start(this.GetType().FullName)) { // Create client var cdnMgmtClient = CdnTestUtilities.GetCdnManagementClient(context, handler1); // Get operations var operations = cdnMgmtClient.Operations.List(); // Verify operations are returned Assert.NotNull(operations); Assert.NotEqual(0, operations.Count()); } }
public void CustomDomainCRUDTest() { var handler1 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; var handler2 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; using (MockContext context = MockContext.Start(this.GetType().FullName)) { // Create clients var cdnMgmtClient = CdnTestUtilities.GetCdnManagementClient(context, handler1); var resourcesClient = CdnTestUtilities.GetResourceManagementClient(context, handler2); // Create resource group var resourceGroupName = CdnTestUtilities.CreateResourceGroup(resourcesClient); // Create a standard cdn profile string profileName = TestUtilities.GenerateName("profile"); ProfileCreateParameters createParameters = new ProfileCreateParameters { Location = "WestUs", Sku = new Sku { Name = SkuName.StandardVerizon }, Tags = new Dictionary <string, string> { { "key1", "value1" }, { "key2", "value2" } } }; var profile = cdnMgmtClient.Profiles.Create(profileName, createParameters, resourceGroupName); // Create a cdn endpoint with minimum requirements string endpointName = "endpoint-554d5e6b9f56"; var endpointCreateParameters = new EndpointCreateParameters { Location = "WestUs", IsHttpAllowed = true, IsHttpsAllowed = true, Origins = new List <DeepCreatedOrigin> { new DeepCreatedOrigin { Name = "origin1", HostName = "host1.hello.com" } } }; var endpoint = cdnMgmtClient.Endpoints.Create(endpointName, endpointCreateParameters, profileName, resourceGroupName); // List custom domains one this endpoint should return none var customDomains = cdnMgmtClient.CustomDomains.ListByEndpoint(endpointName, profileName, resourceGroupName); Assert.Equal(0, customDomains.Count()); // NOTE: There is a CName mapping already created for this custom domain and endpoint hostname // "sdk-1-5b4d5e6b9f56.azureedge-test.net" maps to "endpoint-554d5e6b9f56.azureedge-test.net" // "sdk-2-5b4d5e6b9f56.azureedge-test.net" maps to "endpoint-554d5e6b9f56.azureedge-test.net" // Create custom domain on running endpoint should succeed string customDomainName1 = TestUtilities.GenerateName("customDomain"); cdnMgmtClient.CustomDomains.Create(customDomainName1, endpointName, profileName, resourceGroupName, "sdk-1-5b4d5e6b9f56.azureedge-test.net"); // List custom domains one this endpoint should return one customDomains = cdnMgmtClient.CustomDomains.ListByEndpoint(endpointName, profileName, resourceGroupName); Assert.Equal(1, customDomains.Count()); // Update custom domain on running endpoint should fail Assert.ThrowsAny <ErrorResponseException>(() => { cdnMgmtClient.CustomDomains.Update(customDomainName1, endpointName, profileName, resourceGroupName, "customdomain11.hello.com"); }); // Stop endpoint cdnMgmtClient.Endpoints.Stop(endpointName, profileName, resourceGroupName); // Create another custom domain on stopped endpoint should succeed string customDomainName2 = TestUtilities.GenerateName("customDomain"); cdnMgmtClient.CustomDomains.Create(customDomainName2, endpointName, profileName, resourceGroupName, "sdk-2-5b4d5e6b9f56.azureedge-test.net"); // List custom domains one this endpoint should return two customDomains = cdnMgmtClient.CustomDomains.ListByEndpoint(endpointName, profileName, resourceGroupName); Assert.Equal(2, customDomains.Count()); // Update custom domain on stopped endpoint should fail Assert.ThrowsAny <ErrorResponseException>(() => { cdnMgmtClient.CustomDomains.Update(customDomainName2, endpointName, profileName, resourceGroupName, "customdomain22.hello.com"); }); // Delete second custom domain on stopped endpoint should succeed cdnMgmtClient.CustomDomains.DeleteIfExists(customDomainName2, endpointName, profileName, resourceGroupName); // Get deleted custom domain should fail Assert.ThrowsAny <ErrorResponseException>(() => { cdnMgmtClient.CustomDomains.Get(customDomainName2, endpointName, profileName, resourceGroupName); }); // List custom domains on endpoint should return one customDomains = cdnMgmtClient.CustomDomains.ListByEndpoint(endpointName, profileName, resourceGroupName); Assert.Equal(1, customDomains.Count()); // Start endpoint cdnMgmtClient.Endpoints.Start(endpointName, profileName, resourceGroupName); // Delete first custom domain on stopped endpoint should succeed cdnMgmtClient.CustomDomains.DeleteIfExists(customDomainName1, endpointName, profileName, resourceGroupName); // Get deleted custom domain should fail Assert.ThrowsAny <ErrorResponseException>(() => { cdnMgmtClient.CustomDomains.Get(customDomainName1, endpointName, profileName, resourceGroupName); }); // List custom domains on endpoint should return none customDomains = cdnMgmtClient.CustomDomains.ListByEndpoint(endpointName, profileName, resourceGroupName); Assert.Equal(0, customDomains.Count()); // Delete resource group CdnTestUtilities.DeleteResourceGroup(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 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 ProfileUpdateTest() { 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); // Create a standard cdn profile string profileName = TestUtilities.GenerateName("profile"); Profile createParameters = new Profile { Location = "WestUs", Sku = new Sku { Name = SkuName.StandardAkamai }, Tags = new Dictionary <string, string> { { "key1", "value1" }, { "key2", "value2" } } }; var profile = cdnMgmtClient.Profiles.Create(resourceGroupName, profileName, createParameters); VerifyProfileCreated(profile, createParameters); // Update profile with new tags var newTags = new Dictionary <string, string> { { "newkey1", "newValue1" } }; var updatedProfile = cdnMgmtClient.Profiles.Update( resourceGroupName, profileName, newTags); VerifyProfileUpdated(profile, updatedProfile, newTags); // Create a standard cdn profile and don't wait for creation to finish profileName = TestUtilities.GenerateName("profile"); createParameters = new Profile { Location = "WestUs", Sku = new Sku { Name = SkuName.StandardVerizon }, Tags = new Dictionary <string, string> { { "key1", "value1" }, { "key2", "value2" } } }; cdnMgmtClient.Profiles.BeginCreateAsync(resourceGroupName, profileName, createParameters) .ConfigureAwait(false) .GetAwaiter() .GetResult(); // Update profile in creating state should fail var tags = new Dictionary <string, string> { { "key", "value" } }; Assert.ThrowsAny <ErrorResponseException>(() => { cdnMgmtClient.Profiles.Update(resourceGroupName, profileName, tags); }); // Wait for second profile to complete creation CdnTestUtilities.WaitIfNotInPlaybackMode(2); // Update profile now should succeed cdnMgmtClient.Profiles.Update(resourceGroupName, profileName, tags); // Delete resource group CdnTestUtilities.DeleteResourceGroup(resourcesClient, resourceGroupName); } }
public void OriginUpdateTest() { 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); // Create a standard cdn profile string profileName = TestUtilities.GenerateName("profile"); Profile createParameters = new Profile { Location = "WestUs", Sku = new Sku { Name = SkuName.StandardVerizon }, Tags = new Dictionary <string, string> { { "key1", "value1" }, { "key2", "value2" } } }; var profile = cdnMgmtClient.Profiles.Create(resourceGroupName, profileName, createParameters); // Create a cdn endpoint with minimum requirements string endpointName = TestUtilities.GenerateName("endpoint"); var endpointCreateParameters = new Endpoint { Location = "WestUs", IsHttpAllowed = true, IsHttpsAllowed = true, Origins = new List <DeepCreatedOrigin> { new DeepCreatedOrigin { Name = "origin1", HostName = "host1.hello.com" } } }; var endpoint = cdnMgmtClient.Endpoints.Create(resourceGroupName, profileName, endpointName, endpointCreateParameters); // Update origin on running endpoint should succeed var originParameters = new OriginUpdateParameters { HostName = "www.bing.com", HttpPort = 1234, HttpsPort = 8081 }; cdnMgmtClient.Origins.Update(resourceGroupName, profileName, endpointName, "origin1", originParameters); // Update origin with invalid hostname should fail originParameters = new OriginUpdateParameters { HostName = "invalid!Hostname&", HttpPort = 1234, HttpsPort = 8081 }; Assert.ThrowsAny <ErrorResponseException>(() => { cdnMgmtClient.Origins.Update(resourceGroupName, profileName, endpointName, "origin1", originParameters); }); // Stop endpoint should succeed cdnMgmtClient.Endpoints.Stop(resourceGroupName, profileName, endpointName); // Update origin on stopped endpoint should succeed originParameters = new OriginUpdateParameters { HostName = "www.hello.com", HttpPort = 1265 }; cdnMgmtClient.Origins.Update(resourceGroupName, profileName, endpointName, "origin1", originParameters); // Update origin with invalid ports should fail originParameters = new OriginUpdateParameters { HttpPort = 99999, HttpsPort = -2000 }; Assert.ThrowsAny <ErrorResponseException>(() => { cdnMgmtClient.Origins.Update(resourceGroupName, profileName, endpointName, "origin1", originParameters); }); // Delete resource group CdnTestUtilities.DeleteResourceGroup(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 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 ProfileCheckUsageTest() { 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); // CheckUsage on subscription to get existing usage for profiles var subscriptionLevelUsages = cdnMgmtClient.ResourceUsage.List(); Assert.Single(subscriptionLevelUsages); var defaultSubscriptionUsage = subscriptionLevelUsages.First(); var existingSubscriptionUsageLimit = defaultSubscriptionUsage.Limit; var existingSubscriptionUsageCurrentValue = defaultSubscriptionUsage.CurrentValue; // Create resource group var resourceGroupName = CdnTestUtilities.CreateResourceGroup(resourcesClient); // Create a standard cdn profile string profileName = TestUtilities.GenerateName("profile"); Profile createParameters = new Profile { Location = "WestUs", Sku = new Sku { Name = SkuName.StandardVerizon }, Tags = new Dictionary <string, string> { { "key1", "value1" }, { "key2", "value2" } } }; var profile = cdnMgmtClient.Profiles.Create(resourceGroupName, profileName, createParameters); VerifyProfileCreated(profile, createParameters); subscriptionLevelUsages = cdnMgmtClient.ResourceUsage.List(); Assert.Single(subscriptionLevelUsages); var usageAfterCreation = subscriptionLevelUsages.First(); Assert.Equal(existingSubscriptionUsageLimit, usageAfterCreation.Limit); Assert.Equal(existingSubscriptionUsageCurrentValue + 1, usageAfterCreation.CurrentValue); // test Profile level usage - usage for endpoints under the profile var profileLevelUsages = cdnMgmtClient.Profiles.ListResourceUsage(resourceGroupName, profileName); Assert.Single(profileLevelUsages); var profileLevelUsage = profileLevelUsages.First(); Assert.Equal(25, profileLevelUsage.Limit); Assert.Equal(0, profileLevelUsage.CurrentValue); //Create an endpoint under this profile string endpointName = TestUtilities.GenerateName("endpoint"); var endpointCreateParameters = new Endpoint { Location = "WestUs", IsHttpAllowed = true, IsHttpsAllowed = true, Origins = new List <DeepCreatedOrigin> { new DeepCreatedOrigin { Name = "origin1", HostName = "host1.hello.com" } } }; var endpoint = cdnMgmtClient.Endpoints.Create(resourceGroupName, profileName, endpointName, endpointCreateParameters); profileLevelUsages = cdnMgmtClient.Profiles.ListResourceUsage(resourceGroupName, profileName); Assert.Single(profileLevelUsages); var profileLevelUsageAfterEndpointCreation = profileLevelUsages.First(); Assert.Equal(25, profileLevelUsageAfterEndpointCreation.Limit); Assert.Equal(1, profileLevelUsageAfterEndpointCreation.CurrentValue); // Delete resource group CdnTestUtilities.DeleteResourceGroup(resourcesClient, resourceGroupName); } }
public void ProfileListBySubcriptionTest() { 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 resourceGroupName1 = CdnTestUtilities.CreateResourceGroup(resourcesClient); // List profiles should return all profiles in the subscription var profiles = cdnMgmtClient.Profiles.List(); var existingProfileCount = profiles.Count(); // Create a standard cdn profile string profileName = TestUtilities.GenerateName("profile"); Profile createParameters = new Profile { Location = "WestUs", Sku = new Sku { Name = SkuName.StandardVerizon }, Tags = new Dictionary <string, string> { { "key1", "value1" }, { "key2", "value2" } } }; var profile = cdnMgmtClient.Profiles.Create(resourceGroupName1, profileName, createParameters); VerifyProfileCreated(profile, createParameters); // Get profile returns the created profile var existingProfile = cdnMgmtClient.Profiles.Get(resourceGroupName1, profileName); VerifyProfilesEqual(profile, existingProfile); // List profile returns the created profile profiles = cdnMgmtClient.Profiles.List(); Assert.NotNull(profiles.FirstOrDefault(x => x.Name == profileName)); // Create another resource group var resourceGroupName2 = CdnTestUtilities.CreateResourceGroup(resourcesClient); // Create a second cdn profile and don't wait for creation to finish var profileName2 = TestUtilities.GenerateName("profile"); createParameters = new Profile { Location = "WestUs", Sku = new Sku { Name = SkuName.StandardVerizon }, Tags = new Dictionary <string, string> { { "key1", "value1" }, { "key2", "value2" } } }; profile = cdnMgmtClient.Profiles.Create(resourceGroupName2, profileName2, createParameters); VerifyProfileCreated(profile, createParameters); // List profiles should return the new profiles profiles = cdnMgmtClient.Profiles.List(); Assert.NotNull(profiles.FirstOrDefault(x => x.Name == profileName2)); // Delete first profile cdnMgmtClient.Profiles.Delete(resourceGroupName1, profileName); // Verify the created profile no longer is listed profiles = cdnMgmtClient.Profiles.List(); Assert.Null(profiles.FirstOrDefault(x => x.Name == profileName)); // Delete second profile cdnMgmtClient.Profiles.Delete(resourceGroupName2, profileName2); // Verify the second profile no longer is listed profiles = cdnMgmtClient.Profiles.List(); Assert.Null(profiles.FirstOrDefault(x => x.Name == profileName2)); // Delete resource groups CdnTestUtilities.DeleteResourceGroup(resourcesClient, resourceGroupName1); CdnTestUtilities.DeleteResourceGroup(resourcesClient, resourceGroupName2); } }
public void GenerateSsoUriTest() { 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); // Create a standard cdn profile string profileName = TestUtilities.GenerateName("profile"); Profile createParameters = new Profile { Location = "WestUs", Sku = new Sku { Name = SkuName.StandardVerizon }, Tags = new Dictionary <string, string> { { "key1", "value1" }, { "key2", "value2" } } }; var profile = cdnMgmtClient.Profiles.Create(resourceGroupName, profileName, createParameters); VerifyProfileCreated(profile, createParameters); // Generate Sso Uri on created profile should succeed var ssoUri = cdnMgmtClient.Profiles.GenerateSsoUri(resourceGroupName, profileName); Assert.NotNull(ssoUri); Assert.False(string.IsNullOrWhiteSpace(ssoUri.SsoUriValue)); // Create a cdn profile and don't wait for creation to finish profileName = TestUtilities.GenerateName("profile"); createParameters = new Profile { Location = "WestUs", Sku = new Sku { Name = SkuName.StandardVerizon }, Tags = new Dictionary <string, string> { { "key1", "value1" }, { "key2", "value2" } } }; cdnMgmtClient.Profiles.BeginCreateAsync(resourceGroupName, profileName, createParameters) .ConfigureAwait(false) .GetAwaiter() .GetResult(); // Generate Sso Uri on creating profile should fail Assert.ThrowsAny <ErrorResponseException>(() => { cdnMgmtClient.Profiles.GenerateSsoUri(resourceGroupName, profileName); }); // Delete resource group CdnTestUtilities.DeleteResourceGroup(resourcesClient, resourceGroupName); } }
public void ProfileGetListTest() { 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); // List profiles should return none var profiles = cdnMgmtClient.Profiles.ListByResourceGroup(resourceGroupName); Assert.Empty(profiles); // Create a standard cdn profile string profileName = TestUtilities.GenerateName("profile"); Profile createParameters = new Profile { Location = "WestUs", Sku = new Sku { Name = SkuName.StandardVerizon }, Tags = new Dictionary <string, string> { { "key1", "value1" }, { "key2", "value2" } } }; var profile = cdnMgmtClient.Profiles.Create(resourceGroupName, profileName, createParameters); VerifyProfileCreated(profile, createParameters); // Get profile returns the created profile var existingProfile = cdnMgmtClient.Profiles.Get(resourceGroupName, profileName); VerifyProfilesEqual(profile, existingProfile); // List profiles should return one profile profiles = cdnMgmtClient.Profiles.ListByResourceGroup(resourceGroupName); Assert.Single(profiles); // Create a second cdn profile and don't wait for creation to finish var profileName2 = TestUtilities.GenerateName("profile"); createParameters = new Profile { Location = "WestUs", Sku = new Sku { Name = SkuName.StandardVerizon }, Tags = new Dictionary <string, string> { { "key1", "value1" }, { "key2", "value2" } } }; cdnMgmtClient.Profiles.BeginCreateAsync(resourceGroupName, profileName2, createParameters) .ConfigureAwait(false) .GetAwaiter() .GetResult(); // List profiles should return two profiles profiles = cdnMgmtClient.Profiles.ListByResourceGroup(resourceGroupName); Assert.Equal(2, profiles.Count()); // Delete first profile cdnMgmtClient.Profiles.Delete(resourceGroupName, profileName); // Get deleted profile should fail Assert.ThrowsAny <ErrorResponseException>(() => { cdnMgmtClient.Profiles.Get(resourceGroupName, profileName); }); // List profiles should return only one profile profiles = cdnMgmtClient.Profiles.ListByResourceGroup(resourceGroupName); Assert.Single(profiles); // Wait for second profile to complete creation CdnTestUtilities.WaitIfNotInPlaybackMode(); // Delete second profile but don't wait for operation to complete cdnMgmtClient.Profiles.BeginDeleteAsync(resourceGroupName, profileName2) .ConfigureAwait(false) .GetAwaiter() .GetResult(); // Get second profile returns profile in Deleting state existingProfile = cdnMgmtClient.Profiles.Get(resourceGroupName, profileName2); Assert.Equal(existingProfile.ResourceState, ProfileResourceState.Deleting); // Wait for second profile to complete creation CdnTestUtilities.WaitIfNotInPlaybackMode(); // List profiles should none profiles = cdnMgmtClient.Profiles.ListByResourceGroup(resourceGroupName); Assert.Empty(profiles); // Delete resource group CdnTestUtilities.DeleteResourceGroup(resourcesClient, resourceGroupName); } }
public void ProfileDeleteTest() { 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); // Create a standard cdn profile string profileName = TestUtilities.GenerateName("profile"); Profile createParameters = new Profile { Location = "WestUs", Sku = new Sku { Name = SkuName.StandardVerizon }, Tags = new Dictionary <string, string> { { "key1", "value1" }, { "key2", "value2" } } }; var profile = cdnMgmtClient.Profiles.Create(resourceGroupName, profileName, createParameters); VerifyProfileCreated(profile, createParameters); // Delete existing profile should succeed cdnMgmtClient.Profiles.Delete(resourceGroupName, profile.Name); // List profiles should return none var profiles = cdnMgmtClient.Profiles.ListByResourceGroup(resourceGroupName); Assert.Empty(profiles); // Delete non-existing profile should succeed cdnMgmtClient.Profiles.Delete(resourceGroupName, profile.Name); // Create a standard cdn profile and don't wait for creation to finish profileName = TestUtilities.GenerateName("profile"); createParameters = new Profile { Location = "WestUs", Sku = new Sku { Name = SkuName.StandardVerizon }, Tags = new Dictionary <string, string> { { "key1", "value1" }, { "key2", "value2" } } }; cdnMgmtClient.Profiles.BeginCreateAsync(resourceGroupName, profileName, createParameters) .ConfigureAwait(false) .GetAwaiter() .GetResult(); // Wait for second profile to complete creation CdnTestUtilities.WaitIfNotInPlaybackMode(); // Delete profile should succeed cdnMgmtClient.Profiles.Delete(resourceGroupName, profileName); // List profiles should return none profiles = cdnMgmtClient.Profiles.ListByResourceGroup(resourceGroupName); Assert.Empty(profiles); // Delete resource group CdnTestUtilities.DeleteResourceGroup(resourcesClient, resourceGroupName); } }
public void ProfileCreateTest() { 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); // Create a standard verizon cdn profile string profileName = TestUtilities.GenerateName("profile"); Profile createParameters = new Profile { Location = "WestUs", Sku = new Sku { Name = SkuName.StandardVerizon }, Tags = new Dictionary <string, string> { { "key1", "value1" }, { "key2", "value2" } } }; var profile = cdnMgmtClient.Profiles.Create(resourceGroupName, profileName, createParameters); VerifyProfileCreated(profile, createParameters); // Create a standard akamai cdn profile profileName = TestUtilities.GenerateName("profile"); createParameters = new Profile { Location = "EastUs", Sku = new Sku { Name = SkuName.StandardAkamai }, Tags = new Dictionary <string, string> { { "key3", "value3" }, { "key4", "value4" } } }; profile = cdnMgmtClient.Profiles.Create(resourceGroupName, profileName, createParameters); VerifyProfileCreated(profile, createParameters); // Create a standard microsoft cdn profile profileName = TestUtilities.GenerateName("profile"); createParameters = new Profile { Location = "WestUs", Sku = new Sku { Name = SkuName.StandardMicrosoft }, Tags = new Dictionary <string, string> { { "key5", "value5" }, { "key6", "value6" } } }; profile = cdnMgmtClient.Profiles.Create(resourceGroupName, profileName, createParameters); VerifyProfileCreated(profile, createParameters); // Create a premium verizon cdn profile profileName = TestUtilities.GenerateName("profile"); createParameters = new Profile { Location = "EastUs", Sku = new Sku { Name = SkuName.PremiumVerizon }, Tags = new Dictionary <string, string> { { "key7", "value7" }, { "key8", "value8" } } }; profile = cdnMgmtClient.Profiles.Create(resourceGroupName, profileName, createParameters); VerifyProfileCreated(profile, createParameters); // Create profile with same name but different params should fail createParameters = new Profile { Location = "WestUs", Sku = new Sku { Name = SkuName.StandardVerizon }, Tags = new Dictionary <string, string>() }; Assert.ThrowsAny <ErrorResponseException>(() => { cdnMgmtClient.Profiles.Create(resourceGroupName, profileName, createParameters); }); // Delete resource group CdnTestUtilities.DeleteResourceGroup(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); } } }
public void EndpointCheckNameAvailabilityTest() { var handler1 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; var handler2 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; using (MockContext context = MockContext.Start(this.GetType().FullName)) { // Create clients var cdnMgmtClient = CdnTestUtilities.GetCdnManagementClient(context, handler1); var resourcesClient = CdnTestUtilities.GetResourceManagementClient(context, handler2); // Generate new endpoint name string endpointName = TestUtilities.GenerateName("endpoint-unique"); // CheckNameAvailability should return true var output = cdnMgmtClient.NameAvailability.CheckNameAvailability(endpointName, ResourceType.MicrosoftCdnProfilesEndpoints); Assert.Equal(output.NameAvailable, true); // Create endpoint with that name then CheckNameAvailability again // Create resource group var resourceGroupName = CdnTestUtilities.CreateResourceGroup(resourcesClient); // Create a standard cdn profile string profileName = TestUtilities.GenerateName("profile"); ProfileCreateParameters createParameters = new ProfileCreateParameters { Location = "WestUs", Sku = new Sku { Name = SkuName.StandardVerizon }, Tags = new Dictionary <string, string> { { "key1", "value1" }, { "key2", "value2" } } }; var profile = cdnMgmtClient.Profiles.Create(profileName, createParameters, resourceGroupName); // Create endpoint with this name var endpointCreateParameters = new EndpointCreateParameters { Location = "WestUs", IsHttpAllowed = true, IsHttpsAllowed = true, Origins = new List <DeepCreatedOrigin> { new DeepCreatedOrigin { Name = "origin1", HostName = "host1.hello.com" } } }; var endpoint = cdnMgmtClient.Endpoints.Create(endpointName, endpointCreateParameters, profileName, resourceGroupName); // CheckNameAvailability after endpoint was created should return false output = cdnMgmtClient.NameAvailability.CheckNameAvailability(endpointName, ResourceType.MicrosoftCdnProfilesEndpoints); Assert.Equal(output.NameAvailable, false); // Delete resource group CdnTestUtilities.DeleteResourceGroup(resourcesClient, resourceGroupName); } }
public void OriginGetListTest() { 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); // Create a standard cdn profile string profileName = TestUtilities.GenerateName("profile"); Profile createParameters = new Profile { Location = "WestUs", Sku = new Sku { Name = SkuName.StandardVerizon }, Tags = new Dictionary <string, string> { { "key1", "value1" }, { "key2", "value2" } } }; var profile = cdnMgmtClient.Profiles.Create(resourceGroupName, profileName, createParameters); // Create a cdn endpoint with minimum requirements string endpointName = TestUtilities.GenerateName("endpoint"); var endpointCreateParameters = new Endpoint { Location = "WestUs", IsHttpAllowed = true, IsHttpsAllowed = true, Origins = new List <DeepCreatedOrigin> { new DeepCreatedOrigin { Name = "origin1", HostName = "host1.hello.com" } } }; var endpoint = cdnMgmtClient.Endpoints.Create(resourceGroupName, profileName, endpointName, endpointCreateParameters); // Get origin on endpoint should return the deep created origin var origin = cdnMgmtClient.Origins.Get(resourceGroupName, profileName, endpointName, "origin1"); Assert.NotNull(origin); // Get origins on endpoint should return one var origins = cdnMgmtClient.Origins.ListByEndpoint(resourceGroupName, profileName, endpointName); Assert.Single(origins); // Delete resource group CdnTestUtilities.DeleteResourceGroup(resourcesClient, resourceGroupName); } }
public void OriginUpdateTest() { 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); // Create a standard cdn profile string profileName = TestUtilities.GenerateName("profile"); Profile createParameters = new Profile { Location = "WestUs", Sku = new Sku { Name = SkuName.StandardMicrosoft }, Tags = new Dictionary <string, string> { { "key1", "value1" }, { "key2", "value2" } } }; var profile = cdnMgmtClient.Profiles.Create(resourceGroupName, profileName, createParameters); // Create a cdn endpoint with minimum requirements var endpointName = TestUtilities.GenerateName("endpoint"); var originGroupName = "origingroup1"; var originName = "origin1"; var endpointCreateParameters = new Endpoint { Location = "WestUs", IsHttpAllowed = true, IsHttpsAllowed = true, Origins = new List <DeepCreatedOrigin> { new DeepCreatedOrigin { Name = originName, HostName = "host1.hello.com", Priority = 5, Weight = 100, PrivateLinkLocation = "EastUS", PrivateLinkResourceId = "/subscriptions/da61bba1-cbd5-438c-a738-c717a6b2d59f/resourceGroups/moeidrg/providers/Microsoft.Network/privateLinkServices/pls-east-3", PrivateLinkApprovalMessage = "This is a test request", } }, OriginGroups = new List <DeepCreatedOriginGroup> { new DeepCreatedOriginGroup { Name = originGroupName, HealthProbeSettings = new HealthProbeParameters { ProbeIntervalInSeconds = 60, ProbePath = "/healthz", ProbeProtocol = ProbeProtocol.Https, ProbeRequestType = HealthProbeRequestType.HEAD, }, Origins = new List <ResourceReference> { new ResourceReference { Id = $"{profile.Id}/endpoints/{endpointName}/origins/{originName}" } }, } }, DefaultOriginGroup = new ResourceReference { Id = $"{profile.Id}/endpoints/{endpointName}/originGroups/{originGroupName}" } }; var endpoint = cdnMgmtClient.Endpoints.Create(resourceGroupName, profileName, endpointName, endpointCreateParameters); // Update origin on running endpoint should succeed var originParameters = new OriginUpdateParameters { HostName = "www.bing.com", HttpPort = 1234, HttpsPort = 8081, PrivateLinkLocation = "EastUS", PrivateLinkResourceId = "/subscriptions/da61bba1-cbd5-438c-a738-c717a6b2d59f/resourceGroups/moeidrg/providers/Microsoft.Network/privateLinkServices/pls-east-2", PrivateLinkApprovalMessage = "This is a test update request", }; cdnMgmtClient.Origins.Update(resourceGroupName, profileName, endpointName, "origin1", originParameters); // Update origin with invalid hostname should fail originParameters = new OriginUpdateParameters { HostName = "invalid!Hostname&", HttpPort = 1234, HttpsPort = 8081 }; Assert.ThrowsAny <ErrorResponseException>(() => { cdnMgmtClient.Origins.Update(resourceGroupName, profileName, endpointName, "origin1", originParameters); }); // Stop endpoint should succeed cdnMgmtClient.Endpoints.Stop(resourceGroupName, profileName, endpointName); // Update origin on stopped endpoint should succeed originParameters = new OriginUpdateParameters { HostName = "www.hello.com", HttpPort = 1265 }; cdnMgmtClient.Origins.Update(resourceGroupName, profileName, endpointName, "origin1", originParameters); // Update origin with invalid ports should fail originParameters = new OriginUpdateParameters { HttpPort = 99999, HttpsPort = -2000 }; Assert.ThrowsAny <ErrorResponseException>(() => { cdnMgmtClient.Origins.Update(resourceGroupName, profileName, endpointName, "origin1", originParameters); }); // Delete resource group CdnTestUtilities.DeleteResourceGroup(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 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 CustomDomainCRUDTest() { var handler1 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; var handler2 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; using (MockContext context = MockContext.Start(this.GetType().FullName)) { // Create clients var cdnMgmtClient = CdnTestUtilities.GetCdnManagementClient(context, handler1); var resourcesClient = CdnTestUtilities.GetResourceManagementClient(context, handler2); // Create resource group var resourceGroupName = CdnTestUtilities.CreateResourceGroup(resourcesClient); // Create a standard cdn profile string profileName = TestUtilities.GenerateName("profile"); Profile createParameters = new Profile { Location = "WestUs", Sku = new Sku { Name = SkuName.StandardMicrosoft }, Tags = new Dictionary <string, string> { { "key1", "value1" }, { "key2", "value2" } } }; var profile = cdnMgmtClient.Profiles.Create(resourceGroupName, profileName, createParameters); // Create a cdn endpoint with minimum requirements string endpointName = "endpoint-f3757d2a3e10"; var endpointCreateParameters = new Endpoint { Location = "WestUs", IsHttpAllowed = true, IsHttpsAllowed = true, Origins = new List <DeepCreatedOrigin> { new DeepCreatedOrigin { Name = "origin1", HostName = "host1.hello.com" } } }; var endpoint = cdnMgmtClient.Endpoints.Create(resourceGroupName, profileName, endpointName, endpointCreateParameters); // List custom domains one this endpoint should return none var customDomains = cdnMgmtClient.CustomDomains.ListByEndpoint(resourceGroupName, profileName, endpointName); Assert.Empty(customDomains); // NOTE: There is a CName mapping already created for this custom domain and endpoint hostname // "sdk-1-f3757d2a3e10.DUSTYDOGPETCARE.US" maps to "endpoint-f3757d2a3e10.azureedge.net" // "sdk-2-f3757d2a3e10.DUSTYDOGPETCARE.US" maps to "endpoint-f3757d2a3e10.azureedge.net" // Create custom domain on running endpoint should succeed string customDomainName1 = TestUtilities.GenerateName("customDomain"); cdnMgmtClient.CustomDomains.Create(resourceGroupName, profileName, endpointName, customDomainName1, "sdk-1-f3757d2a3e10.DUSTYDOGPETCARE.US"); // List custom domains one this endpoint should return one customDomains = cdnMgmtClient.CustomDomains.ListByEndpoint(resourceGroupName, profileName, endpointName); Assert.Single(customDomains); // Stop endpoint cdnMgmtClient.Endpoints.Stop(resourceGroupName, profileName, endpointName); // Create another custom domain on stopped endpoint should succeed string customDomainName2 = TestUtilities.GenerateName("customDomain"); cdnMgmtClient.CustomDomains.Create(resourceGroupName, profileName, endpointName, customDomainName2, "sdk-2-f3757d2a3e10.DUSTYDOGPETCARE.US"); // List custom domains one this endpoint should return two customDomains = cdnMgmtClient.CustomDomains.ListByEndpoint(resourceGroupName, profileName, endpointName); Assert.Equal(2, customDomains.Count()); // Disable custom https on custom domain that is not enabled should fail Assert.ThrowsAny <ErrorResponseException>(() => { cdnMgmtClient.CustomDomains.DisableCustomHttps(resourceGroupName, profileName, endpointName, customDomainName2); }); // Delete second custom domain on stopped endpoint should succeed cdnMgmtClient.CustomDomains.Delete(resourceGroupName, profileName, endpointName, customDomainName2); // Get deleted custom domain should fail Assert.ThrowsAny <ErrorResponseException>(() => { cdnMgmtClient.CustomDomains.Get(resourceGroupName, profileName, endpointName, customDomainName2); }); // List custom domains on endpoint should return one customDomains = cdnMgmtClient.CustomDomains.ListByEndpoint(resourceGroupName, profileName, endpointName); Assert.Single(customDomains); // Start endpoint cdnMgmtClient.Endpoints.Start(resourceGroupName, profileName, endpointName); // Enable custom https using CDN managed certificate on custom domain cdnMgmtClient.CustomDomains.EnableCustomHttps(resourceGroupName, profileName, endpointName, customDomainName1); // add the same deleted custom domain again cdnMgmtClient.CustomDomains.Create(resourceGroupName, profileName, endpointName, customDomainName2, "sdk-2-f3757d2a3e10.DUSTYDOGPETCARE.US"); // Enable custom https using BYOC on custom domain var byocParameters = new KeyVaultCertificateSourceParameters() { ResourceGroupName = "byoc", SecretName = "CdnSDKE2EBYOCTest", SecretVersion = "526c5d25cc1a46a5bb85ce85ee2b89cc", SubscriptionId = "3c0124f9-e564-4c42-86f7-fa79457aedc3", VaultName = "Azure-CDN-BYOC" }; cdnMgmtClient.CustomDomains.EnableCustomHttps(resourceGroupName, profileName, endpointName, customDomainName2, new UserManagedHttpsParameters(ProtocolType.ServerNameIndication, byocParameters)); // Delete first custom domain should succeed cdnMgmtClient.CustomDomains.Delete(resourceGroupName, profileName, endpointName, customDomainName1); // Get deleted custom domain should fail Assert.ThrowsAny <ErrorResponseException>(() => { cdnMgmtClient.CustomDomains.Get(resourceGroupName, profileName, endpointName, customDomainName1); }); // Delete second custom domain should succeed cdnMgmtClient.CustomDomains.Delete(resourceGroupName, profileName, endpointName, customDomainName2); // Get deleted custom domain should fail Assert.ThrowsAny <ErrorResponseException>(() => { cdnMgmtClient.CustomDomains.Get(resourceGroupName, profileName, endpointName, customDomainName2); }); // List custom domains on endpoint should return none customDomains = cdnMgmtClient.CustomDomains.ListByEndpoint(resourceGroupName, profileName, endpointName); Assert.Empty(customDomains); // Delete resource group CdnTestUtilities.DeleteResourceGroup(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); } } }