| 345 | } |
| 346 | |
| 347 | func TestBuiltin_memory_limits(t *testing.T) { |
| 348 | tests := []struct { |
| 349 | input string |
| 350 | }{ |
| 351 | {`repeat("\xc4<\xc4\xc4\xc4",10009999990)`}, |
| 352 | } |
| 353 | |
| 354 | for _, test := range tests { |
| 355 | t.Run(test.input, func(t *testing.T) { |
| 356 | timeout := make(chan bool, 1) |
| 357 | go func() { |
| 358 | time.Sleep(time.Second) |
| 359 | timeout <- true |
| 360 | }() |
| 361 | |
| 362 | done := make(chan bool, 1) |
| 363 | go func() { |
| 364 | _, err := expr.Eval(test.input, nil) |
| 365 | assert.Error(t, err) |
| 366 | assert.Contains(t, err.Error(), "memory budget exceeded") |
| 367 | done <- true |
| 368 | }() |
| 369 | |
| 370 | select { |
| 371 | case <-done: |
| 372 | // Success. |
| 373 | case <-timeout: |
| 374 | t.Fatal("timeout") |
| 375 | } |
| 376 | }) |
| 377 | } |
| 378 | } |
| 379 | |
| 380 | func TestBuiltin_allow_builtins_override(t *testing.T) { |
| 381 | t.Run("via env var", func(t *testing.T) { |