mirror of
https://github.com/whyour/qinglong.git
synced 2025-12-13 07:25:05 +08:00
Clean up test files and update gitignore
Co-authored-by: whyour <22700758+whyour@users.noreply.github.com>
This commit is contained in:
parent
b14b77deee
commit
7abba4c77b
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -28,3 +28,6 @@ __pycache__
|
|||
/shell/preload/notify.*
|
||||
/shell/preload/*-notify.json
|
||||
/shell/preload/__ql_notify__.*
|
||||
test_sandbox_integration.sh
|
||||
data/scripts/test_*.js
|
||||
data/scripts/test_*.py
|
||||
|
|
|
|||
|
|
@ -1,43 +0,0 @@
|
|||
// Minimal test of sandbox module
|
||||
const path = require('path');
|
||||
|
||||
// Set up environment
|
||||
process.env.QL_DIR = path.join(__dirname, '../..');
|
||||
process.env.QL_DATA_DIR = path.join(__dirname, '../../data');
|
||||
|
||||
// Load sandbox
|
||||
require('./sandbox.js');
|
||||
|
||||
const fs = require('fs');
|
||||
|
||||
console.log("Testing filesystem sandbox...\n");
|
||||
|
||||
// Test 1: Try to write to config directory (should fail)
|
||||
console.log("Test 1: Attempting to write to config/test.txt (should fail)...");
|
||||
try {
|
||||
const configPath = path.join(__dirname, '../../data/config/test.txt');
|
||||
fs.writeFileSync(configPath, 'test');
|
||||
console.log("❌ FAILED: Was able to write to protected config directory!");
|
||||
process.exit(1);
|
||||
} catch (error) {
|
||||
if (error.code === 'EACCES' && error.message.includes('Security Error')) {
|
||||
console.log("✅ PASSED: Correctly blocked write to config directory");
|
||||
console.log("Error message:", error.message.split('\n')[0]);
|
||||
} else {
|
||||
console.log("❓ UNEXPECTED ERROR:", error.message);
|
||||
}
|
||||
}
|
||||
|
||||
// Test 2: Write to scripts directory (should succeed)
|
||||
console.log("\nTest 2: Attempting to write to scripts directory (should succeed)...");
|
||||
try {
|
||||
const scriptsPath = path.join(__dirname, '../../data/scripts/test_output.txt');
|
||||
fs.writeFileSync(scriptsPath, 'This is a test file');
|
||||
console.log("✅ PASSED: Successfully wrote to scripts directory");
|
||||
fs.unlinkSync(scriptsPath);
|
||||
} catch (error) {
|
||||
console.log("❌ FAILED: Could not write to allowed scripts directory:", error.message);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
console.log("\n✅ Basic sandbox tests passed!");
|
||||
|
|
@ -1,50 +0,0 @@
|
|||
#!/usr/bin/env python3
|
||||
# Minimal test of Python sandbox module
|
||||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
# Set up environment
|
||||
script_dir = Path(__file__).parent.resolve()
|
||||
ql_dir = script_dir.parent.parent
|
||||
os.environ['QL_DIR'] = str(ql_dir)
|
||||
os.environ['QL_DATA_DIR'] = str(ql_dir / 'data')
|
||||
|
||||
# Add preload to path
|
||||
sys.path.insert(0, str(script_dir))
|
||||
|
||||
# Load sandbox
|
||||
import sandbox
|
||||
|
||||
print("Testing Python filesystem sandbox...\n")
|
||||
|
||||
# Test 1: Try to write to config directory (should fail)
|
||||
print("Test 1: Attempting to write to config/test.txt (should fail)...")
|
||||
try:
|
||||
config_path = ql_dir / 'data' / 'config' / 'test.txt'
|
||||
with open(config_path, 'w') as f:
|
||||
f.write('test')
|
||||
print("❌ FAILED: Was able to write to protected config directory!")
|
||||
sys.exit(1)
|
||||
except PermissionError as e:
|
||||
if 'Security Error' in str(e):
|
||||
print("✅ PASSED: Correctly blocked write to config directory")
|
||||
print(f"Error message: {str(e).split(chr(10))[0]}")
|
||||
else:
|
||||
print(f"❓ UNEXPECTED ERROR: {e}")
|
||||
except Exception as e:
|
||||
print(f"❓ UNEXPECTED ERROR: {e}")
|
||||
|
||||
# Test 2: Write to scripts directory (should succeed)
|
||||
print("\nTest 2: Attempting to write to scripts directory (should succeed)...")
|
||||
try:
|
||||
scripts_path = ql_dir / 'data' / 'scripts' / 'test_output.txt'
|
||||
with open(scripts_path, 'w') as f:
|
||||
f.write('This is a test file')
|
||||
print("✅ PASSED: Successfully wrote to scripts directory")
|
||||
os.remove(scripts_path)
|
||||
except Exception as e:
|
||||
print(f"❌ FAILED: Could not write to allowed scripts directory: {e}")
|
||||
sys.exit(1)
|
||||
|
||||
print("\n✅ Basic Python sandbox tests passed!")
|
||||
Loading…
Reference in New Issue
Block a user