Example #1
0
        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);
                }
            }
        }
Example #2
0
        private static void VerifyEndpointCreated(string endpointName, AFDEndpoint endpointCreateParameters, AFDEndpoint endpoint)
        {
            Assert.NotNull(endpoint);
            Assert.Equal(endpointName, endpoint.Name);
            Assert.Equal(endpointCreateParameters.EnabledState, endpoint.EnabledState);
            Assert.Equal(endpointCreateParameters.OriginResponseTimeoutSeconds, endpoint.OriginResponseTimeoutSeconds);

            Assert.Equal(endpointCreateParameters.Tags, endpoint.Tags);
        }
Example #3
0
        public void CreateAfdEndpoint()
        {
            try
            {
                AFDEndpoint afdEndpoint = new AFDEndpoint
                {
                    Location = AfdResourceConstants.AfdResourceLocation,
                    Tags     = TagsConversionHelper.CreateTagDictionary(this.Tag, true)
                };

                PSAfdEndpoint psAfdEndpoint = this.CdnManagementClient.AFDEndpoints.Create(this.ResourceGroupName, this.ProfileName, this.EndpointName, afdEndpoint).ToPSAfdEndpoint();

                WriteObject(psAfdEndpoint);
            }
            catch (AfdErrorResponseException errorResponse)
            {
                throw new PSArgumentException(errorResponse.Response.Content);
            }
        }
Example #4
0
        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);
                }
            }
        }
 /// <summary>
 /// Creates a new AzureFrontDoor endpoint with the specified endpoint name
 /// under the specified subscription, resource group and profile.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Name of the Resource group within the Azure subscription.
 /// </param>
 /// <param name='profileName'>
 /// Name of the CDN profile which is unique within the resource group.
 /// </param>
 /// <param name='endpointName'>
 /// Name of the endpoint under the profile which is unique globally.
 /// </param>
 /// <param name='endpoint'>
 /// Endpoint properties
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <AFDEndpoint> BeginCreateAsync(this IAFDEndpointsOperations operations, string resourceGroupName, string profileName, string endpointName, AFDEndpoint endpoint, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.BeginCreateWithHttpMessagesAsync(resourceGroupName, profileName, endpointName, endpoint, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
 /// <summary>
 /// Creates a new AzureFrontDoor endpoint with the specified endpoint name
 /// under the specified subscription, resource group and profile.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Name of the Resource group within the Azure subscription.
 /// </param>
 /// <param name='profileName'>
 /// Name of the CDN profile which is unique within the resource group.
 /// </param>
 /// <param name='endpointName'>
 /// Name of the endpoint under the profile which is unique globally.
 /// </param>
 /// <param name='endpoint'>
 /// Endpoint properties
 /// </param>
 public static AFDEndpoint BeginCreate(this IAFDEndpointsOperations operations, string resourceGroupName, string profileName, string endpointName, AFDEndpoint endpoint)
 {
     return(operations.BeginCreateAsync(resourceGroupName, profileName, endpointName, endpoint).GetAwaiter().GetResult());
 }
        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);
                }
            }
        }
Example #9
0
 private static void VerifyEndpointUpdated(AFDEndpointUpdateParameters endpointUpdateProperties, AFDEndpoint endpoint)
 {
     Assert.NotNull(endpoint);
     Assert.Equal(endpointUpdateProperties.EnabledState, endpoint.EnabledState);
     Assert.Equal(endpointUpdateProperties.OriginResponseTimeoutSeconds, endpoint.OriginResponseTimeoutSeconds);
     Assert.Equal(endpointUpdateProperties.Tags, endpoint.Tags);
 }
        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);
                }
            }
        }
Example #11
0
        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);
                }
            }
        }