|
@@ -76,31 +76,26 @@ def test_audit_logging_middleware_enable():
|
|
|
c = make_logged_in_client(username='test_audit_logging_middleware_enable', is_superuser=False)
|
|
c = make_logged_in_client(username='test_audit_logging_middleware_enable', is_superuser=False)
|
|
|
|
|
|
|
|
# Make sure we enable it with a file path
|
|
# Make sure we enable it with a file path
|
|
|
- log_tmp = tempfile.NamedTemporaryFile("w+t") # Get a tempfile path
|
|
|
|
|
- log_path = log_tmp.name
|
|
|
|
|
- log_tmp.close()
|
|
|
|
|
- reset = AUDIT_EVENT_LOG_DIR.set_for_testing(log_path)
|
|
|
|
|
- settings.MIDDLEWARE_CLASSES.append('desktop.middleware.AuditLoggingMiddleware') # Re-add middleware
|
|
|
|
|
|
|
+ with tempfile.NamedTemporaryFile("w+t") as log_tmp:
|
|
|
|
|
+ log_path = log_tmp.name
|
|
|
|
|
+ reset = AUDIT_EVENT_LOG_DIR.set_for_testing(log_path)
|
|
|
|
|
+ settings.MIDDLEWARE_CLASSES.append('desktop.middleware.AuditLoggingMiddleware') # Re-add middleware
|
|
|
|
|
|
|
|
- try:
|
|
|
|
|
- # Check if we audit correctly
|
|
|
|
|
- response = c.get("/beeswax/")
|
|
|
|
|
- assert_true('audited' in response, response)
|
|
|
|
|
-
|
|
|
|
|
- audit = open(log_path).readlines()
|
|
|
|
|
- for line in audit:
|
|
|
|
|
- audit_json = json.loads(line)
|
|
|
|
|
- audit_record = audit_json.values()[0]
|
|
|
|
|
- assert_equal('test_audit_logging_middleware_enable', audit_record['user'], audit_record)
|
|
|
|
|
- assert_equal('/beeswax/', audit_record['url'], audit_record)
|
|
|
|
|
-
|
|
|
|
|
- finally:
|
|
|
|
|
- settings.MIDDLEWARE_CLASSES.pop()
|
|
|
|
|
- reset()
|
|
|
|
|
try:
|
|
try:
|
|
|
- os.remove(log_tmp)
|
|
|
|
|
- except OSError:
|
|
|
|
|
- pass
|
|
|
|
|
|
|
+ # Check if we audit correctly
|
|
|
|
|
+ response = c.get("/beeswax/")
|
|
|
|
|
+ assert_true('audited' in response, response)
|
|
|
|
|
+
|
|
|
|
|
+ audit = open(log_path).readlines()
|
|
|
|
|
+ for line in audit:
|
|
|
|
|
+ audit_json = json.loads(line)
|
|
|
|
|
+ audit_record = audit_json.values()[0]
|
|
|
|
|
+ assert_equal('test_audit_logging_middleware_enable', audit_record['user'], audit_record)
|
|
|
|
|
+ assert_equal('/beeswax/', audit_record['url'], audit_record)
|
|
|
|
|
+
|
|
|
|
|
+ finally:
|
|
|
|
|
+ settings.MIDDLEWARE_CLASSES.pop()
|
|
|
|
|
+ reset()
|
|
|
|
|
|
|
|
def test_audit_logging_middleware_disable():
|
|
def test_audit_logging_middleware_disable():
|
|
|
c = make_logged_in_client(username='test_audit_logging_middleware_disable', is_superuser=False)
|
|
c = make_logged_in_client(username='test_audit_logging_middleware_disable', is_superuser=False)
|