Skip to content

Commit

Permalink
feat: Use candlepin container's cert for REST calls
Browse files Browse the repository at this point in the history
This automatically copies the candlepin cert for use in REST calls
when using the container deployed 'candlepin' context.

Signed off by: J.C. Molet <[email protected]>
  • Loading branch information
Lorquas committed Jul 15, 2024
1 parent 11e560d commit c1ae965
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
4 changes: 2 additions & 2 deletions pytest_client_tools/candlepin.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ class Candlepin:
This class represents a Candlepin server.
"""

def __init__(self, host, port, prefix, insecure):
def __init__(self, host, port, prefix, insecure, verify=False):
self._host = host
self._port = port
self._prefix = prefix
self._insecure = insecure
self._rest_client = RestClient(
base_url=f"https://{self._host}:{self._port}{self._prefix}",
verify=False,
verify=verify,
)

@property
Expand Down
20 changes: 19 additions & 1 deletion pytest_client_tools/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import logging
import shutil
import subprocess
import tempfile

import pytest

Expand Down Expand Up @@ -91,15 +92,32 @@ def candlepin(request):
"--candlepin-container-is-running"
)
initial_wait = 0
verify = False
if start_container:
stack.enter_context(_create_candlepin_container())
container = _create_candlepin_container()
stack.enter_context(container)
# candlepin takes a while to start
initial_wait = 5
temp_cert = tempfile.NamedTemporaryFile()
stack.enter_context(temp_cert)
subprocess.run(
[
"podman",
"cp",
f"{container.running_id}:/etc/candlepin/certs/candlepin-ca.crt",
temp_cert.name,
],
check=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
verify = temp_cert.name
candlepin = Candlepin(
host="localhost",
port=8443,
prefix="/candlepin",
insecure=True,
verify=verify,
)
ping_candlepin(candlepin, initial_wait=initial_wait)
yield candlepin
Expand Down

0 comments on commit c1ae965

Please sign in to comment.