public static void AssertValidAfdSecurityPolicy(AfdSecurityPolicyResource model, AfdSecurityPolicyResource getResult)
 {
     Assert.AreEqual(model.Data.Name, getResult.Data.Name);
     Assert.AreEqual(model.Data.Id, getResult.Data.Id);
     Assert.AreEqual(model.Data.ResourceType, getResult.Data.ResourceType);
     Assert.AreEqual(model.Data.ProvisioningState, getResult.Data.ProvisioningState);
     Assert.AreEqual(model.Data.DeploymentStatus, getResult.Data.DeploymentStatus);
     Assert.AreEqual(model.Data.Parameters.PolicyType, getResult.Data.Parameters.PolicyType);
 }
        public async Task Update()
        {
            SubscriptionResource subscription = await Client.GetDefaultSubscriptionAsync();

            ResourceGroupResource rg = await CreateResourceGroup(subscription, "testRg-");

            string          afdProfileName = Recording.GenerateAssetName("AFDProfile-");
            ProfileResource afdProfile     = await CreateAfdProfile(rg, afdProfileName, CdnSkuName.StandardAzureFrontDoor);

            string afdEndpointName1 = Recording.GenerateAssetName("AFDEndpoint-");
            AfdEndpointResource afdEndpointInstance1 = await CreateAfdEndpoint(afdProfile, afdEndpointName1);

            string afdSecurityPolicyName = Recording.GenerateAssetName("AFDSecurityPolicy-");
            AfdSecurityPolicyResource afdSecurityPolicy = await CreateAfdSecurityPolicy(afdProfile, afdEndpointInstance1, afdSecurityPolicyName);

            string afdEndpointName2 = Recording.GenerateAssetName("AFDEndpoint-");
            AfdEndpointResource afdEndpointInstance2 = await CreateAfdEndpoint(afdProfile, afdEndpointName2);

            AfdSecurityPolicyPatch updateOptions = new AfdSecurityPolicyPatch
            {
                Parameters = new SecurityPolicyWebApplicationFirewallDefinition
                {
                    WafPolicy = new WritableSubResource
                    {
                        Id = new ResourceIdentifier("/subscriptions/f3d94233-a9aa-4241-ac82-2dfb63ce637a/resourceGroups/CdnTest/providers/Microsoft.Network/frontdoorWebApplicationFirewallPolicies/testAFDWaf")
                    }
                }
            };
            SecurityPolicyWebApplicationFirewallAssociation securityPolicyWebApplicationFirewallAssociation = new SecurityPolicyWebApplicationFirewallAssociation();

            securityPolicyWebApplicationFirewallAssociation.Domains.Add(new ActivatedResourceReference
            {
                Id = afdEndpointInstance1.Id
            });
            securityPolicyWebApplicationFirewallAssociation.Domains.Add(new ActivatedResourceReference
            {
                Id = afdEndpointInstance2.Id
            });
            securityPolicyWebApplicationFirewallAssociation.PatternsToMatch.Add("/*");
            ((SecurityPolicyWebApplicationFirewallDefinition)updateOptions.Parameters).Associations.Add(securityPolicyWebApplicationFirewallAssociation);
            var lro = await afdSecurityPolicy.UpdateAsync(WaitUntil.Completed, updateOptions);

            AfdSecurityPolicyResource updatedSecurityPolicy = lro.Value;

            ResourceDataHelper.AssertAfdSecurityPolicyUpdate(updatedSecurityPolicy, updateOptions);
        }
Пример #3
0
        public async Task CreateOrUpdate()
        {
            SubscriptionResource subscription = await Client.GetDefaultSubscriptionAsync();

            ResourceGroupResource rg = await CreateResourceGroup(subscription, "testRg-");

            string          afdProfileName = Recording.GenerateAssetName("AFDProfile-");
            ProfileResource afdProfile     = await CreateAfdProfile(rg, afdProfileName, CdnSkuName.StandardAzureFrontDoor);

            string afdEndpointName = Recording.GenerateAssetName("AFDEndpoint-");
            AfdEndpointResource afdEndpointInstance = await CreateAfdEndpoint(afdProfile, afdEndpointName);

            string afdSecurityPolicyName = Recording.GenerateAssetName("AFDSecurityPolicy-");
            AfdSecurityPolicyResource afdSecurityPolicy = await CreateAfdSecurityPolicy(afdProfile, afdEndpointInstance, afdSecurityPolicyName);

            Assert.AreEqual(afdSecurityPolicyName, afdSecurityPolicy.Data.Name);
            Assert.ThrowsAsync <ArgumentNullException>(async() => _ = await afdProfile.GetAfdSecurityPolicies().CreateOrUpdateAsync(WaitUntil.Completed, null, afdSecurityPolicy.Data));
            Assert.ThrowsAsync <ArgumentNullException>(async() => _ = await afdProfile.GetAfdSecurityPolicies().CreateOrUpdateAsync(WaitUntil.Completed, afdSecurityPolicyName, null));
        }
Пример #4
0
        public async Task Get()
        {
            SubscriptionResource subscription = await Client.GetDefaultSubscriptionAsync();

            ResourceGroupResource rg = await CreateResourceGroup(subscription, "testRg-");

            string          afdProfileName = Recording.GenerateAssetName("AFDProfile-");
            ProfileResource afdProfile     = await CreateAfdProfile(rg, afdProfileName, CdnSkuName.StandardAzureFrontDoor);

            string afdEndpointName = Recording.GenerateAssetName("AFDEndpoint-");
            AfdEndpointResource afdEndpointInstance = await CreateAfdEndpoint(afdProfile, afdEndpointName);

            string afdSecurityPolicyName = Recording.GenerateAssetName("AFDSecurityPolicy-");
            AfdSecurityPolicyResource afdSecurityPolicy = await CreateAfdSecurityPolicy(afdProfile, afdEndpointInstance, afdSecurityPolicyName);

            AfdSecurityPolicyResource getAfdSecurityPolicy = await afdProfile.GetAfdSecurityPolicies().GetAsync(afdSecurityPolicyName);

            ResourceDataHelper.AssertValidAfdSecurityPolicy(afdSecurityPolicy, getAfdSecurityPolicy);
            Assert.ThrowsAsync <ArgumentNullException>(async() => _ = await afdProfile.GetAfdSecurityPolicies().GetAsync(null));
        }
        public async Task Delete()
        {
            SubscriptionResource subscription = await Client.GetDefaultSubscriptionAsync();

            ResourceGroupResource rg = await CreateResourceGroup(subscription, "testRg-");

            string          afdProfileName = Recording.GenerateAssetName("AFDProfile-");
            ProfileResource afdProfile     = await CreateAfdProfile(rg, afdProfileName, CdnSkuName.StandardAzureFrontDoor);

            string afdEndpointName = Recording.GenerateAssetName("AFDEndpoint-");
            AfdEndpointResource afdEndpointInstance = await CreateAfdEndpoint(afdProfile, afdEndpointName);

            string afdSecurityPolicyName = Recording.GenerateAssetName("AFDSecurityPolicy-");
            AfdSecurityPolicyResource afdSecurityPolicy = await CreateAfdSecurityPolicy(afdProfile, afdEndpointInstance, afdSecurityPolicyName);

            await afdSecurityPolicy.DeleteAsync(WaitUntil.Completed);

            var ex = Assert.ThrowsAsync <RequestFailedException>(async() => await afdSecurityPolicy.GetAsync());

            Assert.AreEqual(404, ex.Status);
        }
 public static void AssertAfdSecurityPolicyUpdate(AfdSecurityPolicyResource updatedSecurityPolicy, AfdSecurityPolicyPatch updateOptions)
 {
     Assert.AreEqual(((SecurityPolicyWebApplicationFirewallParameters)updatedSecurityPolicy.Data.Parameters).Associations.Count, 1);
     Assert.AreEqual(((SecurityPolicyWebApplicationFirewallParameters)updatedSecurityPolicy.Data.Parameters).Associations[0].Domains.Count, 2);
 }