Skip to content

Commit 760aa3c

Browse files
committed
Limit groups and label actions to 100 items
1 parent f5d0726 commit 760aa3c

File tree

6 files changed

+54
-14
lines changed

6 files changed

+54
-14
lines changed

flows/actions/add_contact_groups.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ type AddContactGroupsAction struct {
3232
baseAction
3333
universalAction
3434

35-
Groups []*assets.GroupReference `json:"groups" validate:"required,dive"`
35+
Groups []*assets.GroupReference `json:"groups" validate:"required,max=100,dive"`
3636
}
3737

3838
// NewAddContactGroups creates a new add to groups action

flows/actions/add_input_labels.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ type AddInputLabelsAction struct {
3333
baseAction
3434
interactiveAction
3535

36-
Labels []*assets.LabelReference `json:"labels" validate:"required,dive"`
36+
Labels []*assets.LabelReference `json:"labels" validate:"required,max=100,dive"`
3737
}
3838

3939
// NewAddInputLabels creates a new add labels action

flows/actions/base.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,9 @@ func (a *otherContactsAction) resolveRecipients(run flows.Run, logEvent flows.Ev
258258

259259
// utility struct for actions which create a message
260260
type createMsgAction struct {
261-
Text string `json:"text" validate:"required" engine:"localized,evaluated"`
262-
Attachments []string `json:"attachments,omitempty" validate:"dive,attachment" engine:"localized,evaluated"`
263-
QuickReplies []string `json:"quick_replies,omitempty" engine:"localized,evaluated"`
261+
Text string `json:"text" validate:"required" engine:"localized,evaluated"`
262+
Attachments []string `json:"attachments,omitempty" validate:"max=10,dive,attachment" engine:"localized,evaluated"`
263+
QuickReplies []string `json:"quick_replies,omitempty" validate:"max=10,dive,max=64" engine:"localized,evaluated"`
264264
}
265265

266266
// helper function for actions that have a set of group references that must be resolved to actual groups

flows/actions/set_run_local.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ type SetRunLocalAction struct {
4040
baseAction
4141
universalAction
4242

43-
Local string `json:"local" validate:"required,local_ref"`
43+
Local string `json:"local" validate:"required,local_ref"`
4444
Value string `json:"value,omitempty" engine:"evaluated" validate:"max=1000"`
4545
Operation LocalOperation `json:"operation" validate:"required,eq=set|eq=increment|eq=clear"`
4646
}

flows/actions/testdata/add_contact_groups.json

+14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
11
[
2+
{
3+
"description": "Read fails when invalid group reference",
4+
"action": {
5+
"type": "add_contact_groups",
6+
"uuid": "ad154980-7bf7-4ab8-8728-545fd6378912",
7+
"groups": [
8+
{
9+
"uuid": "x",
10+
"name": "1"
11+
}
12+
]
13+
},
14+
"read_error": "field 'groups[0].uuid' must be a valid UUID4"
15+
},
216
{
317
"description": "Error event and NOOP for missing group",
418
"action": {

flows/actions/testdata/send_msg.json

+34-8
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,51 @@
11
[
22
{
3-
"description": "Read fails when text is empty",
3+
"description": "Read fails when text is empty or too many attachments",
44
"action": {
55
"type": "send_msg",
66
"uuid": "ad154980-7bf7-4ab8-8728-545fd6378912",
77
"text": "",
88
"attachments": [
9-
"image:http://example.com/red.jpg"
9+
"image:http://example.com/1.jpg",
10+
"image:http://example.com/2.jpg",
11+
"image:http://example.com/3.jpg",
12+
"image:http://example.com/4.jpg",
13+
"image:http://example.com/5.jpg",
14+
"image:http://example.com/6.jpg",
15+
"image:http://example.com/7.jpg",
16+
"image:http://example.com/8.jpg",
17+
"image:http://example.com/9.jpg",
18+
"image:http://example.com/10.jpg",
19+
"image:http://example.com/11.jpg"
20+
],
21+
"quick_replies": [
22+
"1",
23+
"2",
24+
"3",
25+
"4",
26+
"5",
27+
"6",
28+
"7",
29+
"8",
30+
"9",
31+
"10",
32+
"11"
1033
]
1134
},
12-
"read_error": "field 'text' is required"
35+
"read_error": "field 'text' is required, field 'attachments' must have a maximum of 10 items, field 'quick_replies' must have a maximum of 10 items"
1336
},
1437
{
15-
"description": "Read fails when topic is invalid",
38+
"description": "Read fails when topic is invalid or a quick reply is too long",
1639
"action": {
1740
"type": "send_msg",
1841
"uuid": "ad154980-7bf7-4ab8-8728-545fd6378912",
1942
"text": "hi there",
20-
"topic": "spam"
43+
"topic": "spam",
44+
"quick_replies": [
45+
"1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
46+
]
2147
},
22-
"read_error": "field 'topic' is not a valid message topic"
48+
"read_error": "field 'quick_replies[0]' must be less than or equal to 64, field 'topic' is not a valid message topic"
2349
},
2450
{
2551
"description": "Error events if msg text, attachments and quick replies have expression errors",
@@ -197,7 +223,7 @@
197223
"text": "Hi there",
198224
"quick_replies": [
199225
"yes",
200-
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
226+
"@(repeat(\"1234567890\", 10))"
201227
]
202228
},
203229
"events": [
@@ -218,7 +244,7 @@
218244
"text": "yes"
219245
},
220246
{
221-
"text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed ..."
247+
"text": "1234567890123456789012345678901234567890123456789012345678901..."
222248
}
223249
],
224250
"locale": "eng-US"

0 commit comments

Comments
 (0)