Repository: privacyidea/privacyidea

Issue:
Make signature and missing line entries visible in audit log
The `Signature` and `Missing Line` fields in the audit log were removed in #2532 since they weren't included in the newly introduced `available_audit_columns` property.



Discussion:

Resolving patch:
diff --git a/privacyidea/lib/auditmodules/base.py b/privacyidea/lib/auditmodules/base.py
--- a/privacyidea/lib/auditmodules/base.py
+++ b/privacyidea/lib/auditmodules/base.py
@@ -141,7 +141,8 @@ def available_audit_columns(self):
         return ['number', 'action', 'success', 'serial', 'date', 'startdate',
                 'duration', 'token_type', 'user', 'realm', 'administrator',
                 'action_detail', 'info', 'privacyidea_server', 'client',
-                'loglevel', 'policies', 'clearance_level']
+                'log_level', 'policies', 'clearance_level', 'sig_check',
+                'missing_line', 'resolver']
 
     def get_total(self, param, AND=True, display_error=True, timelimit=None):
         """
diff --git a/privacyidea/lib/auditmodules/sqlaudit.py b/privacyidea/lib/auditmodules/sqlaudit.py
--- a/privacyidea/lib/auditmodules/sqlaudit.py
+++ b/privacyidea/lib/auditmodules/sqlaudit.py
@@ -402,7 +402,7 @@ def _get_logentry_attribute(key):
                     'info': LogEntry.info,
                     'privacyidea_server': LogEntry.privacyidea_server,
                     'client': LogEntry.client,
-                    'loglevel': LogEntry.loglevel,
+                    'log_level': LogEntry.loglevel,
                     'policies': LogEntry.policies,
                     'clearance_level': LogEntry.clearance_level}
         return sortname.get(key)


Test patch:
diff --git a/tests/test_api_audit.py b/tests/test_api_audit.py
--- a/tests/test_api_audit.py
+++ b/tests/test_api_audit.py
@@ -9,6 +9,7 @@
 from privacyidea.models import Audit
 from privacyidea.lib.resolver import save_resolver
 from privacyidea.lib.realm import set_realm
+from privacyidea.lib.auditmodules.base import Audit as BaseAudit
 
 PWFILE = "tests/testdata/passwords"
 
@@ -45,6 +46,18 @@ def test_00_get_audit(self):
             self.assertTrue(json_response.get("result").get("status"), res)
             self.assertTrue(json_response.get("result").get("value").get(
                 "current") == 1, res)
+            # check that we have all available entries in the audit data
+            # create a fake base Audit object to get the available_columns prop
+            a = BaseAudit()
+            self.assertEqual(set(json_response['result']['value']['auditcolumns']),
+                             set(a.available_audit_columns),
+                             json_response['result']['value']['auditcolumns'])
+            self.assertEqual(set(json_response['result']['value']['auditdata'][0].keys()),
+                             set(a.available_audit_columns),
+                             json_response['result']['value']['auditcolumns'])
+
+        # TODO: test audit columns if HIDE_AUDIT_COLUMNS policy is set.
+
         # check for entry in audit log
         aentry = self.find_most_recent_audit_entry(action='GET /audit/')
         self.assertEqual(aentry['action'], 'GET /audit/', aentry)
@@ -61,7 +74,7 @@ def test_00_get_audit(self):
             cols = json_response.get("result").get("value").get("auditcolumns")
             self.assertIn("number", cols)
             self.assertIn("serial", cols)
-            self.assertEqual(18, len(cols))
+            self.assertEqual(21, len(cols))
 
     def test_01_get_audit_csv(self):
         @contextmanager
diff --git a/tests/test_lib_audit.py b/tests/test_lib_audit.py
--- a/tests/test_lib_audit.py
+++ b/tests/test_lib_audit.py
@@ -317,6 +317,16 @@ def test_10_check_tokentype(self):
         # The tokentype was actually written as token_type
         self.assertEqual(audit_log.auditdata[0].get("token_type"), "spass")
 
+    def test_11_check_audit_columns(self):
+        self.Audit.log({"action": "test11"})
+        self.Audit.finalize_log()
+        audit_log = self.Audit.search({"action": "test11"})
+        self.assertEqual(audit_log.total, 1)
+        # The tokentype was actually written as token_type
+        self.assertEqual(set(audit_log.auditdata[0].keys()),
+                         set(self.Audit.available_audit_columns),
+                         audit_log.auditdata[0].keys())
+
 
 class AuditColumnLengthTestCase(OverrideConfigTestCase):
     class Config(TestingConfig):