From caaac6b145548759f48e2389c1a81cc6819b4687 Mon Sep 17 00:00:00 2001 From: Gani Georgiev Date: Sun, 3 Nov 2024 11:11:51 +0200 Subject: [PATCH] added topic length validator to avoid relying solely on the body limit for more user friendly error message --- CHANGELOG.md | 7 +++++++ forms/realtime_subscribe.go | 5 ++++- forms/realtime_subscribe_test.go | 14 ++++++++++++-- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b6394bfcf..c275903c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)_). diff --git a/forms/realtime_subscribe.go b/forms/realtime_subscribe.go index def653420..8fd5eb511 100644 --- a/forms/realtime_subscribe.go +++ b/forms/realtime_subscribe.go @@ -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)), + ), ) } diff --git a/forms/realtime_subscribe_test.go b/forms/realtime_subscribe_test.go index d615c4141..36e571116 100644 --- a/forms/realtime_subscribe_test.go +++ b/forms/realtime_subscribe_test.go @@ -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 {