Skip to content

Commit

Permalink
Merge pull request #1286 from nyaruka/result_validation
Browse files Browse the repository at this point in the history
Validate result name/category fields in actions that create results
  • Loading branch information
rowanseymour authored Sep 17, 2024
2 parents bd5ec3f + f2e435b commit dd21a10
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 16 deletions.
2 changes: 1 addition & 1 deletion flows/actions/call_classifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type CallClassifierAction struct {

Classifier *assets.ClassifierReference `json:"classifier" validate:"required"`
Input string `json:"input" validate:"required" engine:"evaluated"`
ResultName string `json:"result_name" validate:"required"`
ResultName string `json:"result_name" validate:"required,max=128"`
}

// NewCallClassifier creates a new call classifier action
Expand Down
4 changes: 2 additions & 2 deletions flows/actions/call_resthook.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ type CallResthookAction struct {
baseAction
onlineAction

Resthook string `json:"resthook" validate:"required"`
ResultName string `json:"result_name,omitempty"`
Resthook string `json:"resthook" validate:"required"`
ResultName string `json:"result_name,omitempty" validate:"max=128"`
}

// NewCallResthook creates a new call resthook action
Expand Down
10 changes: 5 additions & 5 deletions flows/actions/call_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ type CallWebhookAction struct {
baseAction
onlineAction

Method string `json:"method" validate:"required,http_method"`
URL string `json:"url" validate:"required" engine:"evaluated"`
Headers map[string]string `json:"headers,omitempty" engine:"evaluated"`
Body string `json:"body,omitempty" engine:"evaluated"`
ResultName string `json:"result_name,omitempty"`
Method string `json:"method" validate:"required,http_method"`
URL string `json:"url" engine:"evaluated" validate:"required"`
Headers map[string]string `json:"headers,omitempty" engine:"evaluated"`
Body string `json:"body,omitempty" engine:"evaluated"`
ResultName string `json:"result_name,omitempty" validate:"max=128"`
}

// NewCallWebhook creates a new call webhook action
Expand Down
6 changes: 3 additions & 3 deletions flows/actions/open_ticket.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ type OpenTicketAction struct {
baseAction
onlineAction

Topic *assets.TopicReference `json:"topic" validate:"omitempty"`
Topic *assets.TopicReference `json:"topic" validate:"omitempty"`
Body string `json:"body" engine:"evaluated"` // TODO will become "note" in future migration
Assignee *assets.UserReference `json:"assignee" validate:"omitempty"`
ResultName string `json:"result_name" validate:"required"`
Assignee *assets.UserReference `json:"assignee" validate:"omitempty"`
ResultName string `json:"result_name" validate:"required,max=128"`
}

// NewOpenTicket creates a new open ticket action
Expand Down
6 changes: 3 additions & 3 deletions flows/actions/set_run_result.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ type SetRunResultAction struct {
baseAction
universalAction

Name string `json:"name" validate:"required"`
Value string `json:"value" engine:"evaluated"`
Category string `json:"category,omitempty" engine:"localized"`
Name string `json:"name" validate:"required,max=128"`
Value string `json:"value" engine:"evaluated"`
Category string `json:"category,omitempty" engine:"localized" validate:"max=128"`
}

// NewSetRunResult creates a new set run result action
Expand Down
10 changes: 10 additions & 0 deletions flows/actions/testdata/call_resthook.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
[
{
"description": "Read fails when result name is too long",
"action": {
"type": "call_resthook",
"uuid": "ad154980-7bf7-4ab8-8728-545fd6378912",
"resthook": "doesnt-exist",
"result_name": "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
},
"read_error": "field 'result_name' must be less than or equal to 128"
},
{
"description": "NOOP if resthook doesn't exist",
"action": {
Expand Down
15 changes: 15 additions & 0 deletions flows/actions/testdata/call_webhook.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,21 @@
},
"read_error": "header 'Accept:' is not a valid HTTP header"
},
{
"description": "Read fails when result name is too long",
"action": {
"type": "call_webhook",
"uuid": "ad154980-7bf7-4ab8-8728-545fd6378912",
"method": "POST",
"url": "http://temba.io/",
"body": "Hi there!",
"headers": {
"Accept:": "something"
},
"result_name": "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
},
"read_error": "field 'result_name' must be less than or equal to 128"
},
{
"description": "Error events created if URL, header or body contain expression errors",
"http_mocks": {
Expand Down
15 changes: 15 additions & 0 deletions flows/actions/testdata/open_ticket.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
[
{
"description": "Read fails when result name is too long",
"action": {
"type": "open_ticket",
"uuid": "ad154980-7bf7-4ab8-8728-545fd6378912",
"topic": {
"uuid": "dc61e948-26a1-407e-9739-b73b46400b51",
"name": "Deleted"
},
"body": "Where are my cookies?",
"assignee": null,
"result_name": "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
},
"read_error": "field 'result_name' must be less than or equal to 128"
},
{
"description": "Error event for invalid topic reference",
"action": {
Expand Down
22 changes: 22 additions & 0 deletions flows/actions/testdata/set_run_result.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,26 @@
[
{
"description": "Read fails when name is empty",
"action": {
"uuid": "ad154980-7bf7-4ab8-8728-545fd6378912",
"type": "set_run_result",
"name": "",
"value": "bar",
"category": ""
},
"read_error": "field 'name' is required"
},
{
"description": "Read fails when category is too long",
"action": {
"uuid": "ad154980-7bf7-4ab8-8728-545fd6378912",
"type": "set_run_result",
"name": "Foo",
"value": "bar",
"category": "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
},
"read_error": "field 'category' must be less than or equal to 128"
},
{
"description": "Error event and action skipped if value contains expression error",
"action": {
Expand Down
4 changes: 2 additions & 2 deletions flows/actions/transfer_airtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ type TransferAirtimeAction struct {
baseAction
onlineAction

Amounts map[string]decimal.Decimal `json:"amounts" validate:"required"`
ResultName string `json:"result_name" validate:"required"`
Amounts map[string]decimal.Decimal `json:"amounts" validate:"required"`
ResultName string `json:"result_name" validate:"required,max=128"`
}

// NewTransferAirtime creates a new airtime transfer action
Expand Down

0 comments on commit dd21a10

Please sign in to comment.