Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: rewrite test code without os.system() #627

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions tests/test_win32compat.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import ctypes
import os
import pathlib
import subprocess

Check warning on line 4 in tests/test_win32compat.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

tests/test_win32compat.py#L4

Consider possible security implications associated with the subprocess module.
import sys

import pytest
Expand Down Expand Up @@ -63,7 +64,9 @@
hard = tmp_path / "target" / "link"
hard.parent.mkdir(parents=True, exist_ok=True)
if sys.platform.startswith("win"):
os.system("mklink /H %s %s" % (str(hard), str(target.resolve())))
cmd_path = r"c:\Windows\System32\cmd.exe"
command = [cmd_path, "/c", "mklink", "/H", str(hard), str(target.resolve())]
subprocess.run(command)

Check warning on line 69 in tests/test_win32compat.py

View check run for this annotation

reviewdog / pylint

[pylint] tests/test_win32compat.py#L69 <1510>

'subprocess.run' used without explicitly defining the value for 'check'. (subprocess-run-check)
Raw output
tests/test_win32compat.py:69:8: W1510: 'subprocess.run' used without explicitly defining the value for 'check'. (subprocess-run-check)

Check failure on line 69 in tests/test_win32compat.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

tests/test_win32compat.py#L69

Detected subprocess function 'run' without a static string.

Check failure on line 69 in tests/test_win32compat.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

tests/test_win32compat.py#L69

Python possesses many mechanisms to invoke an external executable.

Check warning on line 69 in tests/test_win32compat.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

tests/test_win32compat.py#L69

subprocess call - check for execution of untrusted input.
else:
os.link(str(target.resolve()), str(hard))
assert hard.open("r").read() == "Original"
Expand All @@ -82,7 +85,9 @@
f.write("Original")
junction = tmp_path / "target" / "link"
junction.parent.mkdir(parents=True, exist_ok=True)
os.system("mklink /J %s %s" % (str(junction), str(target.resolve())))
cmd_path = r"c:\Windows\System32\cmd.exe"
command = [cmd_path, "/c", "mklink", "/J", str(junction), str(target.resolve())]
subprocess.run(command)

Check warning on line 90 in tests/test_win32compat.py

View check run for this annotation

reviewdog / pylint

[pylint] tests/test_win32compat.py#L90 <1510>

'subprocess.run' used without explicitly defining the value for 'check'. (subprocess-run-check)
Raw output
tests/test_win32compat.py:90:4: W1510: 'subprocess.run' used without explicitly defining the value for 'check'. (subprocess-run-check)
assert not os.path.islink(str(junction))
assert py7zr.win32compat.is_reparse_point(str(junction))
assert py7zr.win32compat.readlink(str(junction)) == PATH_PREFIX + str(target.resolve())
Expand Down
Loading