-
-
Notifications
You must be signed in to change notification settings - Fork 324
/
Copy pathtest_common.py
70 lines (62 loc) · 1.88 KB
/
test_common.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import pytest
from reactpy import html
from reactpy.backend._common import (
CommonOptions,
traversal_safe_path,
vdom_head_elements_to_html,
)
def test_common_options_url_prefix_starts_with_slash():
# no prefix specified
CommonOptions(url_prefix="")
with pytest.raises(ValueError, match="start with '/'"):
CommonOptions(url_prefix="not-start-withslash")
@pytest.mark.parametrize(
"bad_path",
[
"../escaped",
"ok/../../escaped",
"ok/ok-again/../../ok-yet-again/../../../escaped",
],
)
def test_catch_unsafe_relative_path_traversal(tmp_path, bad_path):
with pytest.raises(ValueError, match="Unsafe path"):
traversal_safe_path(tmp_path, *bad_path.split("/"))
@pytest.mark.parametrize(
"vdom_in, html_out",
[
(
"<title>example</title>",
"<title>example</title>",
),
(
# We do not modify strings given by user. If given as VDOM we would have
# striped this head element, but since provided as string, we leav as-is.
"<head></head>",
"<head></head>",
),
(
html.head(
html.meta({"charset": "utf-8"}),
html.title("example"),
),
# we strip the head element
'<meta charset="utf-8"><title>example</title>',
),
(
html.fragment(
html.meta({"charset": "utf-8"}),
html.title("example"),
),
'<meta charset="utf-8"><title>example</title>',
),
(
[
html.meta({"charset": "utf-8"}),
html.title("example"),
],
'<meta charset="utf-8"><title>example</title>',
),
],
)
def test_vdom_head_elements_to_html(vdom_in, html_out):
assert vdom_head_elements_to_html(vdom_in) == html_out