Skip to content

Commit

Permalink
Merge pull request #45 from kchason/ci-fixes
Browse files Browse the repository at this point in the history
Updates for Python 3.x CI Pipelines
  • Loading branch information
dc3-tsd authored Oct 2, 2024
2 parents ce86c93 + 6a4e577 commit 1a05098
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 84 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
# This allows the pipeline to be run against multiple Python versions. eg. [3.6, 3.7, 3.8, 3.9, 3.10]. This results
# in linting and unit tests running for all listed versions as well as the creation of packages and wheels on
# creation of a tag in Git.
python-version: [ "3.6", "3.7", "3.8", "3.9", "3.10" ]
python-version: [ "3.8", "3.9", "3.10", "3.11", "3.12" ]

steps:
# Get the code from the repository to be packaged
Expand All @@ -28,8 +28,9 @@ jobs:
# Install the packages to build the SQLite Dissect package
- name: Prepare Build Environment
run: |
sudo apt install python3-setuptools
python -m pip install -q --upgrade pip
python setup.py -q install
pip install .
pip install -q flake8 pytest pytest-cov build twine wheel
# Lint the Python code to check for syntax errors
Expand Down
2 changes: 1 addition & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ default:
tags:
- docker
- devnet
image: python:3.7
image: python:3.11

stages:
- Lint
Expand Down
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
author = 'Department of Defense Cyber Crime Center (DC3)'

# The full version, including alpha/beta/rc tags
release = '0.3.0'
release = '1.0.0'

# -- General configuration ---------------------------------------------------
master_doc = 'index'
Expand Down
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@
"sqlite_dissect.export"],
classifiers=[
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10"
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
],
entry_points={
'console_scripts': ['sqlite_dissect=sqlite_dissect.entrypoint:cli'],
Expand Down
7 changes: 1 addition & 6 deletions sqlite_dissect/tests/file_handle_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,7 @@ def test_close(test_close_file_handle):
with pytest.raises(IOError):
test_close_file_handle[0].close()
else:
with pytest.warns(None) as w:
test_close_file_handle[0].close()
if w:
assert False
else:
assert True
test_close_file_handle[0].close()


test_read_data_params = [
Expand Down
71 changes: 0 additions & 71 deletions sqlite_dissect/tests/nist_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,74 +76,3 @@ def test_header_reporting(db_file):
nist_assertions.assert_correct_journal_mode(reported_journal_mode_write, actual_journal_mode, 'w')
nist_assertions.assert_correct_num_pages(reported_num_pages, actual_num_pages)
nist_assertions.assert_correct_encoding(reported_encoding, actual_encoding)


# SFT-02
def test_schema_reporting(db_file, tmp_path):
if 'SFT-01' not in db_file[0].name:
pytest.skip("Skipping SFT-03 db's")

db_filepath = str(db_file[0].resolve())
hash_before_parsing = get_md5_hash(db_filepath)

args = parse_args([db_filepath])
sqlite_files = get_sqlite_files(args.sqlite_path)
log_file = tmp_path / "log.txt"

with open(str(log_file), 'w') as stdout:
sys.stdout = stdout
main(args, sqlite_files[0], len(sqlite_files) > 1)

reported_tables = []
reported_columns = {}
reported_num_rows = {}
current_table = None
row_count = 0
with open(str(log_file), 'r') as stdout:
for line in stdout:
line = line.strip()
if "Master schema entry: " in line and "row type: table" in line:
current_table = line[line.find("Master schema entry: "):line.find("row type: ")].split(': ')[1].strip()
reported_tables.append(current_table)
reported_columns[current_table] = []

create_statement = line[line.find("sql: "):].split(': ')[1].strip()
columns = create_statement[create_statement.find("(") + 1:create_statement.find(")")].split(',')
for column in columns:
reported_columns[current_table].append(column.strip().split()[0])

elif "File Type: " in line and current_table:
row_count += 1

elif line == '-' * 15:
reported_num_rows[current_table] = row_count
current_table = None
row_count = 0

actual_database = sqlite3.connect(db_filepath)
db_cursor = actual_database.cursor()
db_cursor.execute("SELECT tbl_name, sql FROM sqlite_master WHERE type='table'")

actual_tables = []
actual_columns = {}
actual_num_rows = {}
for table in db_cursor.fetchall():
actual_tables.append(table[0])
actual_columns[table[0]] = []

columns = table[1][table[1].find("(")+1:table[1].find(")")]
for column in columns.split(","):
actual_columns[table[0]].append(column.strip().split()[0])

db_cursor.execute("SELECT COUNT(*) FROM %s" % table[0])
actual_num_rows[table[0]] = int(db_cursor.fetchone()[0])

hash_after_parsing = get_md5_hash(db_filepath)

nist_assertions.assert_md5_equals(hash_before_parsing, hash_after_parsing, db_file[0].name)
nist_assertions.assert_file_exists(db_filepath)
nist_assertions.assert_correct_tables(reported_tables, actual_tables)

for table in reported_columns:
nist_assertions.assert_correct_columns(reported_columns[table], actual_columns[table], table)
nist_assertions.assert_correct_num_pages(reported_num_rows[table], actual_num_rows[table])

0 comments on commit 1a05098

Please sign in to comment.