From bf0c2e77fb01678166ac808e02ed40322210ff6f Mon Sep 17 00:00:00 2001 From: Angelo Dell'Aera Date: Fri, 8 Nov 2024 09:14:28 +0100 Subject: [PATCH 01/14] [Unit tests] MongoDB logging --- .github/workflows/linux.yml | 7 ++- pyproject.toml | 1 - tests/Logging/modules/test_MongoDB.py | 90 ++++++++++++++++++++++----- 3 files changed, 79 insertions(+), 19 deletions(-) diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 2b21cc4cb9..975f642b0b 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -62,11 +62,14 @@ jobs: with: elasticsearch version: '8.8.0' - - name: STEP 9. Test Thug + - name: STEP 9. Setup MongoDB + uses: DigiPie/mongo-action@v2.0.1 + + - name: STEP 10. Test Thug run: | tox - - name: STEP 10. Upload coverage report to Codecov + - name: STEP 11. Upload coverage report to Codecov uses: codecov/codecov-action@v4 with: token: ${{ secrets.CODECOV_TOKEN }} diff --git a/pyproject.toml b/pyproject.toml index b634c31c01..93743accea 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -96,7 +96,6 @@ documentation = [ test = [ "thug[elasticsearch,exploitgraph,image,shellcode]", "mock", - "mongomock", "pydantic>=2.9.2", "pre-commit", "pytest", diff --git a/tests/Logging/modules/test_MongoDB.py b/tests/Logging/modules/test_MongoDB.py index 983f3355f8..f485bdbaca 100644 --- a/tests/Logging/modules/test_MongoDB.py +++ b/tests/Logging/modules/test_MongoDB.py @@ -1,9 +1,8 @@ # coding=utf-8 +import os import logging -import pymongo -from mock import patch -import mongomock +import pytest import thug from thug.ThugAPI.ThugOpts import ThugOpts @@ -27,6 +26,11 @@ log.PyHooks = dict() +IN_GITHUB_ACTIONS = os.getenv("GITHUB_ACTIONS") == "true" and os.getenv( + "RUNNER_OS" +) in ("Linux",) + + class TestMongoDB: cve = "CVE-XXXX" url = "www.example.com" @@ -56,24 +60,19 @@ class TestMongoDB: dest = "www.ex2.com" con_method = "iframe" - # Creating a MongoDB object for all the test methods. - with ( - patch(pymongo.__name__ + ".MongoClient", new=mongomock.MongoClient), - patch("gridfs.Database", new=mongomock.database.Database), - ): - log.ThugOpts.mongodb_address = "mongodb://localhost:123" - mongo = MongoDB() - log.ThugOpts.mongodb_address = None - - @patch(pymongo.__name__ + ".MongoClient", new=mongomock.MongoClient) - @patch("gridfs.Database", new=mongomock.database.Database) + @pytest.mark.skipif( + not (IN_GITHUB_ACTIONS), reason="Test works just in Github Actions (Linux)" + ) def test_address(self): - log.ThugOpts.mongodb_address = "syntax-error://localhost:123" + log.ThugOpts.mongodb_address = "syntax-error://localhost:27017" mongo = MongoDB() log.ThugOpts.mongodb_address = None assert not mongo.enabled + @pytest.mark.skipif( + not (IN_GITHUB_ACTIONS), reason="Test works just in Github Actions (Linux)" + ) def test_init(self): """ Testing for conf file 'thug.conf' @@ -81,11 +80,17 @@ def test_init(self): mongo = MongoDB() assert not mongo.enabled + @pytest.mark.skipif( + not (IN_GITHUB_ACTIONS), reason="Test works just in Github Actions (Linux)" + ) def test_make_counter(self): counter = self.mongo.make_counter(2) assert next(counter) in (2,) assert next(counter) in (3,) + @pytest.mark.skipif( + not (IN_GITHUB_ACTIONS), reason="Test works just in Github Actions (Linux)" + ) def test_get_url(self): assert self.mongo.urls.count_documents({}) in (0,) @@ -96,6 +101,9 @@ def test_get_url(self): self.mongo.get_url(self.url) assert self.mongo.urls.count_documents({}) in (1,) + @pytest.mark.skipif( + not (IN_GITHUB_ACTIONS), reason="Test works just in Github Actions (Linux)" + ) def test_set_url(self): self.mongo.enabled = False self.mongo.set_url(self.url) @@ -111,6 +119,9 @@ def test_set_url(self): assert analysis assert self.mongo.analyses.count_documents({}) in (1,) + @pytest.mark.skipif( + not (IN_GITHUB_ACTIONS), reason="Test works just in Github Actions (Linux)" + ) def test_log_location(self): self.mongo.enabled = False self.mongo.log_location(self.url, self.file_data) @@ -120,6 +131,9 @@ def test_log_location(self): self.mongo.log_location(self.url, self.file_data) assert self.mongo.locations.count_documents({}) in (1,) + @pytest.mark.skipif( + not (IN_GITHUB_ACTIONS), reason="Test works just in Github Actions (Linux)" + ) def test_log_connection(self): self.mongo.enabled = False self.mongo.log_connection(self.source, self.dest, self.con_method) @@ -133,6 +147,9 @@ def test_log_connection(self): assert self.source in nodes assert self.dest in nodes + @pytest.mark.skipif( + not (IN_GITHUB_ACTIONS), reason="Test works just in Github Actions (Linux)" + ) def test_log_exploit_event(self): self.mongo.enabled = False self.mongo.log_exploit_event(self.url, "ActiveX", self.desc, self.cve) @@ -142,6 +159,9 @@ def test_log_exploit_event(self): self.mongo.log_exploit_event(self.url, "ActiveX", self.desc, self.cve) assert self.mongo.exploits.count_documents({}) in (1,) + @pytest.mark.skipif( + not (IN_GITHUB_ACTIONS), reason="Test works just in Github Actions (Linux)" + ) def test_log_image_ocr(self): self.mongo.enabled = False self.mongo.log_image_ocr(self.url, "Test") @@ -151,6 +171,9 @@ def test_log_image_ocr(self): self.mongo.log_image_ocr(self.url, "Test") assert self.mongo.images.count_documents({}) in (1,) + @pytest.mark.skipif( + not (IN_GITHUB_ACTIONS), reason="Test works just in Github Actions (Linux)" + ) def test_log_classifier(self): self.mongo.enabled = False self.mongo.log_classifier("exploit", self.url, self.cve, self.tag) @@ -160,7 +183,9 @@ def test_log_classifier(self): self.mongo.log_classifier("exploit", self.url, self.cve, self.tag) assert self.mongo.classifiers.count_documents({}) in (1,) - @patch("gridfs.grid_file.Collection", new=mongomock.collection.Collection) + @pytest.mark.skipif( + not (IN_GITHUB_ACTIONS), reason="Test works just in Github Actions (Linux)" + ) def test_log_file(self): self.mongo.enabled = False self.mongo.log_file(self.file_data) @@ -174,6 +199,9 @@ def test_log_file(self): self.mongo.log_file(self.file_data) assert self.mongo.samples.count_documents({}) in (1,) + @pytest.mark.skipif( + not (IN_GITHUB_ACTIONS), reason="Test works just in Github Actions (Linux)" + ) def test_log_json(self): self.mongo.enabled = False self.mongo.log_json(self.base_dir) @@ -190,6 +218,9 @@ def test_log_json(self): log.ThugOpts.json_logging = False assert self.mongo.json.count_documents({}) in (0,) + @pytest.mark.skipif( + not (IN_GITHUB_ACTIONS), reason="Test works just in Github Actions (Linux)" + ) def test_log_screenshot(self): self.mongo.enabled = False self.mongo.log_screenshot(self.url, self.data) @@ -200,6 +231,9 @@ def test_log_screenshot(self): self.mongo.log_screenshot(self.url, self.data) assert self.mongo.screenshots.count_documents({}) in (1,) + @pytest.mark.skipif( + not (IN_GITHUB_ACTIONS), reason="Test works just in Github Actions (Linux)" + ) def test_log_event(self): self.mongo.enabled = False self.mongo.log_event(self.base_dir) @@ -209,6 +243,9 @@ def test_log_event(self): self.mongo.log_event(self.base_dir) assert self.mongo.graphs.count_documents({}) in (1,) + @pytest.mark.skipif( + not (IN_GITHUB_ACTIONS), reason="Test works just in Github Actions (Linux)" + ) def test_fix(self): encoded_data = self.mongo.fix("") assert "" in (encoded_data,) @@ -219,6 +256,9 @@ def test_fix(self): encoded_data = self.mongo.fix("sample\n-\ncontent(í)", drop_spaces=False) assert "sample\n-\ncontent(í)" in (encoded_data,) + @pytest.mark.skipif( + not (IN_GITHUB_ACTIONS), reason="Test works just in Github Actions (Linux)" + ) def test_add_code_snippet(self): self.mongo.enabled = False self.mongo.add_code_snippet( @@ -232,6 +272,9 @@ def test_add_code_snippet(self): ) assert self.mongo.codes.count_documents({}) in (1,) + @pytest.mark.skipif( + not (IN_GITHUB_ACTIONS), reason="Test works just in Github Actions (Linux)" + ) def test_add_shellcode_snippet(self): self.mongo.codes.delete_many({}) self.mongo.enabled = False @@ -246,6 +289,9 @@ def test_add_shellcode_snippet(self): ) assert self.mongo.codes.count_documents({}) in (1,) + @pytest.mark.skipif( + not (IN_GITHUB_ACTIONS), reason="Test works just in Github Actions (Linux)" + ) def test_add_behaviour_warn(self): self.mongo.enabled = False self.mongo.add_behavior_warn(self.desc, self.cve, self.code_snippet) @@ -258,6 +304,9 @@ def test_add_behaviour_warn(self): self.mongo.add_behavior_warn() assert self.mongo.behaviors.count_documents({}) in (1,) + @pytest.mark.skipif( + not (IN_GITHUB_ACTIONS), reason="Test works just in Github Actions (Linux)" + ) def test_log_certificate(self): self.mongo.enabled = False self.mongo.log_certificate(self.url, self.cert) @@ -267,12 +316,18 @@ def test_log_certificate(self): self.mongo.log_certificate(self.url, self.cert) assert self.mongo.certificates.count_documents({}) in (1,) + @pytest.mark.skipif( + not (IN_GITHUB_ACTIONS), reason="Test works just in Github Actions (Linux)" + ) def test_log_honeyagent(self): assert self.mongo.honeyagent.count_documents({}) in (0,) self.mongo.log_honeyagent(self.file_data, "sample-report") assert self.mongo.honeyagent.count_documents({}) in (1,) + @pytest.mark.skipif( + not (IN_GITHUB_ACTIONS), reason="Test works just in Github Actions (Linux)" + ) def test_log_cookies(self): assert self.mongo.cookies.count_documents({}) in (0,) @@ -280,6 +335,9 @@ def test_log_cookies(self): self.mongo.log_cookies() assert self.mongo.honeyagent.count_documents({}) in (1,) + @pytest.mark.skipif( + not (IN_GITHUB_ACTIONS), reason="Test works just in Github Actions (Linux)" + ) def test_log_favicon(self): self.mongo.enabled = False self.mongo.log_favicon(self.url, self.favicon_dhash) From d1bfe3e900820d7ad70f1a5b1047ec9983402166 Mon Sep 17 00:00:00 2001 From: Angelo Dell'Aera Date: Fri, 8 Nov 2024 09:23:14 +0100 Subject: [PATCH 02/14] Minor fixes --- tests/Logging/modules/test_MongoDB.py | 252 ++++++++++++++------------ 1 file changed, 136 insertions(+), 116 deletions(-) diff --git a/tests/Logging/modules/test_MongoDB.py b/tests/Logging/modules/test_MongoDB.py index f485bdbaca..045614b168 100644 --- a/tests/Logging/modules/test_MongoDB.py +++ b/tests/Logging/modules/test_MongoDB.py @@ -84,7 +84,8 @@ def test_init(self): not (IN_GITHUB_ACTIONS), reason="Test works just in Github Actions (Linux)" ) def test_make_counter(self): - counter = self.mongo.make_counter(2) + mongo = MongoDB() + counter = mongo.make_counter(2) assert next(counter) in (2,) assert next(counter) in (3,) @@ -92,58 +93,62 @@ def test_make_counter(self): not (IN_GITHUB_ACTIONS), reason="Test works just in Github Actions (Linux)" ) def test_get_url(self): - assert self.mongo.urls.count_documents({}) in (0,) + mongo = MongoDB() + assert mongo.urls.count_documents({}) in (0,) - self.mongo.get_url(self.url) - assert self.mongo.urls.count_documents({}) in (1,) + mongo.get_url(self.url) + assert mongo.urls.count_documents({}) in (1,) # Testing for Duplicate entry - self.mongo.get_url(self.url) - assert self.mongo.urls.count_documents({}) in (1,) + mongo.get_url(self.url) + assert mongo.urls.count_documents({}) in (1,) @pytest.mark.skipif( not (IN_GITHUB_ACTIONS), reason="Test works just in Github Actions (Linux)" ) def test_set_url(self): - self.mongo.enabled = False - self.mongo.set_url(self.url) - assert self.mongo.analyses.count_documents({}) in (0,) + mongo = MongoDB() + mongo.enabled = False + mongo.set_url(self.url) + assert mongo.analyses.count_documents({}) in (0,) - self.mongo.enabled = True + mongo.enabled = True log.ThugVulnModules.disable_acropdf() - self.mongo.set_url(self.url) + mongo.set_url(self.url) log.ThugVulnModules._acropdf_disabled = ( False # TODO: Have enable_acropdf() function? ) - analysis = self.mongo.analyses.find_one({"thug.plugins.acropdf": "disabled"}) + analysis = mongo.analyses.find_one({"thug.plugins.acropdf": "disabled"}) assert analysis - assert self.mongo.analyses.count_documents({}) in (1,) + assert mongo.analyses.count_documents({}) in (1,) @pytest.mark.skipif( not (IN_GITHUB_ACTIONS), reason="Test works just in Github Actions (Linux)" ) def test_log_location(self): - self.mongo.enabled = False - self.mongo.log_location(self.url, self.file_data) - assert self.mongo.locations.count_documents({}) in (0,) + mongo = MongoDB() + mongo.enabled = False + mongo.log_location(self.url, self.file_data) + assert mongo.locations.count_documents({}) in (0,) - self.mongo.enabled = True - self.mongo.log_location(self.url, self.file_data) - assert self.mongo.locations.count_documents({}) in (1,) + mongo.enabled = True + mongo.log_location(self.url, self.file_data) + assert mongo.locations.count_documents({}) in (1,) @pytest.mark.skipif( not (IN_GITHUB_ACTIONS), reason="Test works just in Github Actions (Linux)" ) def test_log_connection(self): - self.mongo.enabled = False - self.mongo.log_connection(self.source, self.dest, self.con_method) - assert self.mongo.connections.count_documents({}) in (0,) + mongo = MongoDB() + mongo.enabled = False + mongo.log_connection(self.source, self.dest, self.con_method) + assert mongo.connections.count_documents({}) in (0,) - self.mongo.enabled = True - self.mongo.log_connection(self.source, self.dest, self.con_method) - assert self.mongo.connections.count_documents({}) in (1,) + mongo.enabled = True + mongo.log_connection(self.source, self.dest, self.con_method) + assert mongo.connections.count_documents({}) in (1,) - nodes = self.mongo.graph.G.nodes + nodes = mongo.graph.G.nodes assert self.source in nodes assert self.dest in nodes @@ -151,198 +156,213 @@ def test_log_connection(self): not (IN_GITHUB_ACTIONS), reason="Test works just in Github Actions (Linux)" ) def test_log_exploit_event(self): - self.mongo.enabled = False - self.mongo.log_exploit_event(self.url, "ActiveX", self.desc, self.cve) - assert self.mongo.exploits.count_documents({}) in (0,) + mongo = MongoDB() + mongo.enabled = False + mongo.log_exploit_event(self.url, "ActiveX", self.desc, self.cve) + assert mongo.exploits.count_documents({}) in (0,) - self.mongo.enabled = True - self.mongo.log_exploit_event(self.url, "ActiveX", self.desc, self.cve) - assert self.mongo.exploits.count_documents({}) in (1,) + mongo.enabled = True + mongo.log_exploit_event(self.url, "ActiveX", self.desc, self.cve) + assert mongo.exploits.count_documents({}) in (1,) @pytest.mark.skipif( not (IN_GITHUB_ACTIONS), reason="Test works just in Github Actions (Linux)" ) def test_log_image_ocr(self): - self.mongo.enabled = False - self.mongo.log_image_ocr(self.url, "Test") - assert self.mongo.images.count_documents({}) in (0,) + mongo = MongoDB() + mongo.enabled = False + mongo.log_image_ocr(self.url, "Test") + assert mongo.images.count_documents({}) in (0,) - self.mongo.enabled = True - self.mongo.log_image_ocr(self.url, "Test") - assert self.mongo.images.count_documents({}) in (1,) + mongo.enabled = True + mongo.log_image_ocr(self.url, "Test") + assert mongo.images.count_documents({}) in (1,) @pytest.mark.skipif( not (IN_GITHUB_ACTIONS), reason="Test works just in Github Actions (Linux)" ) def test_log_classifier(self): - self.mongo.enabled = False - self.mongo.log_classifier("exploit", self.url, self.cve, self.tag) - assert self.mongo.classifiers.count_documents({}) in (0,) + mongo = MongoDB() + mongo.enabled = False + mongo.log_classifier("exploit", self.url, self.cve, self.tag) + assert mongo.classifiers.count_documents({}) in (0,) - self.mongo.enabled = True - self.mongo.log_classifier("exploit", self.url, self.cve, self.tag) - assert self.mongo.classifiers.count_documents({}) in (1,) + mongo.enabled = True + mongo.log_classifier("exploit", self.url, self.cve, self.tag) + assert mongo.classifiers.count_documents({}) in (1,) @pytest.mark.skipif( not (IN_GITHUB_ACTIONS), reason="Test works just in Github Actions (Linux)" ) def test_log_file(self): - self.mongo.enabled = False - self.mongo.log_file(self.file_data) - assert self.mongo.samples.count_documents({}) in (0,) + mongo = MongoDB() + mongo.enabled = False + mongo.log_file(self.file_data) + assert mongo.samples.count_documents({}) in (0,) - self.mongo.enabled = True - self.mongo.log_file(self.file_data) - assert self.mongo.samples.count_documents({}) in (1,) + mongo.enabled = True + mongo.log_file(self.file_data) + assert mongo.samples.count_documents({}) in (1,) # Testing for duplicate entry - self.mongo.log_file(self.file_data) - assert self.mongo.samples.count_documents({}) in (1,) + mongo.log_file(self.file_data) + assert mongo.samples.count_documents({}) in (1,) @pytest.mark.skipif( not (IN_GITHUB_ACTIONS), reason="Test works just in Github Actions (Linux)" ) def test_log_json(self): - self.mongo.enabled = False - self.mongo.log_json(self.base_dir) - assert self.mongo.json.count_documents({}) in (0,) + mongo = MongoDB() + mongo.enabled = False + mongo.log_json(self.base_dir) + assert mongo.json.count_documents({}) in (0,) - # Setting self.mongo.enabled = True - self.mongo.enabled = True - self.mongo.log_json(self.base_dir) - assert self.mongo.json.count_documents({}) in (0,) + # Setting mongo.enabled = True + mongo.enabled = True + mongo.log_json(self.base_dir) + assert mongo.json.count_documents({}) in (0,) # Enabling json_logging log.ThugOpts.json_logging = True - self.mongo.log_json(self.base_dir) + mongo.log_json(self.base_dir) log.ThugOpts.json_logging = False - assert self.mongo.json.count_documents({}) in (0,) + assert mongo.json.count_documents({}) in (0,) @pytest.mark.skipif( not (IN_GITHUB_ACTIONS), reason="Test works just in Github Actions (Linux)" ) def test_log_screenshot(self): - self.mongo.enabled = False - self.mongo.log_screenshot(self.url, self.data) - assert self.mongo.screenshots.count_documents({}) in (0,) + mongo = MongoDB() + mongo.enabled = False + mongo.log_screenshot(self.url, self.data) + assert mongo.screenshots.count_documents({}) in (0,) - # Setting self.mongo.enabled = True - self.mongo.enabled = True - self.mongo.log_screenshot(self.url, self.data) - assert self.mongo.screenshots.count_documents({}) in (1,) + # Setting mongo.enabled = True + mongo.enabled = True + mongo.log_screenshot(self.url, self.data) + assert mongo.screenshots.count_documents({}) in (1,) @pytest.mark.skipif( not (IN_GITHUB_ACTIONS), reason="Test works just in Github Actions (Linux)" ) def test_log_event(self): - self.mongo.enabled = False - self.mongo.log_event(self.base_dir) - assert self.mongo.graphs.count_documents({}) in (0,) + mongo = MongoDB() + mongo.enabled = False + mongo.log_event(self.base_dir) + assert mongo.graphs.count_documents({}) in (0,) - self.mongo.enabled = True - self.mongo.log_event(self.base_dir) - assert self.mongo.graphs.count_documents({}) in (1,) + mongo.enabled = True + mongo.log_event(self.base_dir) + assert mongo.graphs.count_documents({}) in (1,) @pytest.mark.skipif( not (IN_GITHUB_ACTIONS), reason="Test works just in Github Actions (Linux)" ) def test_fix(self): - encoded_data = self.mongo.fix("") + mongo = MongoDB() + encoded_data = mongo.fix("") assert "" in (encoded_data,) - encoded_data = self.mongo.fix("sample\n-\ncontent") + encoded_data = mongo.fix("sample\n-\ncontent") assert "sample-content" in (encoded_data,) - encoded_data = self.mongo.fix("sample\n-\ncontent(í)", drop_spaces=False) + encoded_data = mongo.fix("sample\n-\ncontent(í)", drop_spaces=False) assert "sample\n-\ncontent(í)" in (encoded_data,) @pytest.mark.skipif( not (IN_GITHUB_ACTIONS), reason="Test works just in Github Actions (Linux)" ) def test_add_code_snippet(self): - self.mongo.enabled = False - self.mongo.add_code_snippet( + mongo = MongoDB() + mongo.enabled = False + mongo.add_code_snippet( self.code_snippet, self.language, self.relationship, self.tag ) - assert self.mongo.codes.count_documents({}) in (0,) + assert mongo.codes.count_documents({}) in (0,) - self.mongo.enabled = True - self.mongo.add_code_snippet( + mongo.enabled = True + mongo.add_code_snippet( self.code_snippet, self.language, self.relationship, self.tag ) - assert self.mongo.codes.count_documents({}) in (1,) + assert mongo.codes.count_documents({}) in (1,) @pytest.mark.skipif( not (IN_GITHUB_ACTIONS), reason="Test works just in Github Actions (Linux)" ) def test_add_shellcode_snippet(self): - self.mongo.codes.delete_many({}) - self.mongo.enabled = False - self.mongo.add_shellcode_snippet( + mongo = MongoDB() + mongo.codes.delete_many({}) + mongo.enabled = False + mongo.add_shellcode_snippet( self.code_snippet, self.language, self.relationship, self.tag ) - assert self.mongo.codes.count_documents({}) in (0,) + assert mongo.codes.count_documents({}) in (0,) - self.mongo.enabled = True - self.mongo.add_shellcode_snippet( + mongo.enabled = True + mongo.add_shellcode_snippet( self.code_snippet, self.language, self.relationship, self.tag ) - assert self.mongo.codes.count_documents({}) in (1,) + assert mongo.codes.count_documents({}) in (1,) @pytest.mark.skipif( not (IN_GITHUB_ACTIONS), reason="Test works just in Github Actions (Linux)" ) def test_add_behaviour_warn(self): - self.mongo.enabled = False - self.mongo.add_behavior_warn(self.desc, self.cve, self.code_snippet) - assert self.mongo.behaviors.count_documents({}) in (0,) + mongo = MongoDB() + mongo.enabled = False + mongo.add_behavior_warn(self.desc, self.cve, self.code_snippet) + assert mongo.behaviors.count_documents({}) in (0,) - self.mongo.enabled = True - self.mongo.add_behavior_warn(self.desc, self.cve, self.code_snippet) - assert self.mongo.behaviors.count_documents({}) in (1,) + mongo.enabled = True + mongo.add_behavior_warn(self.desc, self.cve, self.code_snippet) + assert mongo.behaviors.count_documents({}) in (1,) - self.mongo.add_behavior_warn() - assert self.mongo.behaviors.count_documents({}) in (1,) + mongo.add_behavior_warn() + assert mongo.behaviors.count_documents({}) in (1,) @pytest.mark.skipif( not (IN_GITHUB_ACTIONS), reason="Test works just in Github Actions (Linux)" ) def test_log_certificate(self): - self.mongo.enabled = False - self.mongo.log_certificate(self.url, self.cert) - assert self.mongo.certificates.count_documents({}) in (0,) + mongo = MongoDB() + mongo.enabled = False + mongo.log_certificate(self.url, self.cert) + assert mongo.certificates.count_documents({}) in (0,) - self.mongo.enabled = True - self.mongo.log_certificate(self.url, self.cert) - assert self.mongo.certificates.count_documents({}) in (1,) + mongo.enabled = True + mongo.log_certificate(self.url, self.cert) + assert mongo.certificates.count_documents({}) in (1,) @pytest.mark.skipif( not (IN_GITHUB_ACTIONS), reason="Test works just in Github Actions (Linux)" ) def test_log_honeyagent(self): - assert self.mongo.honeyagent.count_documents({}) in (0,) + mongo = MongoDB() + assert mongo.honeyagent.count_documents({}) in (0,) - self.mongo.log_honeyagent(self.file_data, "sample-report") - assert self.mongo.honeyagent.count_documents({}) in (1,) + mongo.log_honeyagent(self.file_data, "sample-report") + assert mongo.honeyagent.count_documents({}) in (1,) @pytest.mark.skipif( not (IN_GITHUB_ACTIONS), reason="Test works just in Github Actions (Linux)" ) def test_log_cookies(self): - assert self.mongo.cookies.count_documents({}) in (0,) + mongo = MongoDB() + assert mongo.cookies.count_documents({}) in (0,) log.HTTPSession.cookies.set("domain", "test.com") - self.mongo.log_cookies() - assert self.mongo.honeyagent.count_documents({}) in (1,) + mongo.log_cookies() + assert mongo.honeyagent.count_documents({}) in (1,) @pytest.mark.skipif( not (IN_GITHUB_ACTIONS), reason="Test works just in Github Actions (Linux)" ) def test_log_favicon(self): - self.mongo.enabled = False - self.mongo.log_favicon(self.url, self.favicon_dhash) - assert self.mongo.favicons.count_documents({}) in (0,) + mongo = MongoDB() + mongo.enabled = False + mongo.log_favicon(self.url, self.favicon_dhash) + assert mongo.favicons.count_documents({}) in (0,) - self.mongo.enabled = True - self.mongo.log_favicon(self.url, self.favicon_dhash) - assert self.mongo.favicons.count_documents({}) in (1,) + mongo.enabled = True + mongo.log_favicon(self.url, self.favicon_dhash) + assert mongo.favicons.count_documents({}) in (1,) From c20872a1f0826cd97f4ff247cd062f1d2b40407b Mon Sep 17 00:00:00 2001 From: Angelo Dell'Aera Date: Fri, 8 Nov 2024 11:11:33 +0100 Subject: [PATCH 03/14] Minor changes --- tests/Logging/modules/test_MongoDB.py | 40 +++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/tests/Logging/modules/test_MongoDB.py b/tests/Logging/modules/test_MongoDB.py index 045614b168..bcca5870fd 100644 --- a/tests/Logging/modules/test_MongoDB.py +++ b/tests/Logging/modules/test_MongoDB.py @@ -84,7 +84,9 @@ def test_init(self): not (IN_GITHUB_ACTIONS), reason="Test works just in Github Actions (Linux)" ) def test_make_counter(self): + log.ThugOpts.mongodb_address = "mongodb://localhost:27017" mongo = MongoDB() + counter = mongo.make_counter(2) assert next(counter) in (2,) assert next(counter) in (3,) @@ -93,7 +95,9 @@ def test_make_counter(self): not (IN_GITHUB_ACTIONS), reason="Test works just in Github Actions (Linux)" ) def test_get_url(self): + log.ThugOpts.mongodb_address = "mongodb://localhost:27017" mongo = MongoDB() + assert mongo.urls.count_documents({}) in (0,) mongo.get_url(self.url) @@ -107,7 +111,9 @@ def test_get_url(self): not (IN_GITHUB_ACTIONS), reason="Test works just in Github Actions (Linux)" ) def test_set_url(self): + log.ThugOpts.mongodb_address = "mongodb://localhost:27017" mongo = MongoDB() + mongo.enabled = False mongo.set_url(self.url) assert mongo.analyses.count_documents({}) in (0,) @@ -126,7 +132,9 @@ def test_set_url(self): not (IN_GITHUB_ACTIONS), reason="Test works just in Github Actions (Linux)" ) def test_log_location(self): + log.ThugOpts.mongodb_address = "mongodb://localhost:27017" mongo = MongoDB() + mongo.enabled = False mongo.log_location(self.url, self.file_data) assert mongo.locations.count_documents({}) in (0,) @@ -139,8 +147,10 @@ def test_log_location(self): not (IN_GITHUB_ACTIONS), reason="Test works just in Github Actions (Linux)" ) def test_log_connection(self): + log.ThugOpts.mongodb_address = "mongodb://localhost:27017" mongo = MongoDB() mongo.enabled = False + mongo.log_connection(self.source, self.dest, self.con_method) assert mongo.connections.count_documents({}) in (0,) @@ -156,7 +166,9 @@ def test_log_connection(self): not (IN_GITHUB_ACTIONS), reason="Test works just in Github Actions (Linux)" ) def test_log_exploit_event(self): + log.ThugOpts.mongodb_address = "mongodb://localhost:27017" mongo = MongoDB() + mongo.enabled = False mongo.log_exploit_event(self.url, "ActiveX", self.desc, self.cve) assert mongo.exploits.count_documents({}) in (0,) @@ -169,7 +181,9 @@ def test_log_exploit_event(self): not (IN_GITHUB_ACTIONS), reason="Test works just in Github Actions (Linux)" ) def test_log_image_ocr(self): + log.ThugOpts.mongodb_address = "mongodb://localhost:27017" mongo = MongoDB() + mongo.enabled = False mongo.log_image_ocr(self.url, "Test") assert mongo.images.count_documents({}) in (0,) @@ -182,7 +196,9 @@ def test_log_image_ocr(self): not (IN_GITHUB_ACTIONS), reason="Test works just in Github Actions (Linux)" ) def test_log_classifier(self): + log.ThugOpts.mongodb_address = "mongodb://localhost:27017" mongo = MongoDB() + mongo.enabled = False mongo.log_classifier("exploit", self.url, self.cve, self.tag) assert mongo.classifiers.count_documents({}) in (0,) @@ -195,7 +211,9 @@ def test_log_classifier(self): not (IN_GITHUB_ACTIONS), reason="Test works just in Github Actions (Linux)" ) def test_log_file(self): + log.ThugOpts.mongodb_address = "mongodb://localhost:27017" mongo = MongoDB() + mongo.enabled = False mongo.log_file(self.file_data) assert mongo.samples.count_documents({}) in (0,) @@ -212,7 +230,9 @@ def test_log_file(self): not (IN_GITHUB_ACTIONS), reason="Test works just in Github Actions (Linux)" ) def test_log_json(self): + log.ThugOpts.mongodb_address = "mongodb://localhost:27017" mongo = MongoDB() + mongo.enabled = False mongo.log_json(self.base_dir) assert mongo.json.count_documents({}) in (0,) @@ -232,7 +252,9 @@ def test_log_json(self): not (IN_GITHUB_ACTIONS), reason="Test works just in Github Actions (Linux)" ) def test_log_screenshot(self): + log.ThugOpts.mongodb_address = "mongodb://localhost:27017" mongo = MongoDB() + mongo.enabled = False mongo.log_screenshot(self.url, self.data) assert mongo.screenshots.count_documents({}) in (0,) @@ -246,7 +268,9 @@ def test_log_screenshot(self): not (IN_GITHUB_ACTIONS), reason="Test works just in Github Actions (Linux)" ) def test_log_event(self): + log.ThugOpts.mongodb_address = "mongodb://localhost:27017" mongo = MongoDB() + mongo.enabled = False mongo.log_event(self.base_dir) assert mongo.graphs.count_documents({}) in (0,) @@ -259,7 +283,9 @@ def test_log_event(self): not (IN_GITHUB_ACTIONS), reason="Test works just in Github Actions (Linux)" ) def test_fix(self): + log.ThugOpts.mongodb_address = "mongodb://localhost:27017" mongo = MongoDB() + encoded_data = mongo.fix("") assert "" in (encoded_data,) @@ -273,7 +299,9 @@ def test_fix(self): not (IN_GITHUB_ACTIONS), reason="Test works just in Github Actions (Linux)" ) def test_add_code_snippet(self): + log.ThugOpts.mongodb_address = "mongodb://localhost:27017" mongo = MongoDB() + mongo.enabled = False mongo.add_code_snippet( self.code_snippet, self.language, self.relationship, self.tag @@ -290,7 +318,9 @@ def test_add_code_snippet(self): not (IN_GITHUB_ACTIONS), reason="Test works just in Github Actions (Linux)" ) def test_add_shellcode_snippet(self): + log.ThugOpts.mongodb_address = "mongodb://localhost:27017" mongo = MongoDB() + mongo.codes.delete_many({}) mongo.enabled = False mongo.add_shellcode_snippet( @@ -308,7 +338,9 @@ def test_add_shellcode_snippet(self): not (IN_GITHUB_ACTIONS), reason="Test works just in Github Actions (Linux)" ) def test_add_behaviour_warn(self): + log.ThugOpts.mongodb_address = "mongodb://localhost:27017" mongo = MongoDB() + mongo.enabled = False mongo.add_behavior_warn(self.desc, self.cve, self.code_snippet) assert mongo.behaviors.count_documents({}) in (0,) @@ -324,7 +356,9 @@ def test_add_behaviour_warn(self): not (IN_GITHUB_ACTIONS), reason="Test works just in Github Actions (Linux)" ) def test_log_certificate(self): + log.ThugOpts.mongodb_address = "mongodb://localhost:27017" mongo = MongoDB() + mongo.enabled = False mongo.log_certificate(self.url, self.cert) assert mongo.certificates.count_documents({}) in (0,) @@ -337,7 +371,9 @@ def test_log_certificate(self): not (IN_GITHUB_ACTIONS), reason="Test works just in Github Actions (Linux)" ) def test_log_honeyagent(self): + log.ThugOpts.mongodb_address = "mongodb://localhost:27017" mongo = MongoDB() + assert mongo.honeyagent.count_documents({}) in (0,) mongo.log_honeyagent(self.file_data, "sample-report") @@ -347,7 +383,9 @@ def test_log_honeyagent(self): not (IN_GITHUB_ACTIONS), reason="Test works just in Github Actions (Linux)" ) def test_log_cookies(self): + log.ThugOpts.mongodb_address = "mongodb://localhost:27017" mongo = MongoDB() + assert mongo.cookies.count_documents({}) in (0,) log.HTTPSession.cookies.set("domain", "test.com") @@ -358,7 +396,9 @@ def test_log_cookies(self): not (IN_GITHUB_ACTIONS), reason="Test works just in Github Actions (Linux)" ) def test_log_favicon(self): + log.ThugOpts.mongodb_address = "mongodb://localhost:27017" mongo = MongoDB() + mongo.enabled = False mongo.log_favicon(self.url, self.favicon_dhash) assert mongo.favicons.count_documents({}) in (0,) From 5834de4d1a52b44b8a26decea315d3c1195d8837 Mon Sep 17 00:00:00 2001 From: Angelo Dell'Aera Date: Fri, 8 Nov 2024 11:52:23 +0100 Subject: [PATCH 04/14] Minor changes --- tests/Logging/modules/test_MongoDB.py | 33 ++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/tests/Logging/modules/test_MongoDB.py b/tests/Logging/modules/test_MongoDB.py index bcca5870fd..d5ad312ef2 100644 --- a/tests/Logging/modules/test_MongoDB.py +++ b/tests/Logging/modules/test_MongoDB.py @@ -136,10 +136,12 @@ def test_log_location(self): mongo = MongoDB() mongo.enabled = False + mongo.set_url(self.url) mongo.log_location(self.url, self.file_data) assert mongo.locations.count_documents({}) in (0,) mongo.enabled = True + mongo.set_url(self.url) mongo.log_location(self.url, self.file_data) assert mongo.locations.count_documents({}) in (1,) @@ -149,12 +151,14 @@ def test_log_location(self): def test_log_connection(self): log.ThugOpts.mongodb_address = "mongodb://localhost:27017" mongo = MongoDB() - mongo.enabled = False + mongo.enabled = False + mongo.set_url(self.url) mongo.log_connection(self.source, self.dest, self.con_method) assert mongo.connections.count_documents({}) in (0,) mongo.enabled = True + mongo.set_url(self.url) mongo.log_connection(self.source, self.dest, self.con_method) assert mongo.connections.count_documents({}) in (1,) @@ -170,10 +174,12 @@ def test_log_exploit_event(self): mongo = MongoDB() mongo.enabled = False + mongo.set_url(self.url) mongo.log_exploit_event(self.url, "ActiveX", self.desc, self.cve) assert mongo.exploits.count_documents({}) in (0,) mongo.enabled = True + mongo.set_url(self.url) mongo.log_exploit_event(self.url, "ActiveX", self.desc, self.cve) assert mongo.exploits.count_documents({}) in (1,) @@ -185,10 +191,12 @@ def test_log_image_ocr(self): mongo = MongoDB() mongo.enabled = False + mongo.set_url(self.url) mongo.log_image_ocr(self.url, "Test") assert mongo.images.count_documents({}) in (0,) mongo.enabled = True + mongo.set_url(self.url) mongo.log_image_ocr(self.url, "Test") assert mongo.images.count_documents({}) in (1,) @@ -200,10 +208,12 @@ def test_log_classifier(self): mongo = MongoDB() mongo.enabled = False + mongo.set_url(self.url) mongo.log_classifier("exploit", self.url, self.cve, self.tag) assert mongo.classifiers.count_documents({}) in (0,) mongo.enabled = True + mongo.set_url(self.url) mongo.log_classifier("exploit", self.url, self.cve, self.tag) assert mongo.classifiers.count_documents({}) in (1,) @@ -215,10 +225,12 @@ def test_log_file(self): mongo = MongoDB() mongo.enabled = False + mongo.set_url(self.url) mongo.log_file(self.file_data) assert mongo.samples.count_documents({}) in (0,) mongo.enabled = True + mongo.set_url(self.url) mongo.log_file(self.file_data) assert mongo.samples.count_documents({}) in (1,) @@ -234,16 +246,19 @@ def test_log_json(self): mongo = MongoDB() mongo.enabled = False + mongo.set_url(self.url) mongo.log_json(self.base_dir) assert mongo.json.count_documents({}) in (0,) # Setting mongo.enabled = True mongo.enabled = True + mongo.set_url(self.url) mongo.log_json(self.base_dir) assert mongo.json.count_documents({}) in (0,) # Enabling json_logging log.ThugOpts.json_logging = True + mongo.set_url(self.url) mongo.log_json(self.base_dir) log.ThugOpts.json_logging = False assert mongo.json.count_documents({}) in (0,) @@ -256,11 +271,13 @@ def test_log_screenshot(self): mongo = MongoDB() mongo.enabled = False + mongo.set_url(self.url) mongo.log_screenshot(self.url, self.data) assert mongo.screenshots.count_documents({}) in (0,) # Setting mongo.enabled = True mongo.enabled = True + mongo.set_url(self.url) mongo.log_screenshot(self.url, self.data) assert mongo.screenshots.count_documents({}) in (1,) @@ -272,10 +289,12 @@ def test_log_event(self): mongo = MongoDB() mongo.enabled = False + mongo.set_url(self.url) mongo.log_event(self.base_dir) assert mongo.graphs.count_documents({}) in (0,) mongo.enabled = True + mongo.set_url(self.url) mongo.log_event(self.base_dir) assert mongo.graphs.count_documents({}) in (1,) @@ -303,12 +322,14 @@ def test_add_code_snippet(self): mongo = MongoDB() mongo.enabled = False + mongo.set_url(self.url) mongo.add_code_snippet( self.code_snippet, self.language, self.relationship, self.tag ) assert mongo.codes.count_documents({}) in (0,) mongo.enabled = True + mongo.set_url(self.url) mongo.add_code_snippet( self.code_snippet, self.language, self.relationship, self.tag ) @@ -323,12 +344,14 @@ def test_add_shellcode_snippet(self): mongo.codes.delete_many({}) mongo.enabled = False + mongo.set_url(self.url) mongo.add_shellcode_snippet( self.code_snippet, self.language, self.relationship, self.tag ) assert mongo.codes.count_documents({}) in (0,) mongo.enabled = True + mongo.set_url(self.url) mongo.add_shellcode_snippet( self.code_snippet, self.language, self.relationship, self.tag ) @@ -342,10 +365,12 @@ def test_add_behaviour_warn(self): mongo = MongoDB() mongo.enabled = False + mongo.set_url(self.url) mongo.add_behavior_warn(self.desc, self.cve, self.code_snippet) assert mongo.behaviors.count_documents({}) in (0,) mongo.enabled = True + mongo.set_url(self.url) mongo.add_behavior_warn(self.desc, self.cve, self.code_snippet) assert mongo.behaviors.count_documents({}) in (1,) @@ -360,10 +385,12 @@ def test_log_certificate(self): mongo = MongoDB() mongo.enabled = False + mongo.set_url(self.url) mongo.log_certificate(self.url, self.cert) assert mongo.certificates.count_documents({}) in (0,) mongo.enabled = True + mongo.set_url(self.url) mongo.log_certificate(self.url, self.cert) assert mongo.certificates.count_documents({}) in (1,) @@ -373,6 +400,7 @@ def test_log_certificate(self): def test_log_honeyagent(self): log.ThugOpts.mongodb_address = "mongodb://localhost:27017" mongo = MongoDB() + mongo.set_url(self.url) assert mongo.honeyagent.count_documents({}) in (0,) @@ -385,6 +413,7 @@ def test_log_honeyagent(self): def test_log_cookies(self): log.ThugOpts.mongodb_address = "mongodb://localhost:27017" mongo = MongoDB() + mongo.set_url(self.url) assert mongo.cookies.count_documents({}) in (0,) @@ -400,9 +429,11 @@ def test_log_favicon(self): mongo = MongoDB() mongo.enabled = False + mongo.set_url(self.url) mongo.log_favicon(self.url, self.favicon_dhash) assert mongo.favicons.count_documents({}) in (0,) mongo.enabled = True + mongo.set_url(self.url) mongo.log_favicon(self.url, self.favicon_dhash) assert mongo.favicons.count_documents({}) in (1,) From ebd9e46d24cb0193cb18b0ab9c8e794339e9efa0 Mon Sep 17 00:00:00 2001 From: Angelo Dell'Aera Date: Fri, 8 Nov 2024 12:07:18 +0100 Subject: [PATCH 05/14] Minor fix --- tests/Logging/modules/test_MongoDB.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Logging/modules/test_MongoDB.py b/tests/Logging/modules/test_MongoDB.py index d5ad312ef2..72e7726a9b 100644 --- a/tests/Logging/modules/test_MongoDB.py +++ b/tests/Logging/modules/test_MongoDB.py @@ -413,7 +413,6 @@ def test_log_honeyagent(self): def test_log_cookies(self): log.ThugOpts.mongodb_address = "mongodb://localhost:27017" mongo = MongoDB() - mongo.set_url(self.url) assert mongo.cookies.count_documents({}) in (0,) From 775dd42185f40f2e3199c28c6a7a46645e7009b1 Mon Sep 17 00:00:00 2001 From: Angelo Dell'Aera Date: Fri, 8 Nov 2024 12:11:16 +0100 Subject: [PATCH 06/14] Revert "Minor fix" This reverts commit ebd9e46d24cb0193cb18b0ab9c8e794339e9efa0. --- tests/Logging/modules/test_MongoDB.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Logging/modules/test_MongoDB.py b/tests/Logging/modules/test_MongoDB.py index 72e7726a9b..d5ad312ef2 100644 --- a/tests/Logging/modules/test_MongoDB.py +++ b/tests/Logging/modules/test_MongoDB.py @@ -413,6 +413,7 @@ def test_log_honeyagent(self): def test_log_cookies(self): log.ThugOpts.mongodb_address = "mongodb://localhost:27017" mongo = MongoDB() + mongo.set_url(self.url) assert mongo.cookies.count_documents({}) in (0,) From 2b6f7f1d3adea257b5eeab9a6480367070865d79 Mon Sep 17 00:00:00 2001 From: Angelo Dell'Aera Date: Fri, 8 Nov 2024 12:11:47 +0100 Subject: [PATCH 07/14] Minor fixes --- tests/Logging/modules/test_MongoDB.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/Logging/modules/test_MongoDB.py b/tests/Logging/modules/test_MongoDB.py index d5ad312ef2..1cadc0a623 100644 --- a/tests/Logging/modules/test_MongoDB.py +++ b/tests/Logging/modules/test_MongoDB.py @@ -400,7 +400,6 @@ def test_log_certificate(self): def test_log_honeyagent(self): log.ThugOpts.mongodb_address = "mongodb://localhost:27017" mongo = MongoDB() - mongo.set_url(self.url) assert mongo.honeyagent.count_documents({}) in (0,) @@ -413,7 +412,6 @@ def test_log_honeyagent(self): def test_log_cookies(self): log.ThugOpts.mongodb_address = "mongodb://localhost:27017" mongo = MongoDB() - mongo.set_url(self.url) assert mongo.cookies.count_documents({}) in (0,) From b2b1df28800686eedef9dae6364c5a7f7c973bd6 Mon Sep 17 00:00:00 2001 From: Angelo Dell'Aera Date: Fri, 8 Nov 2024 12:17:18 +0100 Subject: [PATCH 08/14] Minor fixes --- tests/Logging/modules/test_MongoDB.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/Logging/modules/test_MongoDB.py b/tests/Logging/modules/test_MongoDB.py index 1cadc0a623..d9cb64f43a 100644 --- a/tests/Logging/modules/test_MongoDB.py +++ b/tests/Logging/modules/test_MongoDB.py @@ -401,8 +401,11 @@ def test_log_honeyagent(self): log.ThugOpts.mongodb_address = "mongodb://localhost:27017" mongo = MongoDB() + mongo.enabled = False assert mongo.honeyagent.count_documents({}) in (0,) + mongo.enabled = True + mongo.set_url(self.url) mongo.log_honeyagent(self.file_data, "sample-report") assert mongo.honeyagent.count_documents({}) in (1,) @@ -413,8 +416,12 @@ def test_log_cookies(self): log.ThugOpts.mongodb_address = "mongodb://localhost:27017" mongo = MongoDB() + mongo.enabled = False + mongo.set_url(self.url) assert mongo.cookies.count_documents({}) in (0,) + mongo.enabled = True + mongo.set_url(self.url) log.HTTPSession.cookies.set("domain", "test.com") mongo.log_cookies() assert mongo.honeyagent.count_documents({}) in (1,) From 3081b05620d5b8aa93988ffc806f1928bcaf0059 Mon Sep 17 00:00:00 2001 From: Angelo Dell'Aera Date: Fri, 8 Nov 2024 12:39:58 +0100 Subject: [PATCH 09/14] Minor change --- tests/Logging/modules/test_MongoDB.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/Logging/modules/test_MongoDB.py b/tests/Logging/modules/test_MongoDB.py index d9cb64f43a..85caf90f1b 100644 --- a/tests/Logging/modules/test_MongoDB.py +++ b/tests/Logging/modules/test_MongoDB.py @@ -401,10 +401,8 @@ def test_log_honeyagent(self): log.ThugOpts.mongodb_address = "mongodb://localhost:27017" mongo = MongoDB() - mongo.enabled = False assert mongo.honeyagent.count_documents({}) in (0,) - mongo.enabled = True mongo.set_url(self.url) mongo.log_honeyagent(self.file_data, "sample-report") assert mongo.honeyagent.count_documents({}) in (1,) From ac0e965ee1c8ee786df52cd3a85810b3336bce2c Mon Sep 17 00:00:00 2001 From: Angelo Dell'Aera Date: Fri, 8 Nov 2024 15:21:30 +0100 Subject: [PATCH 10/14] Minor fix --- thug/Logging/modules/MongoDB.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/thug/Logging/modules/MongoDB.py b/thug/Logging/modules/MongoDB.py index 97ed7a6e60..92781fe3fa 100644 --- a/thug/Logging/modules/MongoDB.py +++ b/thug/Logging/modules/MongoDB.py @@ -557,7 +557,7 @@ def log_analysis_module(self, collection, sample, report): "sha1": sample["sha1"], } ) - if not s: # pragma: no cover + if s: # pragma: no cover return r = {"analysis_id": self.analysis_id, "sample_id": s["_id"], "report": report} From f3fc5805f97ab86363ab35c319b2c0e7c81eefa0 Mon Sep 17 00:00:00 2001 From: Angelo Dell'Aera Date: Fri, 8 Nov 2024 15:28:15 +0100 Subject: [PATCH 11/14] Revert "Minor fix" This reverts commit ac0e965ee1c8ee786df52cd3a85810b3336bce2c. --- thug/Logging/modules/MongoDB.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/thug/Logging/modules/MongoDB.py b/thug/Logging/modules/MongoDB.py index 92781fe3fa..97ed7a6e60 100644 --- a/thug/Logging/modules/MongoDB.py +++ b/thug/Logging/modules/MongoDB.py @@ -557,7 +557,7 @@ def log_analysis_module(self, collection, sample, report): "sha1": sample["sha1"], } ) - if s: # pragma: no cover + if not s: # pragma: no cover return r = {"analysis_id": self.analysis_id, "sample_id": s["_id"], "report": report} From 54de71163d23b09ded69291c26a554b3b9dcd3ea Mon Sep 17 00:00:00 2001 From: Angelo Dell'Aera Date: Fri, 8 Nov 2024 15:29:27 +0100 Subject: [PATCH 12/14] Minor fix --- tests/Logging/modules/test_MongoDB.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/Logging/modules/test_MongoDB.py b/tests/Logging/modules/test_MongoDB.py index 85caf90f1b..fee4b4f69c 100644 --- a/tests/Logging/modules/test_MongoDB.py +++ b/tests/Logging/modules/test_MongoDB.py @@ -404,6 +404,8 @@ def test_log_honeyagent(self): assert mongo.honeyagent.count_documents({}) in (0,) mongo.set_url(self.url) + mongo.log_location(self.url, self.file_data) + mongo.log_file(self.file_data) mongo.log_honeyagent(self.file_data, "sample-report") assert mongo.honeyagent.count_documents({}) in (1,) From eace652e44ceffd90f0e155f7f4936447a4565c2 Mon Sep 17 00:00:00 2001 From: Angelo Dell'Aera Date: Fri, 8 Nov 2024 15:37:19 +0100 Subject: [PATCH 13/14] Minor fix --- tests/ThugAPI/test_ThugAPI.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/ThugAPI/test_ThugAPI.py b/tests/ThugAPI/test_ThugAPI.py index 6a65aa0ae2..459fd75ecb 100644 --- a/tests/ThugAPI/test_ThugAPI.py +++ b/tests/ThugAPI/test_ThugAPI.py @@ -279,6 +279,7 @@ def test_log_output(self): assert not os.path.isfile(self.log_file) def test_mongodb_address(self): + log.ThugOpts.mongodb_address = None assert self.thug_api.get_mongodb_address() is None self.thug_api.set_mongodb_address("127.0.0.1:27017") From f45aaeca38bb66c1bfc583bd5e9e8ed3f37424f5 Mon Sep 17 00:00:00 2001 From: Angelo Dell'Aera Date: Fri, 8 Nov 2024 15:49:02 +0100 Subject: [PATCH 14/14] Update requirements --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 93743accea..1a529f9931 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -51,7 +51,7 @@ dependencies = [ "pillow==11.0.0", "promise==2.3", "pylibemu==1.0", - "pymongo==4.8.0", + "pymongo==4.10.1", "pysocks==1.7.1", "python-magic==0.4.27", "rarfile==4.2",