github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/acceptance/openstack/apigw/v2/signature_key_test.go (about) 1 package v2 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/apigw/v2/api" 10 "github.com/opentelekomcloud/gophertelekomcloud/openstack/apigw/v2/env" 11 "github.com/opentelekomcloud/gophertelekomcloud/openstack/apigw/v2/group" 12 "github.com/opentelekomcloud/gophertelekomcloud/openstack/apigw/v2/key" 13 th "github.com/opentelekomcloud/gophertelekomcloud/testhelper" 14 ) 15 16 func TestSignatureKeyLifecycle(t *testing.T) { 17 gatewayID := os.Getenv("GATEWAY_ID") 18 19 if gatewayID == "" { 20 t.Skip("`GATEWAY_ID` needs to be defined") 21 } 22 23 client, err := clients.NewAPIGWClient() 24 th.AssertNoErr(t, err) 25 26 name := tools.RandomString("test_sign_key_", 5) 27 28 createOpts := key.CreateOpts{ 29 GatewayID: gatewayID, 30 Name: name, 31 SignType: "aes", 32 SignAlgorithm: "aes-256-cfb", 33 } 34 35 createResp, err := key.Create(client, createOpts) 36 th.AssertNoErr(t, err) 37 38 t.Cleanup(func() { 39 th.AssertNoErr(t, key.Delete(client, gatewayID, createResp.ID)) 40 }) 41 42 updateOpts := key.UpdateOpts{ 43 Name: createOpts.Name, 44 GatewayID: createOpts.GatewayID, 45 SignID: createResp.ID, 46 SignAlgorithm: "aes-128-cfb", 47 SignType: "aes", 48 } 49 50 updateResp, err := key.Update(client, updateOpts) 51 th.AssertNoErr(t, err) 52 53 tools.PrintResource(t, updateResp) 54 } 55 56 func TestSignatureKeyList(t *testing.T) { 57 gatewayID := os.Getenv("GATEWAY_ID") 58 59 if gatewayID == "" { 60 t.Skip("`GATEWAY_ID` needs to be defined") 61 } 62 63 client, err := clients.NewAPIGWClient() 64 th.AssertNoErr(t, err) 65 66 listResp, err := key.List(client, key.ListOpts{ 67 GatewayID: gatewayID, 68 }) 69 th.AssertNoErr(t, err) 70 71 tools.PrintResource(t, listResp) 72 } 73 74 func TestSignatureKeyBinding(t *testing.T) { 75 gatewayID := os.Getenv("GATEWAY_ID") 76 77 if gatewayID == "" { 78 t.Skip("`GATEWAY_ID` needs to be defined") 79 } 80 81 client, err := clients.NewAPIGWClient() 82 th.AssertNoErr(t, err) 83 84 name := tools.RandomString("test_sign_key_", 5) 85 86 createOpts := key.CreateOpts{ 87 GatewayID: gatewayID, 88 Name: name, 89 SignType: "aes", 90 SignAlgorithm: "aes-256-cfb", 91 } 92 93 createResp, err := key.Create(client, createOpts) 94 th.AssertNoErr(t, err) 95 96 t.Cleanup(func() { 97 th.AssertNoErr(t, key.Delete(client, gatewayID, createResp.ID)) 98 }) 99 100 groupResp := CreateGroup(client, t, gatewayID) 101 t.Cleanup(func() { 102 th.AssertNoErr(t, group.Delete(client, gatewayID, groupResp.ID)) 103 }) 104 105 groupID := groupResp.ID 106 107 _, createAPIResp := CreateAPI(client, t, gatewayID, groupID) 108 109 t.Cleanup(func() { 110 th.AssertNoErr(t, api.Delete(client, gatewayID, createAPIResp.ID)) 111 }) 112 113 envResp := CreateEnv(client, t, gatewayID) 114 115 t.Cleanup(func() { 116 manageOpts := api.ManageOpts{ 117 GatewayID: gatewayID, 118 Action: "offline", 119 EnvID: envResp.ID, 120 ApiID: createAPIResp.ID, 121 Description: "test-api-publish", 122 } 123 124 _, err = api.ManageApi(client, manageOpts) 125 th.AssertNoErr(t, err) 126 th.AssertNoErr(t, env.Delete(client, gatewayID, envResp.ID)) 127 }) 128 129 manageOpts := api.ManageOpts{ 130 GatewayID: gatewayID, 131 Action: "online", 132 EnvID: envResp.ID, 133 ApiID: createAPIResp.ID, 134 Description: "test-api-publish", 135 } 136 137 publishAPI, err := api.ManageApi(client, manageOpts) 138 th.AssertNoErr(t, err) 139 140 bindOpts := key.BindOpts{ 141 GatewayID: gatewayID, 142 SignID: createResp.ID, 143 PublishIds: []string{ 144 publishAPI.PublishID, 145 }, 146 } 147 148 bindResp, err := key.BindKey(client, bindOpts) 149 th.AssertNoErr(t, err) 150 151 listBind, err := key.ListBoundKeys(client, key.ListBindingOpts{ 152 GatewayID: gatewayID, 153 ApiID: createAPIResp.ID, 154 }) 155 th.AssertNoErr(t, err) 156 tools.PrintResource(t, listBind) 157 158 listBindAPI, err := key.ListAPIBoundKeys(client, key.ListBoundOpts{ 159 GatewayID: gatewayID, 160 SignID: createResp.ID, 161 }) 162 th.AssertNoErr(t, err) 163 tools.PrintResource(t, listBindAPI) 164 165 th.AssertNoErr(t, key.UnbindKey(client, gatewayID, bindResp[0].ID)) 166 167 listUnbound, err := key.ListUnboundKeys(client, key.ListUnbindOpts{ 168 GatewayID: gatewayID, 169 SignID: createResp.ID, 170 }) 171 th.AssertNoErr(t, err) 172 173 tools.PrintResource(t, listUnbound) 174 175 }