Skip to content

Commit

Permalink
added topic length validator to avoid relying solely on the body limi…
Browse files Browse the repository at this point in the history
…t for more user friendly error message
  • Loading branch information
ganigeorgiev committed Nov 3, 2024
1 parent cd14714 commit caaac6b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## v0.22.23

-

- Other minor fixes (updated npm deps to fix the vulnerabilities warning, more user friendly realtime topic length error, regenerated JSVM types, etc.)


## v0.22.22

- Added deprecation log in case Instagram OAuth2 is used (_related to [#5652](https://github.com/pocketbase/pocketbase/discussions/5652)_).
Expand Down
5 changes: 4 additions & 1 deletion forms/realtime_subscribe.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ func NewRealtimeSubscribe() *RealtimeSubscribe {
func (form *RealtimeSubscribe) Validate() error {
return validation.ValidateStruct(form,
validation.Field(&form.ClientId, validation.Required, validation.Length(1, 255)),
validation.Field(&form.Subscriptions, validation.Length(0, 1000)),
validation.Field(&form.Subscriptions,
validation.Length(0, 1000),
validation.Each(validation.Length(0, 2500)),
),
)
}
14 changes: 12 additions & 2 deletions forms/realtime_subscribe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,25 @@ func TestRealtimeSubscribeValidate(t *testing.T) {
[]string{},
},
{
"subscriptions > max limit",
"total subscriptions > max limit",
`{"clientId":"test", "subscriptions":[` + strings.Join(invalidSubscriptionsLimit, ",") + `]}`,
[]string{"subscriptions"},
},
{
"subscriptions <= max limit",
"total subscriptions <= max limit",
`{"clientId":"test", "subscriptions":[` + strings.Join(validSubscriptionsLimit, ",") + `]}`,
[]string{},
},
{
"single subscription > max limit",
`{"clientId":"test", "subscriptions":["abc", "` + strings.Repeat("a", 2501) + `"]}`,
[]string{"subscriptions"},
},
{
"single subscription <= max limit",
`{"clientId":"test", "subscriptions":["abc", "` + strings.Repeat("a", 2500) + `"]}`,
[]string{},
},
}

for _, s := range scenarios {
Expand Down

0 comments on commit caaac6b

Please sign in to comment.