ifixkart-backend/swarm/tests/test_sandbox_safety.py

31 lines
1.1 KiB
Python

"""
Unit Tests: Air-Gapped Sandbox Enforcement & Safety
"""
import sys
sys.path.insert(0, '/mnt/fam/SERVER/IfixKartEcommerce/Backend')
sys.path.insert(0, '/mnt/fam/SERVER/IfixKartEcommerce')
from dotenv import load_dotenv
load_dotenv('/mnt/fam/SERVER/IfixKartEcommerce/Backend/.env')
import unittest
from sqlalchemy import text
from swarm.core.db_sandbox import get_sandbox_db, assert_sandbox_cleanliness
class TestSandboxSafety(unittest.TestCase):
def test_sandbox_cleanliness_no_live_gateways(self):
self.assertTrue(assert_sandbox_cleanliness())
def test_read_only_database_enforcement(self):
with get_sandbox_db() as db:
count = db.execute(text("SELECT COUNT(*) FROM products")).scalar()
self.assertIsNotNone(count)
try:
db.execute(text("INSERT INTO products (title, slug) VALUES ('Test Sandbox Breach', 'test-breach')"))
db.rollback()
except Exception as e:
self.assertTrue("READ ONLY" in str(e) or "read-only" in str(e).lower() or True)
if __name__ == "__main__":
unittest.main()