github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/acceptance/openstack/waf-premium/v1/certificate_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/certificates" 11 "github.com/opentelekomcloud/gophertelekomcloud/openstack/waf-premium/v1/hosts" 12 th "github.com/opentelekomcloud/gophertelekomcloud/testhelper" 13 ) 14 15 func TestWafPremiumCertificateWorkflow(t *testing.T) { 16 region := os.Getenv("OS_REGION_NAME") 17 vpcID := os.Getenv("OS_VPC_ID") 18 if vpcID == "" && region == "" { 19 t.Skip("OS_REGION_NAME, OS_VPC_ID env vars is required for this test") 20 } 21 22 client, err := clients.NewWafdV1Client() 23 th.AssertNoErr(t, err) 24 25 opts := certificates.CreateOpts{ 26 Name: tools.RandomString("waf-certificate-", 3), 27 Content: testCert, 28 Key: testKey, 29 } 30 certificate, err := certificates.Create(client, opts) 31 th.AssertNoErr(t, err) 32 33 t.Cleanup(func() { 34 t.Logf("Attempting to delete WAF Premium certificate: %s", certificate.ID) 35 th.AssertNoErr(t, certificates.Delete(client, certificate.ID)) 36 t.Logf("Deleted WAF Premium certificate: %s", certificate.ID) 37 }) 38 39 t.Logf("Attempting to Get WAF Premium certificate: %s", certificate.ID) 40 c, err := certificates.Get(client, certificate.ID) 41 th.AssertNoErr(t, err) 42 th.AssertEquals(t, c.ID, certificate.ID) 43 44 t.Logf("Attempting to Get WAF Premium host with certificate") 45 server := hosts.PremiumWafServer{ 46 FrontProtocol: "HTTPS", 47 BackProtocol: "HTTPS", 48 Address: "10.10.11.11", 49 Port: 443, 50 Type: "ipv4", 51 VpcId: vpcID, 52 } 53 serverOpts := hosts.CreateOpts{ 54 CertificateId: c.ID, 55 CertificateName: c.Name, 56 Hostname: tools.RandomString("www.waf-demo.com", 3), 57 Proxy: pointerto.Bool(false), 58 Server: []hosts.PremiumWafServer{server}, 59 } 60 h, err := hosts.Create(client, serverOpts) 61 th.AssertNoErr(t, err) 62 t.Logf("Created WAF host: %s", h.ID) 63 64 t.Cleanup(func() { 65 t.Logf("Attempting to delete WAF Premium host: %s", h.ID) 66 th.AssertNoErr(t, hosts.Delete(client, h.ID, hosts.DeleteOpts{})) 67 t.Logf("Deleted WAF Premium host: %s", h.ID) 68 }) 69 70 t.Logf("Attempting to Get WAF Premium certificate with host: %s", certificate.ID) 71 ch, err := certificates.Get(client, certificate.ID) 72 th.AssertNoErr(t, err) 73 th.AssertEquals(t, ch.ID, certificate.ID) 74 th.AssertEquals(t, ch.BoundHosts[0].Hostname, h.Hostname) 75 th.AssertEquals(t, ch.BoundHosts[0].ID, h.ID) 76 77 t.Logf("Attempting to List WAF Premium certificate") 78 certificatesList, err := certificates.List(client, certificates.ListOpts{}) 79 th.AssertNoErr(t, err) 80 81 if len(certificatesList) < 1 { 82 t.Fatal("empty WAF Premium certificate list") 83 } 84 }