mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-08-17 16:50:58 +00:00
fix(subscription): bound outbound response body (#5493)
This commit is contained in:
@@ -1,12 +1,38 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"github.com/mhsanaei/3x-ui/v3/internal/database/model"
|
||||
"github.com/mhsanaei/3x-ui/v3/internal/util/link"
|
||||
)
|
||||
|
||||
func TestReadBoundedOutboundSubscriptionBody(t *testing.T) {
|
||||
t.Run("accepts body at the limit", func(t *testing.T) {
|
||||
want := bytes.Repeat([]byte("a"), int(maxOutboundSubscriptionBytes))
|
||||
got, err := readBoundedOutboundSubscriptionBody(bytes.NewReader(want))
|
||||
if err != nil {
|
||||
t.Fatalf("readBoundedOutboundSubscriptionBody: %v", err)
|
||||
}
|
||||
if !bytes.Equal(got, want) {
|
||||
t.Fatalf("body mismatch: got %d bytes, want %d", len(got), len(want))
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("rejects body over the limit", func(t *testing.T) {
|
||||
body := bytes.Repeat([]byte("b"), int(maxOutboundSubscriptionBytes)+1)
|
||||
got, err := readBoundedOutboundSubscriptionBody(bytes.NewReader(body))
|
||||
if !errors.Is(err, errOutboundSubscriptionBodyTooLarge) {
|
||||
t.Fatalf("error = %v, want errOutboundSubscriptionBodyTooLarge", err)
|
||||
}
|
||||
if got != nil {
|
||||
t.Fatalf("oversized body returned %d bytes, want nil", len(got))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestDefaultPrefixNumber(t *testing.T) {
|
||||
mk := func(id int, prefix string) *model.OutboundSubscription {
|
||||
return &model.OutboundSubscription{Id: id, TagPrefix: prefix}
|
||||
|
||||
Reference in New Issue
Block a user