-
Notifications
You must be signed in to change notification settings - Fork 172
Expand file tree
/
Copy pathtest_security.py
More file actions
53 lines (43 loc) · 2.04 KB
/
Copy pathtest_security.py
File metadata and controls
53 lines (43 loc) · 2.04 KB
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
import pytest
from frictionless import FrictionlessException, Package, Resource, platform, system
# General
@pytest.mark.skipif(platform.type == "windows", reason="Fix on Windows")
def test_package_resource_unsafe_schema():
path = "data/table.csv"
schema = "data/../data/schema.json"
with pytest.raises(FrictionlessException) as excinfo:
Package({"resources": [{"name": "name", "path": path, "schema": schema}]})
error = excinfo.value.error
reasons = excinfo.value.reasons
assert len(reasons) == 1
assert error.type == "package-error"
assert error.note == "descriptor is not valid"
assert reasons[0].type == "resource-error"
assert reasons[0].note.count('schema.json" is not safe')
def test_package_resource_unsafe_schema_trusted():
path = "data/table.csv"
schema = "data/../data/schema.json"
with system.use_context(trusted=True):
Package({"resources": [{"name": "name", "path": path, "schema": schema}]})
@pytest.mark.vcr
@pytest.mark.skipif(platform.type == "windows", reason="Fix on Windows")
def test_package_external_profile_invalid_local_from_descriptor_unsafe():
profile = "data/../data/profiles/camtrap.json"
resource = Resource(name="table", path="data/table.csv")
with pytest.raises(FrictionlessException) as excinfo:
Package({"resources": [resource.to_descriptor()], "profile": profile})
error = excinfo.value.error
reasons = excinfo.value.reasons
assert len(reasons) == 1
assert error.type == "package-error"
assert error.note == "descriptor is not valid"
assert reasons[0].type == "package-error"
assert reasons[0].note.count('camtrap.json" is not safe')
@pytest.mark.vcr
def test_package_external_profile_invalid_local_from_descriptor_unsafe_trusted():
profile = "data/../data/profiles/camtrap.json"
resource = Resource(name="table", path="data/table.csv")
with system.use_context(trusted=True):
package = Package(resources=[resource], profile=profile)
report = package.validate()
assert report.stats["errors"] == 5