]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
pybind/mgr/smb: add unit tests file tests/test_validation.py
authorJohn Mulligan <jmulligan@redhat.com>
Wed, 7 Feb 2024 21:15:21 +0000 (16:15 -0500)
committerJohn Mulligan <jmulligan@redhat.com>
Thu, 25 Apr 2024 23:10:39 +0000 (19:10 -0400)
Signed-off-by: John Mulligan <jmulligan@redhat.com>
src/pybind/mgr/smb/tests/test_validation.py [new file with mode: 0644]

diff --git a/src/pybind/mgr/smb/tests/test_validation.py b/src/pybind/mgr/smb/tests/test_validation.py
new file mode 100644 (file)
index 0000000..6210c17
--- /dev/null
@@ -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)