Skip to content

Commit 4719b9f

Browse files
committed
🔧 Melhorando a segurança
- [Codacy] Removendo as vulnerabilidades criticas
1 parent d90d0dc commit 4719b9f

File tree

4 files changed

+20
-15
lines changed

4 files changed

+20
-15
lines changed

encryptdef/VERSION.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.0.1.dev1+g7aff1b9.d20240529
1+
1.0.1.dev7

encryptdef/utils.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@
22

33
import os
44
import re
5-
import subprocess
65
from typing import List
76

7+
from colorama import init
8+
89
from encryptdef.template import TEMPLATE_IS_DIRECTORY
910

11+
# Inicializa colorama para garantir o funcionamento em sistemas Windows
12+
init()
13+
1014

1115
def get_new_file_path(file: str, new_file: str, current_dir: str) -> str:
1216
"""
@@ -91,6 +95,8 @@ def write_file(new_file_path: str, processed_lines: List[str]) -> None:
9195
def clear_console():
9296
"""Limpa o console de forma segura."""
9397
if os.name == "posix":
94-
subprocess.run(["clear"], check=False)
98+
print("\033[H\033[J", end="")
9599
elif os.name == "nt":
96-
subprocess.run(["cls"], shell=True, check=False)
100+
# Inicializa o colorama, que é seguro e portátil
101+
init()
102+
print("\033c", end="")

requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
pycryptodomex >=3.20.0
22
rich-click >=1.8.2
3+
colorama >=0.4.6

tests/test_clear_console.py

+9-11
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
1-
""" Modulo para testar a função clear_console em utils.py"""
1+
"""Modulo para testar a função clear_console em utils.py"""
22

33
from unittest import mock
44

55
from encryptdef.utils import clear_console
66

77

8-
@mock.patch("subprocess.run") # Substitui subprocess.run por um mock
9-
def test_clear_console_posix(mock_run):
10-
"""Test function clear_console"""
8+
@mock.patch("builtins.print")
9+
def test_clear_console_posix(mock_print):
10+
"""Testa a função clear_console em sistemas POSIX"""
1111
with mock.patch("os.name", "posix"):
1212
clear_console()
13+
mock_print.assert_called_once_with("\033[H\033[J", end="")
1314

14-
# Verifica se subprocess.run foi chamado com ["cls"] e check=False
15-
mock_run.assert_called_once_with(["clear"], check=False)
1615

17-
18-
@mock.patch("subprocess.run")
19-
def test_clear_console_nt(mock_run):
20-
"""Test function clear_console"""
16+
@mock.patch("builtins.print")
17+
def test_clear_console_nt(mock_print):
18+
"""Testa a função clear_console em sistemas Windows"""
2119
with mock.patch("os.name", "nt"):
2220
clear_console()
23-
mock_run.assert_called_once_with(["cls"], shell=True, check=False)
21+
mock_print.assert_called_once_with("\033c", end="")

0 commit comments

Comments
 (0)