修复:严格校验测试批次请求头
This commit is contained in:
@@ -14,10 +14,9 @@ def parse_optional_positive_batch_id(raw: str | None) -> int | None:
|
|||||||
"""解析可选的测试批次请求头。"""
|
"""解析可选的测试批次请求头。"""
|
||||||
if raw is None:
|
if raw is None:
|
||||||
return None
|
return None
|
||||||
try:
|
if not isinstance(raw, str) or not raw or not raw.isascii() or not raw.isdigit():
|
||||||
batch_id = int(raw)
|
raise ServiceWarning('', '测试批次标识必须为正整数')
|
||||||
except (TypeError, ValueError):
|
batch_id = int(raw)
|
||||||
raise ServiceWarning('', '测试批次标识必须为正整数') from None
|
|
||||||
if batch_id <= 0:
|
if batch_id <= 0:
|
||||||
raise ServiceWarning('', '测试批次标识必须为正整数')
|
raise ServiceWarning('', '测试批次标识必须为正整数')
|
||||||
return batch_id
|
return batch_id
|
||||||
|
|||||||
@@ -82,6 +82,11 @@ class TestBatchHeaderTest(unittest.TestCase):
|
|||||||
with self.subTest(raw=raw), self.assertRaisesRegex(ServiceWarning, '测试批次标识必须为正整数'):
|
with self.subTest(raw=raw), self.assertRaisesRegex(ServiceWarning, '测试批次标识必须为正整数'):
|
||||||
parse_optional_positive_batch_id(raw)
|
parse_optional_positive_batch_id(raw)
|
||||||
|
|
||||||
|
def test_python_coercible_values_are_not_valid_ascii_decimal_literals(self) -> None:
|
||||||
|
for raw in (' 7', '7 ', '+7', '1_0', '7', True, 7, b'7'):
|
||||||
|
with self.subTest(raw=raw), self.assertRaisesRegex(ServiceWarning, '测试批次标识必须为正整数'):
|
||||||
|
parse_optional_positive_batch_id(raw)
|
||||||
|
|
||||||
|
|
||||||
class TestBatchAccessTest(unittest.IsolatedAsyncioTestCase):
|
class TestBatchAccessTest(unittest.IsolatedAsyncioTestCase):
|
||||||
async def asyncSetUp(self) -> None:
|
async def asyncSetUp(self) -> None:
|
||||||
|
|||||||
Reference in New Issue
Block a user