Skip to content
This repository was archived by the owner on Aug 1, 2023. It is now read-only.

Commit 5ed9e9f

Browse files
committed
Don't allow autoscale webhook updates with no metadata
1 parent cd10b15 commit 5ed9e9f

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

rackspace/autoscale/v1/webhooks/requests.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ import (
77
"github.com/rackspace/gophercloud/pagination"
88
)
99

10-
// ErrNoName represents a validation error in which a create or update operation
11-
// has an empty name field.
12-
var ErrNoName = errors.New("Webhook name cannot by empty.")
10+
// Validation errors returned by create or update operations.
11+
var (
12+
ErrNoName = errors.New("Webhook name cannot by empty.")
13+
ErrNoMetadata = errors.New("Webhook metadata cannot be nil.")
14+
)
1315

1416
// List returns all webhooks for a scaling policy.
1517
func List(client *gophercloud.ServiceClient, groupID, policyID string) pagination.Pager {
@@ -118,13 +120,14 @@ func (opts UpdateOpts) ToWebhookUpdateMap() (map[string]interface{}, error) {
118120
return nil, ErrNoName
119121
}
120122

123+
if opts.Metadata == nil {
124+
return nil, ErrNoMetadata
125+
}
126+
121127
hook := make(map[string]interface{})
122128

123129
hook["name"] = opts.Name
124-
125-
if opts.Metadata != nil {
126-
hook["metadata"] = opts.Metadata
127-
}
130+
hook["metadata"] = opts.Metadata
128131

129132
return hook, nil
130133
}

rackspace/autoscale/v1/webhooks/requests_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,21 @@ func TestUpdate(t *testing.T) {
105105
th.AssertNoErr(t, err)
106106
}
107107

108+
func TestUpdateNoMetadata(t *testing.T) {
109+
th.SetupHTTP()
110+
defer th.TeardownHTTP()
111+
HandleWebhookUpdateSuccessfully(t)
112+
113+
client := client.ServiceClient()
114+
opts := UpdateOpts{
115+
Name: "updated hook",
116+
}
117+
118+
err := Update(client, groupID, policyID, firstID, opts).ExtractErr()
119+
120+
th.AssertEquals(t, ErrNoMetadata, err)
121+
}
122+
108123
func TestDelete(t *testing.T) {
109124
th.SetupHTTP()
110125
defer th.TeardownHTTP()

0 commit comments

Comments
 (0)