From 2a1a93ad499a05db5e55776296e1a02d6de5b5a9 Mon Sep 17 00:00:00 2001 From: John Mulligan Date: Mon, 6 May 2024 19:20:35 -0400 Subject: [PATCH] mgr/smb: add validation unit tests for login names Signed-off-by: John Mulligan --- src/pybind/mgr/smb/tests/test_validation.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/pybind/mgr/smb/tests/test_validation.py b/src/pybind/mgr/smb/tests/test_validation.py index f44c0309798..248b68966cf 100644 --- a/src/pybind/mgr/smb/tests/test_validation.py +++ b/src/pybind/mgr/smb/tests/test_validation.py @@ -110,3 +110,23 @@ def test_clean_custom_options(): smb.validation.check_custom_options(updated) assert smb.validation.clean_custom_options(updated) == orig assert smb.validation.clean_custom_options(None) is None + + +@pytest.mark.parametrize( + "value,ok,err_match", + [ + ("tim", True, ""), + ("britons\\arthur", True, ""), + ("lance a lot", False, "spaces, tabs, or newlines"), + ("tabs\ta\tlot", False, "spaces, tabs, or newlines"), + ("bed\nivere", False, "spaces, tabs, or newlines"), + ("runawa" + ("y" * 122), True, ""), + ("runawa" + ("y" * 123), False, "128"), + ], +) +def test_check_access_name(value, ok, err_match): + if ok: + smb.validation.check_access_name(value) + else: + with pytest.raises(ValueError, match=err_match): + smb.validation.check_access_name(value) -- 2.39.5