Skip to content

Commit 8ce4921

Browse files
authored
Merge pull request #50 from ssbarnea/chore/ci
Make github actions pipelines pass
2 parents 37f79a4 + b00f396 commit 8ce4921

File tree

7 files changed

+80
-19
lines changed

7 files changed

+80
-19
lines changed

.github/workflows/ci.yml

+9-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ jobs:
1919
os: ubuntu-latest
2020
- python: "3.10"
2121
os: ubuntu-latest
22+
- python: "3.11"
23+
os: ubuntu-latest
24+
- python: "3.12"
25+
os: ubuntu-latest
2226
- python: "3.10"
2327
os: macos-latest
2428
steps:
@@ -31,20 +35,23 @@ jobs:
3135
with:
3236
python-version: ${{ matrix.python }}
3337

34-
- name: Install system packages
38+
- name: Install system packages (linux)
3539
if: matrix.os == 'ubuntu-latest'
3640
run: |
3741
sudo apt-get update && \
3842
sudo apt-get -y install \
3943
tmux \
4044
;
4145
42-
- name: Install system packages
46+
- name: Install system packages (macos)
4347
if: matrix.os == 'macos-latest'
4448
run: |
4549
brew install \
4650
tmux \
51+
gpg \
4752
;
53+
which -a gpg
54+
gpg --version
4855
4956
- name: Install tox
5057
run: pip install tox

setup.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
PyScaffold helps you to put up the scaffold of your new Python project.
77
Learn more under: https://pyscaffold.org/
88
"""
9+
910
from setuptools import setup
1011

1112
if __name__ == "__main__":

tests/conftest.py

+5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
from ansible_sign.signing import GPGSigner
1414

1515

16+
if gnupg.__version__ >= "1.0":
17+
# https://stackoverflow.com/q/35028852/99834
18+
pytest.exit("Unsupported gnupg library found, repair it with: pip3 uninstall -y gnupg && pip3 install python-gnupg")
19+
20+
1621
@pytest.fixture
1722
def tmux_session(request):
1823
"""

tests/requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ pytest
33
pytest-mock
44
flake8
55
yamllint
6-
black
6+
black>=24.3.0

tests/test_cli.py

+52-14
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
import os
2+
import sys
23
import pytest
34

45
from ansible_sign.cli import main
56

67
__author__ = "Rick Elrod"
78
__copyright__ = "(c) 2022 Red Hat, Inc."
89
__license__ = "MIT"
10+
IS_GITHUB_ACTION_MACOS = sys.platform == "darwin" and os.environ.get("CI", "false") == "true"
911

1012

1113
@pytest.mark.parametrize(
1214
"args, exp_stdout_substr, exp_stderr_substr, exp_rc",
1315
[
1416
(
1517
[
18+
"--debug",
19+
"--nocolor",
1620
"project",
1721
"gpg-sign",
1822
"tests/fixtures/checksum/missing-manifest",
@@ -23,6 +27,8 @@
2327
),
2428
(
2529
[
30+
"--debug",
31+
"--nocolor",
2632
"project",
2733
"gpg-sign",
2834
"tests/fixtures/checksum/manifest-syntax-error",
@@ -33,6 +39,8 @@
3339
),
3440
(
3541
[
42+
"--debug",
43+
"--nocolor",
3644
"project",
3745
"gpg-verify",
3846
"tests/fixtures/checksum/manifest-success",
@@ -43,6 +51,8 @@
4351
),
4452
(
4553
[
54+
"--debug",
55+
"--nocolor",
4656
"project",
4757
"gpg-verify",
4858
"--gnupg-home=/dir/that/does/not/exist/321",
@@ -75,6 +85,8 @@ def test_main(capsys, args, exp_stdout_substr, exp_stderr_substr, exp_rc):
7585
[
7686
(
7787
[
88+
"--debug",
89+
"--nocolor",
7890
"project",
7991
"gpg-verify",
8092
"--keyring={gpghome}/pubring.kbx",
@@ -86,6 +98,8 @@ def test_main(capsys, args, exp_stdout_substr, exp_stderr_substr, exp_rc):
8698
),
8799
(
88100
[
101+
"--debug",
102+
"--nocolor",
89103
"project",
90104
"gpg-verify",
91105
"--gnupg-home={gpghome}",
@@ -97,6 +111,8 @@ def test_main(capsys, args, exp_stdout_substr, exp_stderr_substr, exp_rc):
97111
),
98112
(
99113
[
114+
"--debug",
115+
"--nocolor",
100116
"project",
101117
"gpg-verify",
102118
"--gnupg-home={gpghome}",
@@ -129,20 +145,40 @@ def test_main_with_pubkey_in_keyring(capsys, gpg_home_with_hao_pubkey, args, exp
129145
@pytest.mark.parametrize(
130146
"project_fixture, exp_stdout_substr, exp_stderr_substr, exp_rc",
131147
[
132-
("signed_project_and_gpg", "GPG signature verification succeeded", "", 0),
133-
("signed_project_broken_manifest", "Invalid line encountered in checksum manifest", "", 1),
134-
("signed_project_missing_manifest", "Checksum manifest file does not exist:", "", 1),
135-
("signed_project_modified_manifest", "Checksum validation failed.", "", 2),
136-
("signed_project_with_different_gpg_home", "Re-run with the global --debug flag", "", 3),
137-
("signed_project_broken_manifest_in", "An error was encountered while parsing MANIFEST.in: unknown action 'invalid-directive'", "", 1),
138-
],
139-
ids=[
140-
"valid checksum file and signature",
141-
"valid signature but broken checksum file",
142-
"missing checksum file entirely",
143-
"checksum file with wrong hashes",
144-
"matching pubkey does not exist in gpg home",
145-
"broken MANIFEST.in after signing",
148+
pytest.param(
149+
"signed_project_and_gpg",
150+
"GPG signature verification succeeded",
151+
"",
152+
0,
153+
id="valid checksum file and signature",
154+
marks=pytest.mark.xfail(IS_GITHUB_ACTION_MACOS, reason="https://github.com/ansible/ansible-sign/issues/51"),
155+
),
156+
pytest.param(
157+
"signed_project_broken_manifest",
158+
"Invalid line encountered in checksum manifest",
159+
"",
160+
1,
161+
id="valid signature but broken checksum file",
162+
marks=pytest.mark.xfail(IS_GITHUB_ACTION_MACOS, reason="https://github.com/ansible/ansible-sign/issues/51"),
163+
),
164+
pytest.param("signed_project_missing_manifest", "Checksum manifest file does not exist:", "", 1, id="missing checksum file entirely"),
165+
pytest.param(
166+
"signed_project_modified_manifest",
167+
"Checksum validation failed.",
168+
"",
169+
2,
170+
id="checksum file with wrong hashes",
171+
marks=pytest.mark.xfail(IS_GITHUB_ACTION_MACOS, reason="https://github.com/ansible/ansible-sign/issues/51"),
172+
),
173+
pytest.param("signed_project_with_different_gpg_home", "Re-run with the global --debug flag", "", 3, id="matching pubkey does not exist in gpg home"),
174+
pytest.param(
175+
"signed_project_broken_manifest_in",
176+
"An error was encountered while parsing MANIFEST.in: unknown action 'invalid-directive'",
177+
"",
178+
1,
179+
id="broken MANIFEST.in after signing",
180+
marks=pytest.mark.xfail(IS_GITHUB_ACTION_MACOS, reason="https://github.com/ansible/ansible-sign/issues/51"),
181+
),
146182
],
147183
)
148184
def test_gpg_verify_manifest_scenario(capsys, request, project_fixture, exp_stdout_substr, exp_stderr_substr, exp_rc):
@@ -153,6 +189,8 @@ def test_gpg_verify_manifest_scenario(capsys, request, project_fixture, exp_stdo
153189
(project_root, gpg_home) = request.getfixturevalue(project_fixture)
154190
keyring = os.path.join(gpg_home, "pubring.kbx")
155191
args = [
192+
"--debug",
193+
"--nocolor",
156194
"project",
157195
"gpg-verify",
158196
f"--keyring={keyring}",

tests/test_cli_pinentry.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1+
import pytest
2+
import sys
13
import time
24

35
__author__ = "Rick Elrod"
46
__copyright__ = "(c) 2022 Red Hat, Inc."
57
__license__ = "MIT"
68

79

10+
# On MacOS the is a dialog popup asking for password, not a console prompt.
11+
@pytest.mark.skipif(sys.platform == "darwin", reason="Interactive test not working on MacOS")
812
def test_pinentry_simple(tmux_session, gpg_home_with_secret_key, unsigned_project_with_checksum_manifest):
913
"""Test that we can sign a file with a pinentry program."""
1014
home = gpg_home_with_secret_key
@@ -17,9 +21,13 @@ def test_pinentry_simple(tmux_session, gpg_home_with_secret_key, unsigned_projec
1721
pane.send_keys(f"cd {unsigned_project_with_checksum_manifest}")
1822
pane.send_keys(f"ansible-sign project gpg-sign --gnupg-home {home} .")
1923
time.sleep(2) # Give the pinentry prompt time to show up.
20-
out = "\n".join(pane.cmd("capture-pane", "-p").stdout)
24+
cmd = pane.cmd("capture-pane", "-p")
25+
assert cmd.returncode == 0
26+
out = "\n".join(cmd.stdout)
2127
assert "Passphrase: _" in out
2228
pane.send_keys("doYouEvenPassphrase")
2329
time.sleep(2) # Give time for returning to ansible-sign and signing to finish.
24-
out = "\n".join(pane.cmd("capture-pane", "-p").stdout)
30+
cmd = pane.cmd("capture-pane", "-p")
31+
assert cmd.returncode == 0
32+
out = "\n".join(cmd.stdout)
2533
assert "GPG signing successful!" in out

tox.ini

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ deps =
1111
setenv =
1212
TOXINIDIR = {toxinidir}
1313
passenv =
14+
CI
15+
GITHUB_*
1416
HOME
1517
SETUPTOOLS_*
1618
extras =

0 commit comments

Comments
 (0)