Swaped from CIS to NIST controls

This commit is contained in:
2025-08-14 14:08:34 +02:00
parent aeaec99621
commit 3734a5b51b
16 changed files with 639 additions and 241 deletions

View File

@@ -6,8 +6,8 @@ from backend.core.models import Control
class ExportControlsCommandTest(TestCase):
def setUp(self):
Control.objects.create(name="Test Safeguard 1")
Control.objects.create(name="Test Safeguard 2")
Control.objects.create(subcategory="PR.AA-01", function="Identity Management")
Control.objects.create(subcategory="PR.DS-11", function="Backups")
self.csv_file_path = 'test_export_controls.csv'
@@ -26,5 +26,7 @@ class ExportControlsCommandTest(TestCase):
self.assertEqual(len(rows), 2)
self.assertEqual(rows[0]["CIS v8.1 Safeguards (Sub-Controls)"], "Test Safeguard 1")
self.assertEqual(rows[1]["CIS v8.1 Safeguards (Sub-Controls)"], "Test Safeguard 2")
self.assertIn("Subcategory", reader.fieldnames)
self.assertIn("Function", reader.fieldnames)
self.assertEqual(rows[0]["Subcategory"], "PR.AA-01")
self.assertEqual(rows[1]["Subcategory"], "PR.DS-11")

View File

@@ -7,11 +7,21 @@ from backend.core.models import Control
class ImportControlsCommandTest(TestCase):
def setUp(self):
self.csv_file_path = 'test_import_controls.csv'
with open(self.csv_file_path, mode='w', encoding='utf-8') as csv_file:
writer = csv.DictWriter(csv_file, fieldnames=["CIS v8.1 Safeguards (Sub-Controls)"])
with open(self.csv_file_path, mode='w', encoding='utf-8', newline='') as csv_file:
writer = csv.DictWriter(csv_file, fieldnames=[
"Subcategory","Function","Category",
"Implementation_Examples","Effectiveness_Monitoring_Examples",
"Documentation_Score","Implementation_Score",
])
writer.writeheader()
writer.writerow({"CIS v8.1 Safeguards (Sub-Controls)": "Test Safeguard 1"})
writer.writerow({"CIS v8.1 Safeguards (Sub-Controls)": "Test Safeguard 2"})
writer.writerow({
"Subcategory":"GV.SC-06",
"Function":"GOVERN (GV): ...",
"Category":"Cybersecurity Supply Chain Risk Management (GV.SC)",
"Implementation_Examples":"Ex1: ...",
"Effectiveness_Monitoring_Examples":"",
"Documentation_Score":"", "Implementation_Score":""
})
def tearDown(self):
if os.path.exists(self.csv_file_path):
@@ -22,19 +32,17 @@ class ImportControlsCommandTest(TestCase):
call_command('import_controls', self.csv_file_path)
self.assertEqual(Control.objects.count(), 2)
self.assertEqual(Control.objects.count(), 1)
safeguards = Control.objects.values_list('name', flat=True)
self.assertIn("Test Safeguard 1", safeguards)
self.assertIn("Test Safeguard 2", safeguards)
controls = Control.objects.all()
self.assertEqual(controls[0].subcategory, "GV.SC-06")
def test_import_controls_update(self):
Control.objects.create(name="Test Safeguard 1")
Control.objects.create(subcategory="GV.SC-06")
call_command('import_controls', self.csv_file_path)
self.assertEqual(Control.objects.count(), 2)
self.assertEqual(Control.objects.count(), 1)
safeguards = Control.objects.values_list('name', flat=True)
self.assertIn("Test Safeguard 1", safeguards)
self.assertIn("Test Safeguard 2", safeguards)
control = Control.objects.first()
self.assertEqual(control.subcategory, "GV.SC-06")