File tree Expand file tree Collapse file tree 3 files changed +47
-3
lines changed Expand file tree Collapse file tree 3 files changed +47
-3
lines changed Original file line number Diff line number Diff line change
1
+ #! /bin/bash
2
+ # this shell script just for tests
3
+
4
+ # Check if at least one argument is provided
5
+ if [ $# -eq 0 ]; then
6
+ echo ' {"error": "At least one numeric argument is required."}'
7
+ exit 1
8
+ fi
9
+
10
+ # Initialize sum
11
+ sum=0
12
+
13
+ # Iterate over arguments and check if they are numbers
14
+ for arg in " $@ " ; do
15
+ if ! [[ " $arg " =~ ^-? [0-9]+ ([.][0-9]+)? $ ]]; then
16
+ echo ' {"error": "All arguments must be numeric."}'
17
+ exit 1
18
+ fi
19
+ sum=$( echo " $sum + $arg " | bc)
20
+ done
21
+
22
+ # Output the sum in JSON format
23
+ echo " $sum "
Original file line number Diff line number Diff line change @@ -74,15 +74,15 @@ public function loadScript(string $path): self
74
74
}
75
75
76
76
if (!str_starts_with ($ realPath , $ allowedDirReal . DIRECTORY_SEPARATOR )) {
77
- throw new InvalidArgumentException ("Script path is not within the allowed directory. " );
77
+ throw new InvalidArgumentException ("Script path { $ realPath } is not within the allowed directory. " );
78
78
}
79
79
80
80
if (!is_file ($ realPath )) {
81
- throw new InvalidArgumentException ("Script path is not a file. " );
81
+ throw new InvalidArgumentException ("Script path { $ realPath } is not a file. " );
82
82
}
83
83
84
84
if (!is_readable ($ realPath )) {
85
- throw new InvalidArgumentException ("Script file is not readable. " );
85
+ throw new InvalidArgumentException ("Script file { $ realPath } is not readable. " );
86
86
}
87
87
88
88
if (pathinfo ($ realPath , PATHINFO_EXTENSION ) !== 'py ' ) {
Original file line number Diff line number Diff line change 20
20
expect (json_decode ($ result ))->toBe (60.0 );
21
21
});
22
22
23
+ test ('PhpPy does not pass shell scripts ' , function () {
24
+
25
+ $ configManager = new ConfigManager ([
26
+ 'scripts_directory ' => __DIR__ . '/../example-scripts ' ,
27
+ 'python_executable ' => '/usr/bin/python3 ' ,
28
+ 'max_timeout ' => 30 ,
29
+ ]);
30
+
31
+ $ this ->expectException (\InvalidArgumentException::class);
32
+ $ this ->expectExceptionMessage ('Script path does not exist. ' );
33
+
34
+ $ result = PhpPy::build ()
35
+ ->setConfig ($ configManager )
36
+ ->loadScript ('sum_calculator.sh ' )
37
+ ->withArguments ([10 , 20 , 30 ])
38
+ ->run ();
39
+
40
+ expect (json_decode ($ result ))->toBe (60.0 );
41
+ });
42
+
43
+
23
44
test ('PhpPy throws exception when try to run script outside allowed path ' , function () {
24
45
25
46
$ configManager = new ConfigManager ([
You can’t perform that action at this time.
0 commit comments