Skip to content

Commit

Permalink
tests: fix setting temporary gpg home
Browse files Browse the repository at this point in the history
When $GPGHOME is set to $HOME/.gnupg, gpg will use default gpg-agent
socket path ($XDG_RUNTIME_DIR/gnupg/S.gpg-agent). If there is gpg-agent
for the original home already running, it will get used, instead of the
one for modified $HOME/$GNUPGHOME. Fix this by setting $GNUPGHOME to a
slightly modified dir, so it doesn't fall into the default case.
  • Loading branch information
marmarek committed Jan 6, 2025
1 parent 6a69649 commit 05b7bc1
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 27 deletions.
39 changes: 20 additions & 19 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ def test_component_host_fc37_sign(artifacts_dir):
)

with tempfile.TemporaryDirectory() as tmpdir:
gnupghome = f"{tmpdir}/.gnupg"
gnupghome = f"{tmpdir}/gnupg"
# Better copy testing keyring into a separate directory to prevent locks inside
# local sources (when executed locally).
shutil.copytree(PROJECT_PATH / "tests/gnupg", gnupghome)
Expand Down Expand Up @@ -526,7 +526,7 @@ def test_component_host_fc37_sign(artifacts_dir):
def test_component_host_fc37_publish(artifacts_dir):
env = os.environ.copy()
with tempfile.TemporaryDirectory() as tmpdir:
gnupghome = f"{tmpdir}/.gnupg"
gnupghome = f"{tmpdir}/gnupg"
shutil.copytree(PROJECT_PATH / "tests/gnupg", gnupghome)
os.chmod(gnupghome, 0o700)

Expand Down Expand Up @@ -746,7 +746,7 @@ def test_component_host_fc37_publish(artifacts_dir):
def test_component_host_fc37_upload(artifacts_dir):
env = os.environ.copy()
with tempfile.TemporaryDirectory() as tmpdir:
gnupghome = f"{tmpdir}/.gnupg"
gnupghome = f"{tmpdir}/gnupg"
shutil.copytree(PROJECT_PATH / "tests/gnupg", gnupghome)
os.chmod(gnupghome, 0o700)
builder_conf = tmpdir + "/builder.yml"
Expand Down Expand Up @@ -852,7 +852,7 @@ def test_component_host_fc37_build_skip(artifacts_dir):
def test_component_host_fc37_sign_skip(artifacts_dir):
env = os.environ.copy()
with tempfile.TemporaryDirectory() as tmpdir:
gnupghome = f"{tmpdir}/.gnupg"
gnupghome = f"{tmpdir}/gnupg"
shutil.copytree(PROJECT_PATH / "tests/gnupg", gnupghome)
os.chmod(gnupghome, 0o700)

Expand Down Expand Up @@ -893,7 +893,7 @@ def test_component_host_fc37_sign_skip(artifacts_dir):
def test_component_host_fc37_unpublish(artifacts_dir):
env = os.environ.copy()
with tempfile.TemporaryDirectory() as tmpdir:
gnupghome = f"{tmpdir}/.gnupg"
gnupghome = f"{tmpdir}/gnupg"
shutil.copytree(PROJECT_PATH / "tests/gnupg", gnupghome)
os.chmod(gnupghome, 0o700)

Expand Down Expand Up @@ -1101,7 +1101,7 @@ def test_component_vm_bookworm_build(artifacts_dir):
def test_component_vm_bookworm_sign(artifacts_dir):
env = os.environ.copy()
with tempfile.TemporaryDirectory() as tmpdir:
gnupghome = f"{tmpdir}/.gnupg"
gnupghome = f"{tmpdir}/gnupg"
shutil.copytree(PROJECT_PATH / "tests/gnupg", gnupghome)
os.chmod(gnupghome, 0o700)

Expand Down Expand Up @@ -1152,7 +1152,7 @@ def test_component_vm_bookworm_sign(artifacts_dir):
def test_component_vm_bookworm_publish(artifacts_dir):
env = os.environ.copy()
with tempfile.TemporaryDirectory() as tmpdir:
gnupghome = f"{tmpdir}/.gnupg"
gnupghome = f"{tmpdir}/gnupg"
shutil.copytree(PROJECT_PATH / "tests/gnupg", gnupghome)
os.chmod(gnupghome, 0o700)

Expand Down Expand Up @@ -1338,7 +1338,7 @@ def test_component_vm_bookworm_build_skip(artifacts_dir):
def test_component_vm_bookworm_sign_skip(artifacts_dir):
env = os.environ.copy()
with tempfile.TemporaryDirectory() as tmpdir:
gnupghome = f"{tmpdir}/.gnupg"
gnupghome = f"{tmpdir}/gnupg"
shutil.copytree(PROJECT_PATH / "tests/gnupg", gnupghome)
os.chmod(gnupghome, 0o700)

Expand Down Expand Up @@ -1376,7 +1376,7 @@ def test_component_vm_bookworm_unpublish(artifacts_dir):

env = os.environ.copy()
with tempfile.TemporaryDirectory() as tmpdir:
gnupghome = f"{tmpdir}/.gnupg"
gnupghome = f"{tmpdir}/gnupg"
shutil.copytree(PROJECT_PATH / "tests/gnupg", gnupghome)
os.chmod(gnupghome, 0o700)

Expand Down Expand Up @@ -1492,7 +1492,7 @@ def test_increment_component_fetch(artifacts_dir):
def test_increment_component_build(artifacts_dir):
env = os.environ.copy()
with tempfile.TemporaryDirectory() as tmpdir:
gnupghome = f"{tmpdir}/.gnupg"
gnupghome = f"{tmpdir}/gnupg"
shutil.copytree(PROJECT_PATH / "tests/gnupg", gnupghome)
os.chmod(gnupghome, 0o700)

Expand Down Expand Up @@ -1658,7 +1658,7 @@ def test_component_vm_archlinux_sign(artifacts_dir):
env = os.environ.copy()

with tempfile.TemporaryDirectory() as tmpdir:
gnupghome = f"{tmpdir}/.gnupg"
gnupghome = f"{tmpdir}/gnupg"
# Better copy testing keyring into a separate directory to prevent locks inside
# local sources (when executed locally).
shutil.copytree(PROJECT_PATH / "tests/gnupg", gnupghome)
Expand Down Expand Up @@ -1702,7 +1702,7 @@ def test_component_vm_archlinux_sign(artifacts_dir):
def test_component_vm_archlinux_publish(artifacts_dir):
env = os.environ.copy()
with tempfile.TemporaryDirectory() as tmpdir:
gnupghome = f"{tmpdir}/.gnupg"
gnupghome = f"{tmpdir}/gnupg"
shutil.copytree(PROJECT_PATH / "tests/gnupg", gnupghome)
os.chmod(gnupghome, 0o700)

Expand Down Expand Up @@ -1823,7 +1823,7 @@ def test_component_vm_archlinux_publish(artifacts_dir):
def test_component_vm_archlinux_upload(artifacts_dir):
env = os.environ.copy()
with tempfile.TemporaryDirectory() as tmpdir:
gnupghome = f"{tmpdir}/.gnupg"
gnupghome = f"{tmpdir}/gnupg"
shutil.copytree(PROJECT_PATH / "tests/gnupg", gnupghome)
os.chmod(gnupghome, 0o700)
builder_conf = tmpdir + "/builder.yml"
Expand Down Expand Up @@ -1960,7 +1960,7 @@ def test_template_fedora_40_build(artifacts_dir):
def test_template_fedora_40_minimal_sign(artifacts_dir):
env = os.environ.copy()
with tempfile.TemporaryDirectory() as tmpdir:
gnupghome = f"{tmpdir}/.gnupg"
gnupghome = f"{tmpdir}/gnupg"
# Better copy testing keyring into a separate directory to prevent locks inside
# local sources (when executed locally).
shutil.copytree(PROJECT_PATH / "tests/gnupg", gnupghome)
Expand All @@ -1970,6 +1970,7 @@ def test_template_fedora_40_minimal_sign(artifacts_dir):
# We prevent rpm to find ~/.rpmmacros
env["HOME"] = tmpdir


qb_call(
DEFAULT_BUILDER_CONF,
artifacts_dir,
Expand Down Expand Up @@ -2004,7 +2005,7 @@ def test_template_fedora_40_minimal_sign(artifacts_dir):
def test_template_fedora_40_minimal_publish(artifacts_dir):
env = os.environ.copy()
with tempfile.TemporaryDirectory() as tmpdir:
gnupghome = f"{tmpdir}/.gnupg"
gnupghome = f"{tmpdir}/gnupg"
shutil.copytree(PROJECT_PATH / "tests/gnupg", gnupghome)
os.chmod(gnupghome, 0o700)

Expand Down Expand Up @@ -2095,7 +2096,7 @@ def test_template_fedora_40_minimal_publish(artifacts_dir):
def test_template_fedora_40_minimal_publish_new(artifacts_dir):
env = os.environ.copy()
with tempfile.TemporaryDirectory() as tmpdir:
gnupghome = f"{tmpdir}/.gnupg"
gnupghome = f"{tmpdir}/gnupg"
shutil.copytree(PROJECT_PATH / "tests/gnupg", gnupghome)
os.chmod(gnupghome, 0o700)

Expand Down Expand Up @@ -2220,7 +2221,7 @@ def test_template_fedora_40_minimal_publish_new(artifacts_dir):
def test_template_fedora_40_minimal_unpublish(artifacts_dir):
env = os.environ.copy()
with tempfile.TemporaryDirectory() as tmpdir:
gnupghome = f"{tmpdir}/.gnupg"
gnupghome = f"{tmpdir}/gnupg"
shutil.copytree(PROJECT_PATH / "tests/gnupg", gnupghome)
os.chmod(gnupghome, 0o700)

Expand Down Expand Up @@ -2407,7 +2408,7 @@ def test_template_debian_12_minimal_build(artifacts_dir):
def test_template_debian_12_minimal_sign(artifacts_dir):
env = os.environ.copy()
with tempfile.TemporaryDirectory() as tmpdir:
gnupghome = f"{tmpdir}/.gnupg"
gnupghome = f"{tmpdir}/gnupg"
# Better copy testing keyring into a separate directory to prevent locks inside
# local sources (when executed locally).
shutil.copytree(PROJECT_PATH / "tests/gnupg", gnupghome)
Expand Down Expand Up @@ -2451,7 +2452,7 @@ def test_template_debian_12_minimal_sign(artifacts_dir):
def test_template_debian_12_minimal_publish(artifacts_dir):
env = os.environ.copy()
with tempfile.TemporaryDirectory() as tmpdir:
gnupghome = f"{tmpdir}/.gnupg"
gnupghome = f"{tmpdir}/gnupg"
shutil.copytree(PROJECT_PATH / "tests/gnupg", gnupghome)
os.chmod(gnupghome, 0o700)

Expand Down
6 changes: 3 additions & 3 deletions tests/test_cli_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def qb_call_output(builder_conf, artifacts_dir, *args, **kwargs):
def test_repository_create_vm_fc40(artifacts_dir):
env = os.environ.copy()
with tempfile.TemporaryDirectory() as tmpdir:
gnupghome = f"{tmpdir}/.gnupg"
gnupghome = f"{tmpdir}/gnupg"
shutil.copytree(PROJECT_PATH / "tests/gnupg", gnupghome)
os.chmod(gnupghome, 0o700)

Expand Down Expand Up @@ -98,7 +98,7 @@ def test_repository_create_vm_fc40(artifacts_dir):
def test_repository_create_vm_bookworm(artifacts_dir):
env = os.environ.copy()
with tempfile.TemporaryDirectory() as tmpdir:
gnupghome = f"{tmpdir}/.gnupg"
gnupghome = f"{tmpdir}/gnupg"
shutil.copytree(PROJECT_PATH / "tests/gnupg", gnupghome)
os.chmod(gnupghome, 0o700)

Expand Down Expand Up @@ -130,7 +130,7 @@ def test_repository_create_vm_bookworm(artifacts_dir):
def test_repository_create_template(artifacts_dir):
env = os.environ.copy()
with tempfile.TemporaryDirectory() as tmpdir:
gnupghome = f"{tmpdir}/.gnupg"
gnupghome = f"{tmpdir}/gnupg"
shutil.copytree(PROJECT_PATH / "tests/gnupg", gnupghome)
os.chmod(gnupghome, 0o700)

Expand Down
10 changes: 5 additions & 5 deletions tests/test_scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def temp_directory():

@pytest.fixture
def home_directory(temp_directory):
gnupghome = f"{temp_directory}/.gnupg"
gnupghome = f"{temp_directory}/gnupg"
shutil.copytree(PROJECT_PATH / "tests/gnupg", gnupghome)
os.chmod(gnupghome, 0o700)
# Initialize the conf
Expand Down Expand Up @@ -390,7 +390,7 @@ def test_non_qubesos_repository_with_maintainer_and_signed_tag(
def test_repository_with_multiple_distinct_signatures(
temp_directory, home_directory
):
gnupg_dir = home_directory / ".gnupg"
gnupg_dir = home_directory / "gnupg"
remote_repo_dir = temp_directory / "remote_repo"
repo_dir = temp_directory / "repo"
key_ids = [
Expand Down Expand Up @@ -443,7 +443,7 @@ def test_repository_with_multiple_distinct_signatures(
def test_repository_with_multiple_non_distinct_signatures(
temp_directory, home_directory
):
gnupg_dir = home_directory / ".gnupg"
gnupg_dir = home_directory / "gnupg"
remote_repo_dir = temp_directory / "remote_repo"
repo_dir = temp_directory / "repo"
key_ids = [
Expand Down Expand Up @@ -502,7 +502,7 @@ def test_repository_with_multiple_non_distinct_signatures(
def test_repository_with_multiple_distinct_signatures_not_in_maintainers(
temp_directory, home_directory
):
gnupg_dir = home_directory / ".gnupg"
gnupg_dir = home_directory / "gnupg"
remote_repo_dir = temp_directory / "remote_repo"
repo_dir = temp_directory / "repo"
key_ids = [
Expand Down Expand Up @@ -553,7 +553,7 @@ def test_repository_with_multiple_distinct_signatures_not_in_maintainers(


def test_repository_with_signed_commit(capsys, temp_directory, home_directory):
gnupg_dir = home_directory / ".gnupg"
gnupg_dir = home_directory / "gnupg"
remote_repo_dir = temp_directory / "remote_repo"
repo_dir = temp_directory / "repo"
key_ids = [
Expand Down

0 comments on commit 05b7bc1

Please sign in to comment.