github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/acceptance/openstack/waf/v1/ccattackprotection_rules_test.go (about) 1 package v1 2 3 import ( 4 "testing" 5 6 golangsdk "github.com/opentelekomcloud/gophertelekomcloud" 7 "github.com/opentelekomcloud/gophertelekomcloud/acceptance/clients" 8 rules "github.com/opentelekomcloud/gophertelekomcloud/openstack/waf/v1/ccattackprotection_rules" 9 "github.com/opentelekomcloud/gophertelekomcloud/openstack/waf/v1/policies" 10 th "github.com/opentelekomcloud/gophertelekomcloud/testhelper" 11 ) 12 13 func TestCCAttackProtectionRuleWorkflow(t *testing.T) { 14 client, err := clients.NewWafV1Client() 15 th.AssertNoErr(t, err) 16 17 pID := prepareAndRemovePolicy(t, client) 18 opts := rules.CreateOpts{ 19 Path: "/admin*", 20 LimitNum: golangsdk.IntToPointer(2), 21 LimitPeriod: golangsdk.IntToPointer(30), 22 LockTime: golangsdk.IntToPointer(1200), 23 TagType: "cookie", 24 TagIndex: "sessionid", 25 TagCondition: rules.TagCondition{ 26 Category: "Referer", 27 Contents: []string{"http://www.example.com/path"}, 28 }, 29 Action: rules.Action{ 30 Category: "block", 31 Detail: rules.Detail{ 32 Response: rules.Response{ 33 ContentType: "application/json", 34 Content: `{"error":"forbidden"}`, 35 }, 36 }, 37 }, 38 } 39 r, err := rules.Create(client, pID, opts).Extract() 40 th.AssertNoErr(t, err) 41 t.Cleanup(func() { 42 th.AssertNoErr(t, rules.Delete(client, pID, r.Id).ExtractErr()) 43 }) 44 45 th.AssertEquals(t, r.PolicyID, pID) 46 } 47 48 func prepareAndRemovePolicy(t *testing.T, client *golangsdk.ServiceClient) string { 49 p := preparePolicy(t, client) 50 t.Cleanup(func() { 51 th.AssertNoErr(t, policies.Delete(client, p.Id).ExtractErr()) 52 }) 53 return p.Id 54 }