Repository: privacyidea/privacyidea

Issue:
Audit log completely disappears
The audit log vanishes if we filter for s.th. that does not exist.

Try to fillter for "date" and enter "X".
All columns vanish and you can not make them appear again, since you can not remove the X.

This was not the way in 3.4.1 and happens in current master.


Discussion:

Resolving patch:
diff --git a/privacyidea/lib/audit.py b/privacyidea/lib/audit.py
--- a/privacyidea/lib/audit.py
+++ b/privacyidea/lib/audit.py
@@ -92,7 +92,7 @@ def search(config, param=None, user=None):
     page_size = 15
     page = 1
     timelimit = None
-    hidden_columns = None
+    hidden_columns = []
     # The filtering dictionary
     param = param or {}
     # special treatment for:
@@ -122,8 +122,10 @@ def search(config, param=None, user=None):
             pagination.auditdata[i] = OrderedDict({audit_col: value for audit_col, value in
                                                    pagination.auditdata[i].items()
                                                    if audit_col not in hidden_columns})
+    visible_columns = [col for col in audit.available_audit_columns if col not in hidden_columns]
 
     ret = {"auditdata": pagination.auditdata,
+           "auditcolumns": visible_columns,
            "prev": pagination.prev,
            "next": pagination.next,
            "current": pagination.page,
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
@@ -136,6 +136,13 @@ def read_keys(self, pub, priv):
     def get_audit_id(self):
         return self.name
 
+    @property
+    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']
+
     def get_total(self, param, AND=True, display_error=True, timelimit=None):
         """
         This method returns the total number of audit entries


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
@@ -50,6 +50,19 @@ def test_00_get_audit(self):
         self.assertEqual(aentry['action'], 'GET /audit/', aentry)
         self.assertEqual(aentry['success'], 1, aentry)
 
+        # Empty search, like search for a date, that contains X
+        with self.app.test_request_context('/audit/',
+                                           method='GET',
+                                           data={'date': '*X*'},
+                                           headers={'Authorization': self.at}):
+            res = self.app.full_dispatch_request()
+            self.assertTrue(res.status_code == 200, res)
+            json_response = res.json
+            cols = json_response.get("result").get("value").get("auditcolumns")
+            self.assertIn("number", cols)
+            self.assertIn("serial", cols)
+            self.assertEqual(18, len(cols))
+
     def test_01_get_audit_csv(self):
         @contextmanager
         def _fake_time(t):