File tree Expand file tree Collapse file tree 5 files changed +71
-0
lines changed
Expand file tree Collapse file tree 5 files changed +71
-0
lines changed Original file line number Diff line number Diff line change 2828
2929 - name : Build package
3030 run : python -m build
31+
32+ - name : Run test suite
33+ run : |
34+ python tests/test_runner.py
Original file line number Diff line number Diff line change 11[ ![ PyPI version] ( https://img.shields.io/pypi/v/crdb-sql-audit )] ( https://pypi.org/project/crdb-sql-audit/ )
22[ ![ Python version] ( https://img.shields.io/pypi/pyversions/crdb-sql-audit )] ( https://pypi.org/project/crdb-sql-audit/ )
33[ ![ License] ( https://img.shields.io/pypi/l/crdb-sql-audit )] ( https://pypi.org/project/crdb-sql-audit/ )
4+ [ ![ Build status] ( https://github.com/viragtripathi/crdb-sql-audit/actions/workflows/python-ci.yml/badge.svg )] ( https://github.com/viragtripathi/crdb-sql-audit/actions )
45
56# crdb-sql-audit
67
@@ -169,3 +170,25 @@ You can use basic Unix commands to check for patterns like pg_ functions directl
169170| Unique function names | ` grep -oE '\bpg_[a-zA-Z0-9_]+\(' chunks/* \| sort \| uniq ` |
170171| Count occurrences of each function | ` grep -oE '\bpg_[a-zA-Z0-9_]+\(' chunks/* \| sort \| uniq -c \| sort -nr ` |
171172| Full SQL lines containing pg\_\* | ` grep -E '\bpg_[a-zA-Z0-9_]+\(' chunks/* ` |
173+
174+
175+ ---
176+
177+ ## 🧪 Running Tests
178+
179+ This project includes a test suite using sample logs and rules to validate behavior.
180+
181+ ### 🔧 To run locally:
182+
183+ ``` bash
184+ python tests/test_runner.py
185+ ```
186+
187+ ### 🧪 What it does:
188+
189+ * Runs ` crdb-sql-audit ` on a small sample of PostgreSQL-style logs
190+ * Uses ` tests/rules/test_rules.yaml `
191+ * Verifies that a CSV report is created with expected issues
192+
193+ ✅ This runs automatically in GitHub Actions on every commit to ` main ` .
194+
Original file line number Diff line number Diff line change 1+ - id : malformed_dml
2+ match : ' ^(SELECT|DELETE FROM)\s*$'
3+ message : " Too short"
4+ level : warning
5+ tags : [syntax]
6+
7+ - id : hash_table
8+ match : ' "[^"]*#\w*"'
9+ message : " Has # in table name"
10+ level : error
11+ tags : [identifier]
12+
13+ - id : pg_func
14+ match : ' ^.*\bpg_\w+\s*\(.*$'
15+ message : " PostgreSQL built-in function"
16+ level : error
17+ tags : [function]
Original file line number Diff line number Diff line change 1+ 2025-05-15 12:00:00 CEST [123456]: [1-1] user=testusr,db=testdb LOG: execute <unnamed>: SELECT * FROM "ACCOUNTS#NAU"
2+ 2025-05-15 12:00:01 CEST [123456]: [2-1] user=testusr,db=testdb LOG: execute <unnamed>: DELETE FROM
3+ 2025-05-15 12:00:02 CEST [123456]: [3-1] user=testusr,db=testdb LOG: execute <unnamed>: SELECT pg_backend_pid()
4+ 2025-05-15 12:00:03 CEST [123456]: [4-1] user=testusr,db=testdb LOG: execute <unnamed>: SELECT
Original file line number Diff line number Diff line change 1+ import os
2+ import subprocess
3+
4+ def run_test ():
5+ print ("🧪 Running crdb-sql-audit on test logs..." )
6+ test_output = "tests/output/test_report"
7+ os .makedirs ("tests/output" , exist_ok = True )
8+
9+ subprocess .run ([
10+ "crdb-sql-audit" ,
11+ "--dir" , "tests/sample_logs" ,
12+ "--terms" , "execute,pg_" ,
13+ "--rules" , "tests/rules/test_rules.yaml" ,
14+ "--out" , test_output
15+ ], check = True )
16+
17+ if os .path .exists (test_output + ".csv" ):
18+ print ("✅ CSV report generated successfully" )
19+ else :
20+ print ("❌ CSV report not found" )
21+
22+ if __name__ == "__main__" :
23+ run_test ()
You can’t perform that action at this time.
0 commit comments