(t *testing.T)
| 10 | ) |
| 11 | |
| 12 | func TestSliceLimitEnforcement(t *testing.T) { |
| 13 | data := UnlimitedData{} |
| 14 | |
| 15 | // Test slice limit with DecodeMsg (using big_slice which is []string) |
| 16 | t.Run("DecodeMsg_SliceLimit", func(t *testing.T) { |
| 17 | buf := msgp.AppendMapHeader(nil, 1) |
| 18 | buf = msgp.AppendString(buf, "big_slice") |
| 19 | buf = msgp.AppendArrayHeader(buf, 150) // Exceeds limit of 100 |
| 20 | |
| 21 | reader := msgp.NewReader(bytes.NewReader(buf)) |
| 22 | err := data.DecodeMsg(reader) |
| 23 | if err != msgp.ErrLimitExceeded { |
| 24 | t.Errorf("Expected ErrLimitExceeded, got %v", err) |
| 25 | } |
| 26 | }) |
| 27 | |
| 28 | // Test slice limit with UnmarshalMsg |
| 29 | t.Run("UnmarshalMsg_SliceLimit", func(t *testing.T) { |
| 30 | buf := msgp.AppendMapHeader(nil, 1) |
| 31 | buf = msgp.AppendString(buf, "big_slice") |
| 32 | buf = msgp.AppendArrayHeader(buf, 150) // Exceeds limit of 100 |
| 33 | |
| 34 | _, err := data.UnmarshalMsg(buf) |
| 35 | if err != msgp.ErrLimitExceeded { |
| 36 | t.Errorf("Expected ErrLimitExceeded, got %v", err) |
| 37 | } |
| 38 | }) |
| 39 | |
| 40 | // Test that slices within limit work fine |
| 41 | t.Run("SliceWithinLimit", func(t *testing.T) { |
| 42 | buf := msgp.AppendMapHeader(nil, 1) |
| 43 | buf = msgp.AppendString(buf, "big_slice") |
| 44 | buf = msgp.AppendArrayHeader(buf, 50) // Within limit |
| 45 | for i := 0; i < 50; i++ { |
| 46 | buf = msgp.AppendString(buf, "test") |
| 47 | } |
| 48 | |
| 49 | _, err := data.UnmarshalMsg(buf) |
| 50 | if err != nil { |
| 51 | t.Errorf("Unexpected error for slice within limit: %v", err) |
| 52 | } |
| 53 | }) |
| 54 | } |
| 55 | |
| 56 | func TestMapLimitEnforcement(t *testing.T) { |
| 57 | data := LimitTestData{} |
nothing calls this directly
no test coverage detected
searching dependent graphs…