github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/acceptance/openstack/waf-premium/v1/policy_test.go (about) 1 package v1 2 3 import ( 4 "os" 5 "testing" 6 7 "github.com/opentelekomcloud/gophertelekomcloud/acceptance/clients" 8 "github.com/opentelekomcloud/gophertelekomcloud/acceptance/tools" 9 "github.com/opentelekomcloud/gophertelekomcloud/openstack/common/pointerto" 10 "github.com/opentelekomcloud/gophertelekomcloud/openstack/waf-premium/v1/policies" 11 th "github.com/opentelekomcloud/gophertelekomcloud/testhelper" 12 ) 13 14 func TestWafPremiumPolicyWorkflow(t *testing.T) { 15 region := os.Getenv("OS_REGION_NAME") 16 vpcID := os.Getenv("OS_VPC_ID") 17 if vpcID == "" && region == "" { 18 t.Skip("OS_REGION_NAME, OS_VPC_ID env vars is required for this test") 19 } 20 21 client, err := clients.NewWafdV1Client() 22 th.AssertNoErr(t, err) 23 24 policyName := tools.RandomString("waf-policy-", 3) 25 opts := policies.CreateOpts{ 26 Name: policyName, 27 } 28 policy, err := policies.Create(client, opts) 29 th.AssertNoErr(t, err) 30 th.AssertEquals(t, policy.Name, policyName) 31 th.AssertEquals(t, policy.Action.Category, "log") 32 th.AssertEquals(t, policy.Level, 2) 33 th.AssertEquals(t, *policy.Options.WebAttack, true) 34 th.AssertEquals(t, *policy.Options.Common, true) 35 th.AssertEquals(t, *policy.Options.AntiCrawler, false) 36 th.AssertEquals(t, *policy.Options.CrawlerEngine, false) 37 th.AssertEquals(t, *policy.Options.CrawlerScript, false) 38 th.AssertEquals(t, *policy.Options.CrawlerOther, false) 39 th.AssertEquals(t, *policy.Options.WebShell, false) 40 th.AssertEquals(t, *policy.Options.Cc, true) 41 th.AssertEquals(t, *policy.Options.Custom, true) 42 th.AssertEquals(t, *policy.Options.WhiteblackIp, true) 43 th.AssertEquals(t, *policy.Options.GeoIp, true) 44 th.AssertEquals(t, *policy.Options.Ignore, true) 45 th.AssertEquals(t, *policy.Options.Privacy, true) 46 th.AssertEquals(t, *policy.Options.AntiTamper, true) 47 th.AssertEquals(t, *policy.Options.AntiLeakage, false) 48 th.AssertEquals(t, *policy.Options.FollowedAction, false) 49 th.AssertEquals(t, *policy.Options.BotEnable, true) 50 th.AssertEquals(t, *policy.Options.Crawler, true) 51 th.AssertEquals(t, *policy.Options.Precise, false) 52 53 // Not supported in SWISS 54 // th.AssertEquals(t, *policy.Options.ModulexEnabled, false) 55 // th.AssertEquals(t, *policy.ModulexOptions.GlobalRateEnabled, true) 56 // th.AssertEquals(t, policy.ModulexOptions.GlobalRateMode, "log") 57 // th.AssertEquals(t, *policy.ModulexOptions.PreciseRulesEnabled, true) 58 // th.AssertEquals(t, policy.ModulexOptions.PreciseRulesMode, "log") 59 // th.AssertEquals(t, policy.ModulexOptions.PreciseRulesManagedMode, "auto") 60 // th.AssertEquals(t, policy.ModulexOptions.PreciseRulesAgingMode, "auto") 61 // th.AssertEquals(t, policy.ModulexOptions.PreciseRulesRetention, 600) 62 // th.AssertEquals(t, *policy.ModulexOptions.CcRulesEnabled, true) 63 // th.AssertEquals(t, policy.ModulexOptions.CcRulesMode, "log") 64 // th.AssertEquals(t, policy.ModulexOptions.CcRulesManagedMode, "auto") 65 // th.AssertEquals(t, policy.ModulexOptions.CcRulesAgingMode, "manual") 66 // th.AssertEquals(t, policy.ModulexOptions.CcRulesRetention, 600) 67 68 t.Cleanup(func() { 69 t.Logf("Attempting to delete WAF Premium policy: %s", policy.ID) 70 th.AssertNoErr(t, policies.Delete(client, policy.ID)) 71 t.Logf("Deleted WAF Premium policy: %s", policy.ID) 72 }) 73 74 t.Logf("Attempting to List WAF Premium policy") 75 certificatesList, err := policies.List(client, policies.ListOpts{ 76 Name: policyName, 77 }) 78 th.AssertNoErr(t, err) 79 80 if len(certificatesList) < 1 { 81 t.Fatal("empty WAF Premium policy list") 82 } 83 84 t.Logf("Attempting to Get WAF Premium policy: %s", policy.ID) 85 p, err := policies.Get(client, policy.ID) 86 th.AssertNoErr(t, err) 87 th.AssertEquals(t, p.ID, policy.ID) 88 89 t.Logf("Attempting to Update WAF Premium policy: %s", policy.ID) 90 updateOpts := policies.UpdateOpts{ 91 Name: policyName + "-updated", 92 Action: &policies.PolicyAction{ 93 Category: "block", 94 }, 95 Options: &policies.PolicyOption{ 96 WebAttack: pointerto.Bool(false), 97 }, 98 Level: 1, 99 FullDetection: pointerto.Bool(true), 100 } 101 updated, err := policies.Update(client, policy.ID, updateOpts) 102 th.AssertNoErr(t, err) 103 th.AssertEquals(t, updated.Level, 1) 104 th.AssertEquals(t, *updated.FullDetection, true) 105 th.AssertEquals(t, updated.Action.Category, "block") 106 th.AssertEquals(t, *updated.Options.WebAttack, false) 107 }