mirror of
https://github.com/pocketbase/pocketbase.git
synced 2025-03-19 22:19:23 +02:00
added realtime topic length validator
This commit is contained in:
parent
8c71a291ff
commit
83d91b3dd5
@ -160,7 +160,10 @@ type realtimeSubscribeForm struct {
|
|||||||
func (form *realtimeSubscribeForm) validate() error {
|
func (form *realtimeSubscribeForm) validate() error {
|
||||||
return validation.ValidateStruct(form,
|
return validation.ValidateStruct(form,
|
||||||
validation.Field(&form.ClientId, validation.Required, validation.Length(1, 255)),
|
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)),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -183,6 +183,54 @@ func TestRealtimeSubscribe(t *testing.T) {
|
|||||||
resetClient()
|
resetClient()
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Name: "existing client with invalid topic length",
|
||||||
|
Method: http.MethodPost,
|
||||||
|
URL: "/api/realtime",
|
||||||
|
Body: strings.NewReader(`{
|
||||||
|
"clientId": "` + client.Id() + `",
|
||||||
|
"subscriptions": ["abc", "` + strings.Repeat("a", 2501) + `"]
|
||||||
|
}`),
|
||||||
|
BeforeTestFunc: func(t testing.TB, app *tests.TestApp, e *core.ServeEvent) {
|
||||||
|
app.SubscriptionsBroker().Register(client)
|
||||||
|
},
|
||||||
|
AfterTestFunc: func(t testing.TB, app *tests.TestApp, res *http.Response) {
|
||||||
|
resetClient()
|
||||||
|
},
|
||||||
|
ExpectedStatus: 400,
|
||||||
|
ExpectedContent: []string{
|
||||||
|
`"data":{`,
|
||||||
|
`"subscriptions":{"1":{"code":"validation_length_too_long"`,
|
||||||
|
},
|
||||||
|
ExpectedEvents: map[string]int{"*": 0},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "existing client with valid topic length",
|
||||||
|
Method: http.MethodPost,
|
||||||
|
URL: "/api/realtime",
|
||||||
|
Body: strings.NewReader(`{
|
||||||
|
"clientId": "` + client.Id() + `",
|
||||||
|
"subscriptions": ["abc", "` + strings.Repeat("a", 2500) + `"]
|
||||||
|
}`),
|
||||||
|
ExpectedStatus: 204,
|
||||||
|
ExpectedEvents: map[string]int{
|
||||||
|
"*": 0,
|
||||||
|
"OnRealtimeSubscribeRequest": 1,
|
||||||
|
},
|
||||||
|
BeforeTestFunc: func(t testing.TB, app *tests.TestApp, e *core.ServeEvent) {
|
||||||
|
client.Subscribe("test0")
|
||||||
|
app.SubscriptionsBroker().Register(client)
|
||||||
|
},
|
||||||
|
AfterTestFunc: func(t testing.TB, app *tests.TestApp, res *http.Response) {
|
||||||
|
if len(client.Subscriptions()) != 2 {
|
||||||
|
t.Errorf("Expected %d subscriptions, got %d", 2, len(client.Subscriptions()))
|
||||||
|
}
|
||||||
|
if client.HasSubscription("test0") {
|
||||||
|
t.Errorf("Expected old subscriptions to be replaced")
|
||||||
|
}
|
||||||
|
resetClient()
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Name: "existing client - empty subscriptions",
|
Name: "existing client - empty subscriptions",
|
||||||
Method: http.MethodPost,
|
Method: http.MethodPost,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user