返回 DeepSeek-Reasonix
python_probe_test.go
根目录 / internal / shellsafe / python_probe_test.go
1 package shellsafe
2
3 import "testing"
4
5 // -v is verbose import tracing in python, not --version: `python3 -v script.py`
6 // runs the script, so it must not be read as a version probe.
7 func TestPythonVerboseIsNotAVersionProbe(t *testing.T) {
8 for _, c := range []string{
9 "python3 -v script.py", "python -v script.py", "python3 -v", "python3 -v -m http.server",
10 "python3 -vv script.py", "python3 -v -c 'import os'",
11 } {
12 if _, _, ok := CommandIsReadOnly(c); ok {
13 t.Errorf("CommandIsReadOnly(%q) = true, want false", c)
14 }
15 if effect := ClassifyBash(c); effect.PermissionSafe {
16 t.Errorf("ClassifyBash(%q) is permission-safe, want not", c)
17 }
18 }
19 }
20
21 func TestPythonVersionProbesStayReadOnly(t *testing.T) {
22 for _, c := range []string{"python --version", "python3 --version", "python3 -V", "python -V"} {
23 if _, _, ok := CommandIsReadOnly(c); !ok {
24 t.Errorf("CommandIsReadOnly(%q) = false, want true", c)
25 }
26 if effect := ClassifyBash(c); !effect.PermissionSafe {
27 t.Errorf("ClassifyBash(%q) is not permission-safe, want safe", c)
28 }
29 }
30 }
31
31 lines GO