Skip to content

Fix: Make OS path logic OS-agnostic using pathlib #1011

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import sys
import os

sys.path.insert(0, os.path.abspath(os.path.dirname(__file__))) # Ensure tests/ is in sys.path
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))) # Ensure project root is in sys.path

9 changes: 0 additions & 9 deletions tests/common.py

This file was deleted.

12 changes: 6 additions & 6 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import sys
from os.path import abspath, dirname, join
from pathlib import Path

project_root = dirname(dirname(__file__))
nettacker_dir = abspath(join(project_root, "src/nettacker"))
tests_dir = abspath(join(project_root, "tests"))
project_root = Path(__file__).resolve().parent.parent
nettacker_dir = project_root / "src" / "nettacker"
tests_dir = project_root / "tests"

sys.path.insert(0, nettacker_dir)
sys.path.insert(1, tests_dir)
sys.path.insert(0, str(nettacker_dir))
sys.path.insert(1, str(tests_dir))
12 changes: 6 additions & 6 deletions tests/lib/payloads/test_passwords.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
from collections import Counter

import pytest

from tests.common import TestCase

from tests.test_common import TestCase

class TestPasswords(TestCase):
top_1000_common_passwords_path = "lib/payloads/passwords/top_1000_common_passwords.txt"

def setUp(self):
super().setUp() # Call parent setup to ensure nettacker_path is set
self.top_1000_common_passwords_path = self.nettacker_path / "lib" / "payloads" / "passwords" / "top_1000_common_passwords.txt"

@pytest.mark.xfail(reason="It currently contains 1001 passwords.")
def test_top_1000_common_passwords(self):
with open(self.nettacker_path / self.top_1000_common_passwords_path) as top_1000_file:
with open(self.top_1000_common_passwords_path) as top_1000_file:
top_1000_passwords = [line.strip() for line in top_1000_file.readlines()]

self.assertEqual(len(top_1000_passwords), 1000, "There should be exactly 1000 passwords")
Expand Down
21 changes: 21 additions & 0 deletions tests/test_common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import unittest
from pathlib import Path

class TestCase(unittest.TestCase):
def setUp(self):
# Fix the paths
self.project_root = Path(__file__).resolve().parent.parent # Go up from 'tests'
self.nettacker_path = self.project_root / "nettacker" # Correct location
self.tests_path = self.project_root / "tests"

# Debugging information
print(f"DEBUG: Expected nettacker_path: {self.nettacker_path}")
print(f"DEBUG: Expected tests_path: {self.tests_path}")

def test_paths_exist(self):
# Check if paths exist
self.assertTrue(self.nettacker_path.exists(), f"Nettacker directory does not exist: {self.nettacker_path}")
self.assertTrue(self.tests_path.exists(), f"Tests directory does not exist: {self.tests_path}")

if __name__ == "__main__":
unittest.main()
Loading