예제 #1
0
        public void ProfileListBySubcriptionTest()
        {
            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 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);

                // 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.Equal(existingProfileCount + 2, profiles.Count());

                // Delete first profile
                cdnMgmtClient.Profiles.Delete(resourceGroupName1, profileName);

                // List profiles should return initial profile count + 1
                profiles = cdnMgmtClient.Profiles.List();
                Assert.Equal(existingProfileCount + 1, profiles.Count());

                // Delete second profile
                cdnMgmtClient.Profiles.Delete(resourceGroupName2, profileName2);

                // List profiles should return initial profile count
                profiles = cdnMgmtClient.Profiles.List();
                Assert.Equal(existingProfileCount, profiles.Count());

                // Delete resource groups
                CdnTestUtilities.DeleteResourceGroup(resourcesClient, resourceGroupName1);
                CdnTestUtilities.DeleteResourceGroup(resourcesClient, resourceGroupName2);
            }
        }
예제 #2
0
        public void GenerateSsoUriTest()
        {
            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.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);
            }
        }
예제 #3
0
        public void OriginGetListTest()
        {
            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             = TestUtilities.GenerateName("endpoint");
                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);

                // Get origin on endpoint should return the deep created origin
                var origin = cdnMgmtClient.Origins.Get("origin1", endpointName, profileName, resourceGroupName);
                Assert.NotNull(origin);

                // Get origins on endpoint should return one
                var origins = cdnMgmtClient.Origins.ListByEndpoint(endpointName, profileName, resourceGroupName);
                Assert.Equal(1, origins.Count());

                // Delete resource group
                CdnTestUtilities.DeleteResourceGroup(resourcesClient, resourceGroupName);
            }
        }
예제 #4
0
        public void ProfileGetListTest()
        {
            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);

                // 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);
            }
        }
예제 #5
0
        public void WafPolicyLinkTest()
        {
            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 cdn waf policy
                var policyName = TestUtilities.GenerateName("policy");
                var policy     = cdnMgmtClient.Policies.CreateOrUpdate(resourceGroupName, policyName, new CdnWebApplicationFirewallPolicy
                {
                    Location       = "Global",
                    Sku            = new Sku("Standard_Microsoft"),
                    PolicySettings = new PolicySettings
                    {
                        EnabledState = "Enabled",
                        Mode         = "Detection",
                        DefaultCustomBlockResponseBody       = "PGh0bWw+PGJvZHk+PGgzPkludmFsaWQgcmVxdWVzdDwvaDM+PC9ib2R5PjwvaHRtbD4=",
                        DefaultRedirectUrl                   = "https://example.com/redirected",
                        DefaultCustomBlockResponseStatusCode = 406
                    },
                    CustomRules = new CustomRuleList(new List <CustomRule>
                    {
                        new CustomRule {
                            Name            = "CustomRule1",
                            Priority        = 2,
                            EnabledState    = "Enabled",
                            Action          = "Block",
                            MatchConditions = new List <MatchCondition>
                            {
                                new MatchCondition {
                                    MatchVariable    = "QueryString",
                                    OperatorProperty = "Contains",
                                    NegateCondition  = false,
                                    MatchValue       = new List <string> {
                                        "TestTrigger123"
                                    },
                                    //Transforms = new List<String> { "Uppercase" }
                                }
                            }
                        }
                    }),
                    RateLimitRules = new RateLimitRuleList(new List <RateLimitRule>
                    {
                        new RateLimitRule {
                            Name         = "RateLimitRule1",
                            Priority     = 1,
                            EnabledState = "Disabled",
                            RateLimitDurationInMinutes = 1,
                            RateLimitThreshold         = 3,
                            MatchConditions            = new List <MatchCondition> {
                                new MatchCondition {
                                    MatchVariable    = "RemoteAddr",
                                    Selector         = null,
                                    OperatorProperty = "IPMatch",
                                    NegateCondition  = false,
                                    MatchValue       = new List <string> {
                                        "131.107.0.0/16",
                                        "167.220.0.0/16"
                                    }
                                }
                            },
                            Action = "Block"
                        },
                        new RateLimitRule {
                            Name         = "RateLimitRule2",
                            Priority     = 10,
                            EnabledState = "Enabled",
                            RateLimitDurationInMinutes = 1,
                            RateLimitThreshold         = 1,
                            MatchConditions            = new List <MatchCondition> {
                                new MatchCondition {
                                    MatchVariable    = "RequestUri",
                                    Selector         = null,
                                    OperatorProperty = "Contains",
                                    NegateCondition  = false,
                                    MatchValue       = new List <string> {
                                        "yes"
                                    }
                                }
                            },
                            Action = "Block"
                        }
                    }),
                    ManagedRules = new ManagedRuleSetList(new List <ManagedRuleSet>
                    {
                        new ManagedRuleSet {
                            RuleSetType        = "DefaultRuleSet",
                            RuleSetVersion     = "1.0",
                            RuleGroupOverrides = new List <ManagedRuleGroupOverride> {
                                new ManagedRuleGroupOverride {
                                    RuleGroupName = "JAVA",
                                    Rules         = new List <ManagedRuleOverride> {
                                        new ManagedRuleOverride {
                                            RuleId       = "944100",
                                            EnabledState = "Disabled",
                                            Action       = "Redirect"
                                        }
                                    }
                                }
                            }
                        }
                    }),
                    Tags = new Dictionary <string, string>
                    {
                        { "abc", "123" }
                    }
                });

                // Create a standard Microsoft 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" }
                    }
                };

                // Wait for policy to complete creation
                CdnTestUtilities.WaitIfNotInPlaybackMode();

                var profile = cdnMgmtClient.Profiles.Create(resourceGroupName, profileName, createParameters);

                // Create a cdn endpoint with waf link should succeed
                string endpointName = TestUtilities.GenerateName("endpoint");
                var    endpoint     = cdnMgmtClient.Endpoints.Create(resourceGroupName, profileName, endpointName, new Endpoint
                {
                    Location       = "WestUs",
                    IsHttpAllowed  = true,
                    IsHttpsAllowed = true,
                    WebApplicationFirewallPolicyLink = new EndpointPropertiesUpdateParametersWebApplicationFirewallPolicyLink(policy.Id.ToString()),
                    Origins = new List <DeepCreatedOrigin>
                    {
                        new DeepCreatedOrigin
                        {
                            Name     = "origin1",
                            HostName = "host1.hello.com"
                        }
                    }
                });

                // Verify linked endpoint
                var existingEndpoint = cdnMgmtClient.Endpoints.Get(resourceGroupName, profileName, endpointName);
                Assert.Equal(policy.Id.ToString(), existingEndpoint.WebApplicationFirewallPolicyLink.Id);

                // Verify policy shows linked endpoint
                var existingPolicy = cdnMgmtClient.Policies.Get(resourceGroupName, policyName);
                Assert.Single(existingPolicy.EndpointLinks);
                Assert.Contains(endpoint.Id, existingPolicy.EndpointLinks.Select(l => l.Id));

                // Create second endpoint linked to the same profile should succeed
                var endpoint2Name = TestUtilities.GenerateName("endpoint");
                var endpoint2     = cdnMgmtClient.Endpoints.Create(resourceGroupName, profileName, endpoint2Name, new Endpoint
                {
                    Location       = "EastUs",
                    IsHttpAllowed  = false,
                    IsHttpsAllowed = true,
                    WebApplicationFirewallPolicyLink = new EndpointPropertiesUpdateParametersWebApplicationFirewallPolicyLink(policy.Id.ToString()),
                    Origins = new List <DeepCreatedOrigin>
                    {
                        new DeepCreatedOrigin
                        {
                            Name     = "origin2",
                            HostName = "host2.hello.com"
                        }
                    }
                });

                // Verify second linked endpoint
                var existingEndpoint2 = cdnMgmtClient.Endpoints.Get(resourceGroupName, profileName, endpoint2Name);
                Assert.Equal(policy.Id.ToString(), existingEndpoint2.WebApplicationFirewallPolicyLink.Id);

                // Verify policy shows both linked endpoints.
                existingPolicy = cdnMgmtClient.Policies.Get(resourceGroupName, policyName);
                Assert.Equal(2, existingPolicy.EndpointLinks.Count());
                Assert.Contains(endpoint.Id, existingPolicy.EndpointLinks.Select(l => l.Id));
                Assert.Contains(endpoint2.Id, existingPolicy.EndpointLinks.Select(l => l.Id));

                // Unlink endpoint should succeed.
                endpoint.WebApplicationFirewallPolicyLink = null;
                endpoint = cdnMgmtClient.Endpoints.Create(resourceGroupName, profileName, endpointName, endpoint);
                Assert.Null(endpoint.WebApplicationFirewallPolicyLink);

                // Verify policy shows only second linked endpoint.
                existingPolicy = cdnMgmtClient.Policies.Get(resourceGroupName, policyName);
                Assert.Single(existingPolicy.EndpointLinks);
                Assert.Contains(endpoint2.Id, existingPolicy.EndpointLinks.Select(l => l.Id));

                // Unlink second endpoint should succeed
                endpoint2.WebApplicationFirewallPolicyLink = null;
                endpoint2 = cdnMgmtClient.Endpoints.Create(resourceGroupName, profileName, endpoint2Name, endpoint2);
                Assert.Null(endpoint2.WebApplicationFirewallPolicyLink);

                // Verify policy shows no linked endpoints
                existingPolicy = cdnMgmtClient.Policies.Get(resourceGroupName, policyName);
                Assert.Empty(existingPolicy.EndpointLinks);

                // Delete resource group
                CdnTestUtilities.DeleteResourceGroup(resourcesClient, resourceGroupName);
            }
        }
예제 #6
0
        public void OriginCreateTest()
        {
            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 one origin should succeed
                string endpointName             = TestUtilities.GenerateName("endpoint");
                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);

                // Create another origin on this endpoint should fail
                string originName       = TestUtilities.GenerateName("origin1");
                var    originParameters = new OriginParameters
                {
                    HostName  = "host1.hello.com",
                    HttpPort  = 9874,
                    HttpsPort = 9090
                };

                Assert.ThrowsAny <ErrorResponseException>(() =>
                {
                    cdnMgmtClient.Origins.Create(originName, originParameters, endpointName, profileName, resourceGroupName);
                });

                // Create a cdn endpoint with invalid ports on origin should fail
                endpointName             = TestUtilities.GenerateName("endpoint");
                endpointCreateParameters = new EndpointCreateParameters
                {
                    Location       = "WestUs",
                    IsHttpAllowed  = true,
                    IsHttpsAllowed = true,
                    Origins        = new List <DeepCreatedOrigin>
                    {
                        new DeepCreatedOrigin
                        {
                            Name      = "origin1",
                            HostName  = "host1.hello.com",
                            HttpPort  = 99999,
                            HttpsPort = -1111
                        }
                    }
                };

                Assert.ThrowsAny <ErrorResponseException>(() =>
                {
                    cdnMgmtClient.Origins.Create(originName, originParameters, endpointName, profileName, resourceGroupName);
                });

                // Delete resource group
                CdnTestUtilities.DeleteResourceGroup(resourcesClient, resourceGroupName);
            }
        }
예제 #7
0
        public void EndpointPurgeLoadTest()
        {
            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 should succeed
                string endpointName             = TestUtilities.GenerateName("endpoint");
                var    endpointCreateParameters = new EndpointCreateParameters
                {
                    Location                   = "WestUs",
                    IsHttpAllowed              = true,
                    IsHttpsAllowed             = true,
                    IsCompressionEnabled       = true,
                    OriginHostHeader           = "www.bing.com",
                    OriginPath                 = "/photos",
                    QueryStringCachingBehavior = QueryStringCachingBehavior.IgnoreQueryString,
                    ContentTypesToCompress     = new List <string> {
                        "text/html", "text/css"
                    },
                    Tags = new Dictionary <string, string> {
                        { "kay1", "value1" }
                    },
                    Origins = new List <DeepCreatedOrigin>
                    {
                        new DeepCreatedOrigin
                        {
                            Name     = TestUtilities.GenerateName("origin"),
                            HostName = "custom.hello.com"
                        }
                    }
                };

                cdnMgmtClient.Endpoints.Create(endpointName, endpointCreateParameters, profileName, resourceGroupName);

                // Purge content on endpoint should succeed
                var purgeContentPaths = new List <string>
                {
                    "/movies/*",
                    "/pictures/pic1.jpg"
                };
                cdnMgmtClient.Endpoints.PurgeContent(endpointName, profileName, resourceGroupName, purgeContentPaths);

                // Purge content on non-existing endpoint should fail
                Assert.Throws <ErrorResponseException>(() => {
                    cdnMgmtClient.Endpoints.PurgeContent("fakeEndpoint", profileName, resourceGroupName, purgeContentPaths);
                });

                // Purge content on endpoint with invalid content paths should fail
                var invalidPurgeContentPaths = new List <string> {
                    "invalidpath!"
                };
                Assert.Throws <ErrorResponseException>(() => {
                    cdnMgmtClient.Endpoints.PurgeContent(endpointName, profileName, resourceGroupName, invalidPurgeContentPaths);
                });

                // Load content on endpoint should succeed
                var loadContentPaths = new List <string>
                {
                    "/movies/amazing.mp4",
                    "/pictures/pic1.jpg"
                };
                cdnMgmtClient.Endpoints.LoadContent(endpointName, profileName, resourceGroupName, loadContentPaths);

                // Load content on non-existing endpoint should fail
                Assert.Throws <ErrorResponseException>(() => {
                    cdnMgmtClient.Endpoints.LoadContent("fakeEndpoint", profileName, resourceGroupName, loadContentPaths);
                });

                // Load content on endpoint with invalid content paths should fail
                var invalidLoadContentPaths = new List <string> {
                    "/movies/*"
                };
                Assert.Throws <ErrorResponseException>(() => {
                    cdnMgmtClient.Endpoints.LoadContent(endpointName, profileName, resourceGroupName, invalidLoadContentPaths);
                });

                // Stop the running endpoint
                cdnMgmtClient.Endpoints.Stop(endpointName, profileName, resourceGroupName);
                var endpoint = cdnMgmtClient.Endpoints.Get(endpointName, profileName, resourceGroupName);
                Assert.Equal(endpoint.ResourceState, EndpointResourceState.Stopped);

                // Purge content on stopped endpoint should fail
                Assert.Throws <ErrorResponseException>(() => {
                    cdnMgmtClient.Endpoints.PurgeContent(endpointName, profileName, resourceGroupName, purgeContentPaths);
                });

                // Load content on stopped endpoint should fail
                Assert.Throws <ErrorResponseException>(() => {
                    cdnMgmtClient.Endpoints.LoadContent(endpointName, profileName, resourceGroupName, loadContentPaths);
                });

                // Delete resource group
                CdnTestUtilities.DeleteResourceGroup(resourcesClient, resourceGroupName);
            }
        }
예제 #8
0
        public void ProfileUpdateTest()
        {
            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.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);
            }
        }
예제 #9
0
        public void EndpointCreateTest()
        {
            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 should succeed
                string endpointName             = TestUtilities.GenerateName("endpoint");
                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);
                var existingEndpoint = cdnMgmtClient.Endpoints.Get(endpointName, profileName, resourceGroupName);

                // Create endpoint with same name should fail
                endpointCreateParameters = new EndpointCreateParameters
                {
                    Location       = "EastUs",
                    IsHttpAllowed  = false,
                    IsHttpsAllowed = true,
                    Origins        = new List <DeepCreatedOrigin>
                    {
                        new DeepCreatedOrigin
                        {
                            Name     = "origin2",
                            HostName = "host2.hello.com"
                        }
                    }
                };

                Assert.ThrowsAny <ErrorResponseException>(() => {
                    cdnMgmtClient.Endpoints.Create(endpointName, endpointCreateParameters, profileName, resourceGroupName);
                });

                // Create a cdn endpoint with full properties should succeed
                endpointName             = TestUtilities.GenerateName("endpoint");
                endpointCreateParameters = new EndpointCreateParameters
                {
                    Location                   = "WestUs",
                    IsHttpAllowed              = true,
                    IsHttpsAllowed             = true,
                    IsCompressionEnabled       = true,
                    OriginHostHeader           = "www.bing.com",
                    OriginPath                 = "/photos",
                    QueryStringCachingBehavior = QueryStringCachingBehavior.BypassCaching,
                    ContentTypesToCompress     = new List <string> {
                        "text/html", "application/octet-stream"
                    },
                    Tags = new Dictionary <string, string> {
                        { "kay1", "value1" }
                    },
                    Origins = new List <DeepCreatedOrigin>
                    {
                        new DeepCreatedOrigin
                        {
                            Name     = "origin1",
                            HostName = "host1.hello.com"
                        }
                    }
                };

                endpoint = cdnMgmtClient.Endpoints.Create(endpointName, endpointCreateParameters, profileName, resourceGroupName);
                Assert.NotNull(endpoint);

                // Create a cdn endpoint with no origins should fail
                endpointName             = TestUtilities.GenerateName("endpoint");
                endpointCreateParameters = new EndpointCreateParameters
                {
                    Location                   = "WestUs",
                    IsHttpAllowed              = true,
                    IsHttpsAllowed             = true,
                    IsCompressionEnabled       = true,
                    OriginHostHeader           = "www.bing.com",
                    OriginPath                 = "/photos",
                    QueryStringCachingBehavior = QueryStringCachingBehavior.BypassCaching,
                    ContentTypesToCompress     = new List <string> {
                        "text/html", "application/octet-stream"
                    },
                    Tags = new Dictionary <string, string> {
                        { "kay1", "value1" }
                    }
                };

                Assert.ThrowsAny <ValidationException>(() => {
                    cdnMgmtClient.Endpoints.Create(endpointName, endpointCreateParameters, profileName, resourceGroupName);
                });

                // Create a cdn endpoint with both http and https disallowed should fail
                endpointName             = TestUtilities.GenerateName("endpoint");
                endpointCreateParameters = new EndpointCreateParameters
                {
                    Location                   = "WestUs",
                    IsHttpAllowed              = false,
                    IsHttpsAllowed             = false,
                    IsCompressionEnabled       = true,
                    OriginHostHeader           = "www.bing.com",
                    OriginPath                 = "/photos",
                    QueryStringCachingBehavior = QueryStringCachingBehavior.BypassCaching,
                    ContentTypesToCompress     = new List <string> {
                        "text/html", "application/octet-stream"
                    },
                    Tags = new Dictionary <string, string> {
                        { "kay1", "value1" }
                    }
                };

                Assert.ThrowsAny <ValidationException>(() => {
                    cdnMgmtClient.Endpoints.Create(endpointName, endpointCreateParameters, profileName, resourceGroupName);
                });

                // Delete resource group
                CdnTestUtilities.DeleteResourceGroup(resourcesClient, resourceGroupName);
            }
        }
예제 #10
0
        public void EndpointGetListTest()
        {
            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);

                // List endpoints should return none
                var endpoints = cdnMgmtClient.Endpoints.ListByProfile(profileName, resourceGroupName);
                Assert.Equal(0, endpoints.Count());

                // Create a cdn endpoint should succeed
                string endpointName             = TestUtilities.GenerateName("endpoint");
                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);

                // Get endpoint returns the created endpoint
                var existingEndpoint = cdnMgmtClient.Endpoints.Get(endpointName, profileName, resourceGroupName);
                Assert.NotNull(existingEndpoint);
                Assert.Equal(existingEndpoint.ResourceState, EndpointResourceState.Running);

                // List endpoints should return one endpoint
                endpoints = cdnMgmtClient.Endpoints.ListByProfile(profileName, resourceGroupName);
                Assert.Equal(1, endpoints.Count());

                // Create a cdn endpoint and don't wait for creation to finish
                string endpointName2 = TestUtilities.GenerateName("endpoint");
                endpointCreateParameters = new EndpointCreateParameters
                {
                    Location       = "WestUs",
                    IsHttpAllowed  = true,
                    IsHttpsAllowed = true,
                    Origins        = new List <DeepCreatedOrigin>
                    {
                        new DeepCreatedOrigin
                        {
                            Name     = "origin1",
                            HostName = "host1.hello.com"
                        }
                    }
                };

                cdnMgmtClient.Endpoints.BeginCreateAsync(endpointName2, endpointCreateParameters, profileName, resourceGroupName).Wait(5000);

                // List endpoints should return two endpoints
                endpoints = cdnMgmtClient.Endpoints.ListByProfile(profileName, resourceGroupName);
                Assert.Equal(2, endpoints.Count());

                // Delete first endpoint should succeed
                cdnMgmtClient.Endpoints.DeleteIfExists(endpointName, profileName, resourceGroupName);

                // Get deleted endpoint fails
                Assert.ThrowsAny <ErrorResponseException>(() => {
                    cdnMgmtClient.Endpoints.Get(endpointName, profileName, resourceGroupName);
                });

                // List endpoints should return 1 endpoint
                endpoints = cdnMgmtClient.Endpoints.ListByProfile(profileName, resourceGroupName);
                Assert.Equal(1, endpoints.Count());

                // Wait for second endpoint to complete creation
                CdnTestUtilities.WaitIfNotInPlaybackMode();

                // Delete second endpoint but don't wait for operation to complete
                cdnMgmtClient.Endpoints.BeginDeleteIfExistsAsync(endpointName2, profileName, resourceGroupName).Wait(2000);

                // Get second endpoint returns endpoint in Deleting state
                existingEndpoint = cdnMgmtClient.Endpoints.Get(endpointName2, profileName, resourceGroupName);
                Assert.Equal(existingEndpoint.ResourceState, EndpointResourceState.Deleting);

                // Wait for second endpoint deletion to complete
                CdnTestUtilities.WaitIfNotInPlaybackMode();

                // List endpoints should return none
                endpoints = cdnMgmtClient.Endpoints.ListByProfile(profileName, resourceGroupName);
                Assert.Equal(0, endpoints.Count());

                // Delete resource group
                CdnTestUtilities.DeleteResourceGroup(resourcesClient, resourceGroupName);
            }
        }
예제 #11
0
        public void EndpointUpdateTest()
        {
            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 should succeed
                string endpointName             = TestUtilities.GenerateName("endpoint");
                var    endpointCreateParameters = new EndpointCreateParameters
                {
                    Location       = "WestUs",
                    IsHttpAllowed  = true,
                    IsHttpsAllowed = true,
                    Origins        = new List <DeepCreatedOrigin>
                    {
                        new DeepCreatedOrigin
                        {
                            Name     = "origin1",
                            HostName = "host1.hello.com"
                        }
                    }
                };

                cdnMgmtClient.Endpoints.Create(endpointName, endpointCreateParameters, profileName, resourceGroupName);

                // Update endpoint with invalid origin path should fail
                var endpointUpdateParameters = new EndpointUpdateParameters
                {
                    IsHttpAllowed    = false,
                    OriginPath       = "\\&123invalid_path/.",
                    OriginHostHeader = "www.bing.com"
                };

                Assert.ThrowsAny <ErrorResponseException>(() => {
                    cdnMgmtClient.Endpoints.Update(endpointName, endpointUpdateParameters, profileName, resourceGroupName);
                });

                // Update endpoint to enable compression without specifying compression types should fail
                endpointUpdateParameters = new EndpointUpdateParameters
                {
                    IsHttpAllowed              = false,
                    OriginPath                 = "/path/valid",
                    OriginHostHeader           = "www.bing.com",
                    IsCompressionEnabled       = true,
                    QueryStringCachingBehavior = QueryStringCachingBehavior.IgnoreQueryString
                };

                Assert.ThrowsAny <ErrorResponseException>(() => {
                    cdnMgmtClient.Endpoints.Update(endpointName, endpointUpdateParameters, profileName, resourceGroupName);
                });

                // Update endpoint with valid properties should succeed
                endpointUpdateParameters = new EndpointUpdateParameters
                {
                    IsHttpAllowed          = false,
                    OriginPath             = "/path/valid",
                    OriginHostHeader       = "www.bing.com",
                    IsCompressionEnabled   = true,
                    ContentTypesToCompress = new List <string> {
                        "text/html", "application/octet-stream"
                    },
                    QueryStringCachingBehavior = QueryStringCachingBehavior.IgnoreQueryString
                };

                var endpoint = cdnMgmtClient.Endpoints.Update(endpointName, endpointUpdateParameters, profileName, resourceGroupName);

                // Create a cdn endpoint but don't wait for creation to complete
                endpointName             = TestUtilities.GenerateName("endpoint");
                endpointCreateParameters = new EndpointCreateParameters
                {
                    Location       = "WestUs",
                    IsHttpAllowed  = true,
                    IsHttpsAllowed = true,
                    Origins        = new List <DeepCreatedOrigin>
                    {
                        new DeepCreatedOrigin
                        {
                            Name     = "origin1",
                            HostName = "host1.hello.com"
                        }
                    }
                };

                cdnMgmtClient.Endpoints.BeginCreateAsync(endpointName, endpointCreateParameters, profileName, resourceGroupName).Wait(5000);

                // Update endpoint in creating state should fail
                endpointUpdateParameters = new EndpointUpdateParameters
                {
                    IsHttpAllowed    = false,
                    OriginHostHeader = "www.bing.com"
                };

                Assert.ThrowsAny <ErrorResponseException>(() => {
                    cdnMgmtClient.Endpoints.Update(endpointName, endpointUpdateParameters, profileName, resourceGroupName);
                });

                // Delete resource group
                CdnTestUtilities.DeleteResourceGroup(resourcesClient, resourceGroupName);
            }
        }
예제 #12
0
        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.CheckNameAvailability(endpointName);
                Assert.True(output.NameAvailable);

                // 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");
                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 endpoint with this name
                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);

                // CheckNameAvailability after endpoint was created should return false
                output = cdnMgmtClient.CheckNameAvailability(endpointName);
                Assert.False(output.NameAvailable);

                // Delete resource group
                CdnTestUtilities.DeleteResourceGroup(resourcesClient, resourceGroupName);
            }
        }
예제 #13
0
        public void WafPolicyCreateOrUpdateTest()
        {
            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 minimal cdn waf policy should succeed
                var policyName = TestUtilities.GenerateName("policy");
                var policy     = cdnMgmtClient.Policies.CreateOrUpdate(resourceGroupName, policyName, new CdnWebApplicationFirewallPolicy
                {
                    Sku      = new Sku(SkuName.StandardMicrosoft),
                    Location = "Global",
                });
                //Assert.NotNull(policy.Etag);
                Assert.Equal(policyName, policy.Name);
                Assert.Equal($"/subscriptions/{resourcesClient.SubscriptionId}/resourcegroups/{resourceGroupName}/providers/Microsoft.Cdn/cdnwebapplicationfirewallpolicies/{policy.Name}", policy.Id);
                Assert.Equal("Global", policy.Location);
                Assert.Equal(SkuName.StandardMicrosoft, policy.Sku.Name);
                Assert.Equal(ProvisioningState.Succeeded, policy.ProvisioningState);
                Assert.Equal(PolicyResourceState.Enabled, policy.ResourceState);
                Assert.Empty(policy.EndpointLinks);
                Assert.Empty(policy.ManagedRules.ManagedRuleSets);
                Assert.Empty(policy.RateLimitRules.Rules);
                Assert.Empty(policy.CustomRules.Rules);
                Assert.Null(policy.PolicySettings.DefaultCustomBlockResponseBody);
                Assert.Null(policy.PolicySettings.DefaultCustomBlockResponseStatusCode);
                Assert.Null(policy.PolicySettings.DefaultRedirectUrl);
                Assert.Equal(PolicyEnabledState.Enabled, policy.PolicySettings.EnabledState);
                Assert.Equal(PolicyMode.Prevention, policy.PolicySettings.Mode);

                // Update policy with all parameters should succeed
                var expect = new CdnWebApplicationFirewallPolicy
                {
                    Location       = "Global",
                    Sku            = new Sku(SkuName.StandardMicrosoft),
                    PolicySettings = new PolicySettings
                    {
                        EnabledState = "Enabled",
                        Mode         = "Detection",
                        DefaultCustomBlockResponseBody       = "PGh0bWw+PGJvZHk+PGgzPkludmFsaWQgcmVxdWVzdDwvaDM+PC9ib2R5PjwvaHRtbD4=",
                        DefaultRedirectUrl                   = "https://example.com/redirected",
                        DefaultCustomBlockResponseStatusCode = 406
                    },
                    CustomRules = new CustomRuleList(new List <CustomRule>
                    {
                        new CustomRule {
                            Name            = "CustomRule1",
                            Priority        = 2,
                            EnabledState    = "Enabled",
                            Action          = "Block",
                            MatchConditions = new List <MatchCondition>
                            {
                                new MatchCondition {
                                    MatchVariable    = "QueryString",
                                    OperatorProperty = "Contains",
                                    NegateCondition  = false,
                                    MatchValue       = new List <string> {
                                        "TestTrigger123"
                                    },
                                    //Transforms = new List<String> { "Uppercase" }
                                }
                            }
                        }
                    }),
                    RateLimitRules = new RateLimitRuleList(new List <RateLimitRule>
                    {
                        new RateLimitRule {
                            Name         = "RateLimitRule1",
                            Priority     = 1,
                            EnabledState = "Disabled",
                            RateLimitDurationInMinutes = 1,
                            RateLimitThreshold         = 3,
                            MatchConditions            = new List <MatchCondition> {
                                new MatchCondition {
                                    MatchVariable    = "RemoteAddr",
                                    Selector         = null,
                                    OperatorProperty = "IPMatch",
                                    NegateCondition  = false,
                                    MatchValue       = new List <string> {
                                        "131.107.0.0/16",
                                        "167.220.0.0/16"
                                    }
                                }
                            },
                            Action = "Block"
                        },
                        new RateLimitRule {
                            Name         = "RateLimitRule2",
                            Priority     = 10,
                            EnabledState = "Enabled",
                            RateLimitDurationInMinutes = 1,
                            RateLimitThreshold         = 1,
                            MatchConditions            = new List <MatchCondition> {
                                new MatchCondition {
                                    MatchVariable    = "RequestUri",
                                    Selector         = null,
                                    OperatorProperty = "Contains",
                                    NegateCondition  = false,
                                    MatchValue       = new List <string> {
                                        "yes"
                                    }
                                }
                            },
                            Action = "Block"
                        }
                    }),
                    ManagedRules = new ManagedRuleSetList(new List <ManagedRuleSet>
                    {
                        new ManagedRuleSet {
                            RuleSetType        = "DefaultRuleSet",
                            RuleSetVersion     = "1.0",
                            RuleGroupOverrides = new List <ManagedRuleGroupOverride> {
                                new ManagedRuleGroupOverride {
                                    RuleGroupName = "JAVA",
                                    Rules         = new List <ManagedRuleOverride> {
                                        new ManagedRuleOverride {
                                            RuleId       = "944100",
                                            EnabledState = "Disabled",
                                            Action       = "Redirect"
                                        }
                                    }
                                }
                            }
                        }
                    }),
                    Tags = new Dictionary <string, string>
                    {
                        { "abc", "123" }
                    }
                };
                policy = cdnMgmtClient.Policies.CreateOrUpdate(resourceGroupName, policyName, expect);
                AssertPoliciesEqual(resourcesClient.SubscriptionId, resourceGroupName, policyName, new List <CdnEndpoint>(), expect, policy);

                // Create a complete cdn waf policy should succeed
                var policy2Name = TestUtilities.GenerateName("policy");
                var expect2     = new CdnWebApplicationFirewallPolicy
                {
                    Location       = "Global",
                    Sku            = new Sku(SkuName.StandardMicrosoft),
                    PolicySettings = new PolicySettings
                    {
                        EnabledState = "Enabled",
                        Mode         = "Detection",
                        DefaultCustomBlockResponseBody       = "PGh0bWw+PGJvZHk+PGgzPkludmFsaWQgcmVxdWVzdDwvaDM+PC9ib2R5PjwvaHRtbD4=",
                        DefaultRedirectUrl                   = "https://example.com/redirected",
                        DefaultCustomBlockResponseStatusCode = 406
                    },
                    CustomRules = new CustomRuleList(new List <CustomRule>
                    {
                        new CustomRule {
                            Name            = "CustomRule1",
                            Priority        = 2,
                            EnabledState    = "Enabled",
                            Action          = "Block",
                            MatchConditions = new List <MatchCondition>
                            {
                                new MatchCondition {
                                    MatchVariable    = "QueryString",
                                    OperatorProperty = "Contains",
                                    NegateCondition  = false,
                                    MatchValue       = new List <string> {
                                        "TestTrigger123"
                                    },
                                    //Transforms = new List<String> { "Uppercase" }
                                }
                            }
                        }
                    }),
                    RateLimitRules = new RateLimitRuleList(new List <RateLimitRule>
                    {
                        new RateLimitRule {
                            Name         = "RateLimitRule1",
                            Priority     = 1,
                            EnabledState = "Disabled",
                            RateLimitDurationInMinutes = 1,
                            RateLimitThreshold         = 3,
                            MatchConditions            = new List <MatchCondition> {
                                new MatchCondition {
                                    MatchVariable    = "RemoteAddr",
                                    Selector         = null,
                                    OperatorProperty = "IPMatch",
                                    NegateCondition  = false,
                                    MatchValue       = new List <string> {
                                        "131.107.0.0/16",
                                        "167.220.0.0/16"
                                    }
                                }
                            },
                            Action = "Block"
                        },
                        new RateLimitRule {
                            Name         = "RateLimitRule2",
                            Priority     = 10,
                            EnabledState = "Enabled",
                            RateLimitDurationInMinutes = 1,
                            RateLimitThreshold         = 1,
                            MatchConditions            = new List <MatchCondition> {
                                new MatchCondition {
                                    MatchVariable    = "RequestUri",
                                    Selector         = null,
                                    OperatorProperty = "Contains",
                                    NegateCondition  = false,
                                    MatchValue       = new List <string> {
                                        "yes"
                                    }
                                }
                            },
                            Action = "Block"
                        }
                    }),
                    ManagedRules = new ManagedRuleSetList(new List <ManagedRuleSet>
                    {
                        new ManagedRuleSet {
                            RuleSetType        = "DefaultRuleSet",
                            RuleSetVersion     = "1.0",
                            RuleGroupOverrides = new List <ManagedRuleGroupOverride> {
                                new ManagedRuleGroupOverride {
                                    RuleGroupName = "JAVA",
                                    Rules         = new List <ManagedRuleOverride> {
                                        new ManagedRuleOverride {
                                            RuleId       = "944100",
                                            EnabledState = "Disabled",
                                            Action       = "Redirect"
                                        }
                                    }
                                }
                            }
                        }
                    }),
                    Tags = new Dictionary <string, string>
                    {
                        { "abc", "123" }
                    }
                };
                var policy2 = cdnMgmtClient.Policies.CreateOrUpdate(resourceGroupName, policy2Name, expect2);
                AssertPoliciesEqual(resourcesClient.SubscriptionId, resourceGroupName, policy2Name, new List <CdnEndpoint>(), expect2, policy2);
            }
        }
예제 #14
0
        public void ProfileCheckUsageTest()
        {
            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);

                // 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);
            }
        }
예제 #15
0
        public void ValidateCustomDomainTest()
        {
            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-5b4f5e6b9ea6";
                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);

                //NOTE: There is a CName mapping already created for this custom domain and endpoint hostname
                // "customdomain31.azureedge-test.net" maps to "endpoint-5b4f5e6b9ea6.azureedge-test.net"

                // Validate exisiting custom domain should return true
                var output = cdnMgmtClient.Endpoints.ValidateCustomDomain(endpointName, profileName, resourceGroupName, "customdomain31.azureedge-test.net");
                Assert.Equal(output.CustomDomainValidated, true);

                // Validate non-exisiting custom domain should return false
                output = cdnMgmtClient.Endpoints.ValidateCustomDomain(endpointName, profileName, resourceGroupName, "customdomain4.hello.com");
                Assert.Equal(output.CustomDomainValidated, false);

                // Validate invalid custom domain should fail
                Assert.ThrowsAny <ErrorResponseException>(() => {
                    cdnMgmtClient.Endpoints.ValidateCustomDomain(endpointName, profileName, resourceGroupName, "invalid\\custom/domain");
                });

                // Delete resource group
                CdnTestUtilities.DeleteResourceGroup(resourcesClient, resourceGroupName);
            }
        }
예제 #16
0
        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.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             = "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.azureedge-test.net" maps to "endpoint-f3757d2a3e10.azureedge.net"
                // "sdk-2-f3757d2a3e10.azureedge-test.net" 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.azureedge-test.net");

                // 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.azureedge-test.net");

                // List custom domains one this endpoint should return two
                customDomains = cdnMgmtClient.CustomDomains.ListByEndpoint(resourceGroupName, profileName, endpointName);
                Assert.Equal(2, customDomains.Count());

                // Enable custom https on custom domain that is already 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 on custom domain that is already enabled should fail
                cdnMgmtClient.CustomDomains.EnableCustomHttps(resourceGroupName, profileName, endpointName, customDomainName1);

                // Delete first custom domain on stopped endpoint 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);
                });

                // 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 CustomDomainCRUDTest()
        {
            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
                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);
            }
        }
예제 #18
0
        public void ProfileCreateTest()
        {
            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 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);
            }
        }
예제 #19
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);
                }
            }
        }