Remove multi-underscores from allowed names
This commit is contained in:
parent
2c2f97cb56
commit
349485d43b
2 changed files with 31 additions and 1 deletions
|
|
@ -353,6 +353,9 @@ class ScanDirectoryManager:
|
|||
For more explanation on the scan naming see `new_scan_dir`
|
||||
"""
|
||||
scan_name = make_name_safe(scan_name)
|
||||
|
||||
# Strip all trailing underscores from the base name
|
||||
scan_name = scan_name.strip("_")
|
||||
# A regex with the scan name and a group for the numbers
|
||||
scan_regex = re.compile(
|
||||
"^" + scan_name + "_([0-9]{" + str(SCAN_ZERO_PAD_DIGITS) + "})$"
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue