-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle security audit findings (#23)
* Fixed DP-001 * Fixed DP-002 * Fixed DP-003 * Fixed DP-012 * Skip permission tests on Windows
- Loading branch information
Showing
7 changed files
with
95 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import pytest | ||
|
||
from dplib.actions.metadata.convert import convert_metadata | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"source,target", | ||
( | ||
("bad", "ckan"), | ||
("ckan", "bad"), | ||
), | ||
) | ||
def test_convert_metadata_bad_source_or_target_dp_012(source: str, target: str): | ||
with pytest.raises(ValueError): | ||
convert_metadata("resource.json", type="resource", source=source, target=target) # type: ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import os | ||
import platform | ||
import stat | ||
from pathlib import Path | ||
|
||
import pytest | ||
|
||
from dplib.helpers.file import write_file | ||
|
||
|
||
@pytest.mark.skipif(platform.system() == "Windows", reason="Unix only") | ||
def test_write_file_implicit_permissions_dp_002(tmpdir: Path): | ||
path = str(tmpdir / "test.txt") | ||
write_file(path, "Hello, World!") | ||
permissions = oct(stat.S_IMODE(os.stat(path).st_mode)) | ||
assert permissions == "0o600" | ||
|
||
|
||
@pytest.mark.skipif(platform.system() == "Windows", reason="Unix only") | ||
def test_write_file_explicit_permissions_dp_003(tmpdir: Path): | ||
path = str(tmpdir / "test.txt") | ||
write_file(path, "Hello, World!", permissions=0o644) | ||
permissions = oct(stat.S_IMODE(os.stat(path).st_mode)) | ||
assert permissions == "0o644" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import pytest | ||
|
||
from dplib.helpers.path import assert_safe_path | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"path", | ||
( | ||
"../data.csv", | ||
"/etc/home/secret.json", | ||
"http:test/../../secret.json", | ||
), | ||
) | ||
def test_assert_safe_path_raises_dp_001(path: str): | ||
with pytest.raises(Exception): | ||
assert_safe_path(path) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters