nodejs_malicious_test.go 800 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package integrationtests_test
  2. import (
  3. "strings"
  4. "testing"
  5. "github.com/langgenius/dify-sandbox/internal/core/runner/types"
  6. "github.com/langgenius/dify-sandbox/internal/service"
  7. )
  8. func TestNodejsRunCommand(t *testing.T) {
  9. // Test case for run_command
  10. resp := service.RunNodeJsCode(`
  11. const { spawn } = require( 'child_process' );
  12. const ls = spawn( 'ls', [ '-lh', '/usr' ] );
  13. ls.stdout.on( 'data', ( data ) => {
  14. console.log(data);
  15. } );
  16. ls.stderr.on( 'data', ( data ) => {
  17. console.log(data);
  18. } );
  19. ls.on( 'close', ( code ) => {
  20. console.log(code);
  21. } );
  22. `, "", &types.RunnerOptions{})
  23. if resp.Code != 0 {
  24. t.Error(resp)
  25. }
  26. if !strings.Contains(resp.Data.(*service.RunCodeResponse).Stderr, "operation not permitted") {
  27. t.Error(resp.Data.(*service.RunCodeResponse).Stderr)
  28. }
  29. }