From: John Mulligan Date: Wed, 7 Feb 2024 21:15:21 +0000 (-0500) Subject: pybind/mgr/smb: add unit tests file tests/test_validation.py X-Git-Tag: v20.0.0~2047^2~13 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=29f658cd8ba89fc2c1c9cebaad1fd7214874ccce;p=ceph.git pybind/mgr/smb: add unit tests file tests/test_validation.py Signed-off-by: John Mulligan --- diff --git a/src/pybind/mgr/smb/tests/test_validation.py b/src/pybind/mgr/smb/tests/test_validation.py new file mode 100644 index 00000000000..6210c179c88 --- /dev/null +++ b/src/pybind/mgr/smb/tests/test_validation.py @@ -0,0 +1,77 @@ +import pytest + +import smb.validation + + +@pytest.mark.parametrize( + "value,valid", + [ + ("cat", True), + ("m-o-u-s-e", True), + ("foo-", False), + ("-bar", False), + ("not-too-bad-1", True), + ("this-one-is-simply-too-long", False), + ("t1", True), + ("x", True), + ("", False), + ], +) +def test_valid_id(value, valid): + assert smb.validation.valid_id(value) == valid + if valid: + smb.validation.check_id(value) + else: + with pytest.raises(ValueError): + smb.validation.check_id(value) + + +@pytest.mark.parametrize( + "value,valid", + [ + ("cat", True), + ("m-o-u-s-e", True), + ("this-one-is-simply-fine-not-toolong", True), + ("t1", True), + ("x", True), + ("A Wonderful Share", True), + ("A_Very_Nice_Share", True), + (">>>!!!", False), + ("", False), + ("A %h Family", False), + ("A" * 64, True), + ("A" * 65, False), + ], +) +def test_valid_share_name(value, valid): + assert smb.validation.valid_share_name(value) == valid + if valid: + smb.validation.check_share_name(value) + else: + with pytest.raises(ValueError): + smb.validation.check_share_name(value) + + +@pytest.mark.parametrize( + "value,valid", + [ + ("cat", True), + ("animals/cat", True), + ("animals/cat", True), + ("./animals/cat", True), + ("/animals/cat", True), + ("/", True), + ("/animals/../cat", True), # weird, but OK + ("../cat", False), + ("", False), + (".", False), + ("..", False), + ], +) +def test_valid_path(value, valid): + assert smb.validation.valid_path(value) == valid + if valid: + smb.validation.check_path(value) + else: + with pytest.raises(ValueError): + smb.validation.check_path(value)