| 1 |
import string |
| 2 |
|
| 3 |
import pytest |
| 4 |
|
| 5 |
from pyxs.exceptions import InvalidPath, InvalidPermission |
| 6 |
from pyxs.helpers import check_path, check_watch_path, check_perms |
| 7 |
|
| 8 |
|
| 9 |
def test_check_path(): |
| 10 |
|
| 11 |
|
| 12 |
with pytest.raises(InvalidPath): |
| 13 |
check_path(b"/foo/bar" * 3072) |
| 14 |
|
| 15 |
with pytest.raises(InvalidPath): |
| 16 |
check_path(b"foo/bar" * 2048) |
| 17 |
|
| 18 |
|
| 19 |
for char in string.punctuation: |
| 20 |
if char in "-/_@": |
| 21 |
continue |
| 22 |
|
| 23 |
with pytest.raises(InvalidPath): |
| 24 |
check_path(b"/foo" + char.encode()) |
| 25 |
|
| 26 |
|
| 27 |
with pytest.raises(InvalidPath): |
| 28 |
check_path(b"/foo/") |
| 29 |
|
| 30 |
|
| 31 |
with pytest.raises(InvalidPath): |
| 32 |
check_path(b"/foo//bar") |
| 33 |
|
| 34 |
|
| 35 |
check_path(b"/") |
| 36 |
|
| 37 |
|
| 38 |
def test_check_watch_path(): |
| 39 |
|
| 40 |
with pytest.raises(InvalidPath): |
| 41 |
check_watch_path(b"/foo/") |
| 42 |
|
| 43 |
with pytest.raises(InvalidPath): |
| 44 |
check_watch_path(b"/fo\x07o") |
| 45 |
|
| 46 |
with pytest.raises(InvalidPath): |
| 47 |
check_watch_path(b"/$/foo") |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
with pytest.raises(InvalidPath): |
| 52 |
check_watch_path(b"@foo") |
| 53 |
|
| 54 |
|
| 55 |
check_watch_path(b"@introduceDomain") |
| 56 |
check_watch_path(b"@releaseDomain") |
| 57 |
|
| 58 |
|
| 59 |
def test_check_perms(): |
| 60 |
|
| 61 |
with pytest.raises(InvalidPermission): |
| 62 |
check_perms([b"foo"]) |
| 63 |
|
| 64 |
with pytest.raises(InvalidPermission): |
| 65 |
check_perms([b"f20"]) |
| 66 |
|
| 67 |
with pytest.raises(InvalidPermission): |
| 68 |
check_perms([b"r-20"]) |
| 69 |
|
| 70 |
|
| 71 |
check_perms(b"w0 r0 b0 n0".split()) |
| 72 |
check_perms([b"w999999"]) |