Skip to content

Commit

Permalink
tests/test_CLI.py: create $GNUPGHOME on the fly (#31)
Browse files Browse the repository at this point in the history
* tests/test_CLI.py: create $GNUPGHOME on the fly

 - avoid expiration of keys by re-creating them
 - prevent gnupg version being incompatible with $GNUPGHOME in git

Storing binary data is bad because:

 - git is not good at handling binary data
 - binary data is harder to inspect (remember the xz incident)

* TransRead.read: pass on -1 instead of 0xFFFFFFFFFFFFFFFF

Passing 0xFFFFFFFFFFFFFFFF to read causes python to complain about:

    OverflowError: cannot fit 'int' into an index-sized integer

Signed-off-by: Jörg Sommer <joerg.sommer@navimatix.de>

* tests: Rework CLI tests

The current tests do not take into account whether the `gpg` package has
been installed or not. If it is missing, the tests should be skipped.

Furthermore, the output of the tests must be checked in order to decide
whether tests fail due to an exception or whether the desired error message
is displayed.

Signed-off-by: Jörg Sommer <joerg.sommer@navimatix.de>

* CLI: rework PGP verification

The verification of PGP signatures had some flaws and didn't work, because
the Python API and the GPG interface have changed. Inline signatures were
not detected, because of a comparison of string and byte array. And even
after this the code failed, because `sig.status` is no longer available.

Signed-off-by: Jörg Sommer <joerg.sommer@navimatix.de>

* tests/test_CLI.py: factor out verification logic into its own function

* add gpg verification methods using gpg and gpgv binaries

* ci: Fix GPG tests

Fixes up the way that the GPG tests work by adding a new "native" python
test version. This is required because the python 'gpg' module *must*
come from the host package in order to patch libgpgme (e.g.
'python3-gpg'). It's not possible to get this module installed with the
pre-canned python versions provided by GitHub Actions, so the gpg tests
are skipped for this version, but using the host native python can.

---------

Signed-off-by: Jörg Sommer <joerg.sommer@navimatix.de>
Co-authored-by: Jörg Sommer <joerg.sommer@navimatix.de>
Co-authored-by: Joshua Watt <JPEWhacker@gmail.com>
  • Loading branch information
3 people authored Jan 16, 2025
1 parent 1f54211 commit 15114f7
Show file tree
Hide file tree
Showing 15 changed files with 295 additions and 393 deletions.
28 changes: 21 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,40 @@ jobs:
- "3.10"
- "3.11"
- "3.12"
# Testing with native host python is required in order to test the
# GPG code, since it must use the host python3-gpg package
- "native"
steps:
- uses: actions/checkout@v4
- name: Setup Python ${{ matrix.python-version }}

- if: matrix.python-version != 'native'
name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- if: matrix.python-version == 'native'
name: Setup Native Python
run: |
sudo apt-get install -y python3 python3-pip libgpgme11-dev python3-gpg
- name: Install dependencies
run: |
sudo apt-get install -y pbzip2 pigz lzop liblz4-tool libgpgme11-dev
python -m pip install --upgrade pip
pip install build
sudo apt-get install -y pbzip2 pigz lzop liblz4-tool
python3 -m pip install --upgrade pip
python3 -m pip install build
- name: Build package
run: |
python -m build
python3 -m build
- name: Install package
run: |
pip install -e .[dev]
python3 -m pip install -e .[dev]
- name: Run tests
run: |
python -m unittest -vb
python3 -m unittest -vb
lint:
runs-on: ubuntu-latest
Expand Down
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ name = "bmaptool"
description = "BMAP tools"
dynamic = ["version"]
dependencies = [
"gpg >= 1.10.0",
# NOTE: gpg is not installed because it must come from the system GPG package
# (e.g. python3-gpg on Ubuntu) and not from PyPi. The PyPi version is very old
# and no longer functions correctly
#"gpg >= 1.10.0",
]
required-python = ">= 3.8"
authors = [
Expand Down
Loading

0 comments on commit 15114f7

Please sign in to comment.