Skip to content

Commit

Permalink
🔧 Melhorando a segurança (#10)
Browse files Browse the repository at this point in the history
- [Codacy] Removendo as vulnerabilidades criticas
  • Loading branch information
AyslanBatista authored Jun 1, 2024
1 parent d90d0dc commit c2f86da
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
run: pip install '.[test,dev]' # instalando o programa em forma de test

- name: Typing
run: mypy encryptdef
run: mypy --ignore-missing-imports encryptdef

- name: Look for style erros
run: pflake8 # Rodando o flake para verificar se tem erro de formatação
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ virtualenv: ## Criar ambiente virtual e instalar dependências

lint: ## Executar linters
@echo "Executando linters..."
@$(VENV_BIN)/mypy encryptdef
@$(VENV_BIN)/mypy --ignore-missing-imports encryptdef
@$(VENV_BIN)/pflake8

fmt: ## Formatar código
Expand Down
2 changes: 1 addition & 1 deletion encryptdef/VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.1.dev1+g7aff1b9.d20240529
1.0.1.dev7
12 changes: 9 additions & 3 deletions encryptdef/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@

import os
import re
import subprocess
from typing import List

from colorama import init

from encryptdef.template import TEMPLATE_IS_DIRECTORY

# Inicializa colorama para garantir o funcionamento em sistemas Windows
init()


def get_new_file_path(file: str, new_file: str, current_dir: str) -> str:
"""
Expand Down Expand Up @@ -91,6 +95,8 @@ def write_file(new_file_path: str, processed_lines: List[str]) -> None:
def clear_console():
"""Limpa o console de forma segura."""
if os.name == "posix":
subprocess.run(["clear"], check=False)
print("\033[H\033[J", end="")
elif os.name == "nt":
subprocess.run(["cls"], shell=True, check=False)
# Inicializa o colorama, que é seguro e portátil
init()
print("\033c", end="")
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pycryptodomex >=3.20.0
rich-click >=1.8.2
colorama >=0.4.6
20 changes: 9 additions & 11 deletions tests/test_clear_console.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
""" Modulo para testar a função clear_console em utils.py"""
"""Modulo para testar a função clear_console em utils.py"""

from unittest import mock

from encryptdef.utils import clear_console


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

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


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

0 comments on commit c2f86da

Please sign in to comment.