You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by cc...@apache.org on 2026/10/13 14:22:43 UTC

(allura) 04/04: fixup! [#8625] Implemented full field level encryption for audit log messages

This is an automated email from the ASF dual-hosted git repository.

asf-gitbox-commits pushed a commit to branch cc/8625-part2
in repository https://gitbox.apache.org/repos/asf/allura.git

commit 5b8108ff8c31bb81210ec87ba9a44143abb137cc
Author: Carlos Cruz <ca...@slashdotmedia.com>
AuthorDate: Tue Oct 13 13:33:57 2026 +0000

    fixup! [#8625] Implemented full field level encryption for audit log messages
    
    Share one helper for matching decrypted audit messages in tests
    
    audits(), out_audits() and test_forum_admin each looped over AuditLog
    entries to regex-match the decrypted message. They now share
    matching_audits() in allura.tests.decorators, which also removes the
    unused `re` import from test_forum_admin.
    
    test_encrypted_message_read_and_update no longer repeats the
    no-plaintext check from test_message_encrypted_storage.
---
 Allura/allura/tests/decorators.py                      | 18 +++++++++---------
 Allura/allura/tests/model/test_auth.py                 |  1 -
 .../tests/functional/test_forum_admin.py               |  4 +---
 3 files changed, 10 insertions(+), 13 deletions(-)

diff --git a/Allura/allura/tests/decorators.py b/Allura/allura/tests/decorators.py
index 63d5ae624..aa9cfb334 100644
--- a/Allura/allura/tests/decorators.py
+++ b/Allura/allura/tests/decorators.py
@@ -150,6 +150,12 @@ def __exit__(self, exc_type, exc_val, exc_t):
         allura.config.middleware.make_app = self._make_app
 
 
+def matching_audits(pattern, **query):
+    """AuditLog entries matching ``query`` whose decrypted message matches the ``pattern`` regex"""
+    pattern = re.compile(pattern)
+    return [entry for entry in M.AuditLog.query.find(query) if pattern.search(entry.message or '')]
+
+
 @contextlib.contextmanager
 def audits(*messages, user=False, actor=r'.*', ip_addr=r'.*', user_agent=r'.*', event_type=None):
     """
@@ -168,12 +174,8 @@ def audits(*messages, user=False, actor=r'.*', ip_addr=r'.*', user_agent=r'.*',
         preamble = ''
 
     for message in messages:
-        query = {}
-        pattern = re.compile(preamble + message)
-        if event_type is not None:
-            query['event_type'] = event_type
-        found = any(pattern.search(entry.message or '') for entry in M.AuditLog.query.find(query))
-        if not found:
+        query = {'event_type': event_type} if event_type is not None else {}
+        if not matching_audits(preamble + message, **query):
             hints = ''
             all = M.AuditLog.query.find().all()
             if len(all) < 10:
@@ -199,9 +201,7 @@ def out_audits(*messages, user=False, actor=r'.*', ip_addr=r'.*'):
     else:
         preamble = ''
     for message in messages:
-        pattern = re.compile(preamble + message)
-        assert not any(pattern.search(entry.message or '') for entry in M.AuditLog.query.find()), (
-            'Found unexpected: "%s"' % message)
+        assert not matching_audits(preamble + message), 'Found unexpected: "%s"' % message
 
 
 # not a decorator but use it with LogCapture() context manager
diff --git a/Allura/allura/tests/model/test_auth.py b/Allura/allura/tests/model/test_auth.py
index 892b3d06b..6071a6cc0 100644
--- a/Allura/allura/tests/model/test_auth.py
+++ b/Allura/allura/tests/model/test_auth.py
@@ -745,7 +745,6 @@ def test_encrypted_message_read_and_update(self):
         entry.url = '/updated'
         session(entry).flush(entry)
         raw = M.main_doc_session.db.audit_log.find_one({'_id': entry_id})
-        assert 'message' not in raw
         assert M.AuditLog.decr(raw['message_encrypted']) == 'add user alice to Developer'
         assert raw['event_type'] == 'project.user_mention.unclassified'
 
diff --git a/ForgeDiscussion/forgediscussion/tests/functional/test_forum_admin.py b/ForgeDiscussion/forgediscussion/tests/functional/test_forum_admin.py
index 8ebb15fae..e00f78f10 100644
--- a/ForgeDiscussion/forgediscussion/tests/functional/test_forum_admin.py
+++ b/ForgeDiscussion/forgediscussion/tests/functional/test_forum_admin.py
@@ -17,7 +17,6 @@
 
 import logging
 
-import re
 from ming.odm import ThreadLocalODMSession
 from tg import tmpl_context as c
 from alluratest.controller import TestController
@@ -55,8 +54,7 @@ def test_forum_CRUD(self):
                                   'forum-0.shortname': 'NewTestForum',
                                   'forum-0.description': 'My desc',
                                   'forum-0.monitoring_email': ''})
-        audit_logs = [entry for entry in M.AuditLog.query.find({'project_id': project._id})
-                      if ' set option ' in (entry.message or '')]
+        audit_logs = td.matching_audits(' set option ', project_id=project._id)
         assert len(audit_logs) == 4
         r = self.app.get('/admin/discussion/forums')
         assert 'New Test Forum' in r