MCPcopy Create free account
hub / github.com/AutoForgeAI/autoforge / test_validate_init_script

Function test_validate_init_script

test_security.py:170–206  ·  view source on GitHub ↗

Test init.sh script execution validation.

()

Source from the content-addressed store, hash-verified

168
169
170def test_validate_init_script():
171 """Test init.sh script execution validation."""
172 print("\nTesting init.sh validation:\n")
173 passed = 0
174 failed = 0
175
176 # Test cases: (command, should_be_allowed, description)
177 test_cases = [
178 # Allowed cases
179 ("./init.sh", True, "basic ./init.sh"),
180 ("./init.sh arg1 arg2", True, "with arguments"),
181 ("/path/to/init.sh", True, "absolute path"),
182 ("../dir/init.sh", True, "relative path with init.sh"),
183 # Blocked cases
184 ("./setup.sh", False, "different script name"),
185 ("./init.py", False, "python script"),
186 ("bash init.sh", False, "bash invocation"),
187 ("sh init.sh", False, "sh invocation"),
188 ("./malicious.sh", False, "malicious script"),
189 ("./init.sh; rm -rf /", False, "command injection attempt"),
190 ]
191
192 for cmd, should_allow, description in test_cases:
193 allowed, reason = validate_init_script(cmd)
194 if allowed == should_allow:
195 print(f" PASS: {cmd!r} ({description})")
196 passed += 1
197 else:
198 expected = "allowed" if should_allow else "blocked"
199 actual = "allowed" if allowed else "blocked"
200 print(f" FAIL: {cmd!r} ({description})")
201 print(f" Expected: {expected}, Got: {actual}")
202 if reason:
203 print(f" Reason: {reason}")
204 failed += 1
205
206 return passed, failed
207
208
209def test_pattern_matching():

Callers 1

mainFunction · 0.85

Calls 1

validate_init_scriptFunction · 0.90

Tested by

no test coverage detected