11"""Tests that verify Flatpak support"""
22
33import os
4- import pytest
54import subprocess
6- from urllib .parse import urlparse
5+
6+ import pytest
77
88from pulp_container .tests .functional .constants import REGISTRY_V2
99
10+ PULP_CA_CERT = "/etc/pulp/certs/pulp_webserver.crt"
11+
12+
13+ def _ensure_system_trust ():
14+ """Add the Pulp CA cert to the system trust store so flatpak can verify TLS.
15+
16+ On RHEL 9, both flatpak (via GLib/libsoup) and Python's OpenSSL resolve trust
17+ through p11-kit. The only reliable way to make flatpak accept the self-signed
18+ Pulp webserver cert is to register it as a trust anchor. This is safe to call
19+ after the certifi patching in script.sh because `trust anchor` only *adds* to
20+ the trust store.
21+ """
22+ anchor = "/etc/pki/ca-trust/source/anchors/pulp_webserver.crt"
23+ if os .path .exists (PULP_CA_CERT ) and not os .path .exists (anchor ):
24+ subprocess .check_call (["cp" , PULP_CA_CERT , anchor ])
25+ subprocess .check_call (["update-ca-trust" ])
26+ # Re-patch certifi in case update-ca-trust regenerated the bundle it points to.
27+ result = subprocess .run (
28+ ["python3" , "-c" , "import certifi; print(certifi.where())" ],
29+ capture_output = True ,
30+ text = True ,
31+ )
32+ if result .returncode == 0 :
33+ certifi_path = result .stdout .strip ()
34+ subprocess .run (
35+ ["bash" , "-c" , f"cat { PULP_CA_CERT } >> '{ certifi_path } '" ],
36+ check = False ,
37+ )
38+
1039
1140def run_flatpak_commands (host ):
41+ _ensure_system_trust ()
42+
1243 # Remove any leftover remote from a previous failed run before starting.
1344 subprocess .run (["flatpak" , "--user" , "remote-delete" , "--force" , "pulptest" ], check = False )
1445
@@ -22,27 +53,6 @@ def run_flatpak_commands(host):
2253 ]
2354 )
2455
25- # OSTree (used by flatpak) verifies TLS against the system CA store, not certifi.
26- # For CI environments using a self-signed cert, configure the remote to trust
27- # the Pulp CA directly rather than relying on system-wide CA trust, which would
28- # interfere with the Python bindings trust setup in script.sh.
29- if urlparse (host ).scheme == "https" :
30- flatpak_user_repo = os .path .expanduser ("~/.local/share/flatpak/repo" )
31- ca_cert = "/etc/pulp/certs/pulp_webserver.crt"
32- tls_option = f"tls-ca-path={ ca_cert } " if os .path .exists (ca_cert ) else "tls-permissive=true"
33- config_path = os .path .join (flatpak_user_repo , "config" )
34- try :
35- with open (config_path ) as f :
36- content = f .read ()
37- content = content .replace (
38- '[remote "pulptest"]' ,
39- f'[remote "pulptest"]\n { tls_option } ' ,
40- )
41- with open (config_path , "w" ) as f :
42- f .write (content )
43- except OSError :
44- pass
45-
4656 try :
4757 # See <https://pagure.io/fedora-lorax-templates/c/cc1155372046baa58f9d2cc27a9e5473bf05a3fb>
4858 # "lorax-embed-flatpaks.tmpl: Run the flatpak-install under dbus-run-session" for the need
@@ -67,7 +77,7 @@ def run_flatpak_commands(host):
6777 "uninstall" ,
6878 "--noninteractive" ,
6979 "net.fishsoup.Hello" ,
70- ]
80+ ],
7181 )
7282 subprocess .run (
7383 [
@@ -76,7 +86,7 @@ def run_flatpak_commands(host):
7686 "uninstall" ,
7787 "--noninteractive" ,
7888 "net.fishsoup.BusyBoxPlatform" ,
79- ]
89+ ],
8090 )
8191 subprocess .run (["flatpak" , "--user" , "remote-delete" , "pulptest" ])
8292
0 commit comments