Common: Add reserved filename validation for Windows in CustomPBAConfigurationSchema

This commit is contained in:
Shreya Malviya 2022-07-26 18:10:45 +05:30
parent cacfb7755d
commit 2b56f039ee
1 changed files with 30 additions and 1 deletions

View File

@ -1,6 +1,6 @@
import re
from marshmallow import Schema, fields, post_load, validate
from marshmallow import Schema, ValidationError, fields, post_load, validate, validates
from .agent_sub_configurations import (
CustomPBAConfiguration,
@ -29,6 +29,35 @@ class CustomPBAConfigurationSchema(Schema):
validate=validate.Regexp(regex=valid_windows_custom_pba_filename_regex)
)
@validates("windows_filename")
def validate_windows_filename_not_reserved(self, windows_filename):
# filename shouldn't start with any of these and be followed by a period
if windows_filename.split(".")[0].upper() in [
"CON",
"PRN",
"AUX",
"NUL",
"COM1",
"COM2",
"COM3",
"COM4",
"COM5",
"COM6",
"COM7",
"COM8",
"COM9",
"LPT1",
"LPT2",
"LPT3",
"LPT4",
"LPT5",
"LPT6",
"LPT7",
"LPT8",
"LPT9",
]:
raise ValidationError("Invalid Windows filename: reserved name used")
@post_load
def _make_custom_pba_configuration(self, data, **kwargs):
return CustomPBAConfiguration(**data)