forked from kevoreilly/CAPEv2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_web_utils.py
92 lines (71 loc) · 2.1 KB
/
test_web_utils.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# Copyright (C) 2010-2015 Cuckoo Foundation.
# This file is part of Cuckoo Sandbox - http://www.cuckoosandbox.org
# See the file 'docs/LICENSE' for copying permission.
import tempfile
import httpretty
import pytest
from lib.cuckoo.common.path_utils import path_delete, path_write_file
from lib.cuckoo.common.web_utils import _download_file, force_int, get_file_content, parse_request_arguments
@pytest.fixture
def paths():
path_list = []
for i in range(3):
path_list += [tempfile.NamedTemporaryFile(delete=False).name]
_ = path_write_file(path_list[i], str(i + 10), mode="text")
yield path_list
try:
for i in path_list:
path_delete(i)
except Exception as e:
print(("Error cleaning up, probably fine:" + str(e)))
@pytest.fixture
def path():
onepath = tempfile.NamedTemporaryFile(delete=False)
_ = path_write_file(onepath.name, "1338", mode="text")
yield onepath.name
try:
path_delete(onepath.name)
except Exception as e:
print(("Error cleaning up, probably fine:" + str(e)))
def test_get_file_content(paths):
assert get_file_content(paths) == b"10"
def test_get_file_contents_path(path):
assert get_file_content(path) == b"1338"
@httpretty.activate
def test__download_file():
httpretty.register_uri(httpretty.GET, "http://mordor.eye/onering", body="frodo")
assert _download_file(route=None, url="http://mordor.eye/onering", options="dne_abc=123,dne_def=456") == b"frodo"
@pytest.fixture
def mock_request():
class MockReq:
POST = {"clock": "03-31-2021 14:24:36"}
yield MockReq()
def test_parse_request_arguments(mock_request):
ret = parse_request_arguments(mock_request)
assert ret == (
"",
"",
0,
0,
"",
"",
"",
None,
"",
False,
"03-31-2021 14:24:36",
False,
None,
None,
None,
None,
False,
None,
None,
None,
"",
"",
)
def test_force_int():
assert force_int(value="1") == 1
assert force_int(value="$") == 0