Remove multi-underscores from allowed names

This commit is contained in:
Beth Probert 2026-03-06 15:52:50 +00:00
parent 2c2f97cb56
commit 349485d43b
2 changed files with 31 additions and 1 deletions

View file

@ -167,7 +167,7 @@ def test_bad_scan_names():
scan_dir = scan_dir_manager.new_scan_dir("fake scan")
assert scan_dir.name == "fake_scan_0001"
scan_dir = scan_dir_manager.new_scan_dir("fake scan;rm -rf /;")
assert scan_dir.name == "fake_scan_rm_-rf____0001"
assert scan_dir.name == "fake_scan_rm_-rf_0001"
def test_scan_sequence_and_listing(caplog):
@ -277,6 +277,33 @@ def test_scan_sequence_case_sensitive():
assert "fake_scan_0005" in all_scans
def test_scan_names_have_single_underscores():
"""Check created scans have only one underscore in them, not two."""
_clear_scan_dir()
scan_dir_manager = ScanDirectoryManager(BASE_SCAN_DIR)
# Create some scan data and mark it as successful to get an end date.
scan_data = fake_active_scan_data()
scan_data.set_final_data(result="Success")
# Make 4 scans
scan_dir = scan_dir_manager.new_scan_dir("fake_scan_")
scan_dir.save_scan_data(scan_data)
scan_dir = scan_dir_manager.new_scan_dir("fake_scan__")
scan_dir.save_scan_data(scan_data)
scan_dir = scan_dir_manager.new_scan_dir("fake_scan_______")
scan_dir.save_scan_data(scan_data)
scan_dir = scan_dir_manager.new_scan_dir("fake_scan")
scan_dir.save_scan_data(scan_data)
# Check they exist and are numbered sequentially
all_scans = scan_dir_manager.all_scans
assert_unique_of_length(all_scans, 4)
assert "fake_scan_0001" in all_scans
assert "fake_scan_0002" in all_scans
assert "fake_scan_0003" in all_scans
assert "fake_scan_0004" in all_scans
def test_scan_name_non_sequential():
"""Check new scan has the correct name if the directories are not sequential."""
_clear_scan_dir()