Skip to content

Commit

Permalink
cert handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Vincinator committed Aug 13, 2024
1 parent 4b08a12 commit b9d7fdb
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
cert
output
cert/
token.sh
Expand All @@ -9,3 +8,4 @@ example.manifest.json
.idea
dist
foobar.json
tests/__pycache__/
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ ifneq (,$(wildcard ./.env))
export
endif

gencert:
./cert/gencert.sh

serve-oci:
zot serve $(ZOT_CONFIG_FILE)

Expand All @@ -29,7 +32,7 @@ install_deps: ## Install dependencies.
$(VENV)/bin/pip install -r requirements.txt


example-%:
example-%: gencert
@echo "==== DEMO ===="
@echo "=== Inspect oci-index"
$(PYTHON) -m gloci.cli image inspect-index --container $(CONTAINER_NAME_$@) --version $(CONTAINER_IMAGE_VERSION)
Expand Down
8 changes: 8 additions & 0 deletions cert/gencert.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
CERT_NAME="$SCRIPT_DIR/oci-sign"


openssl req -x509 -newkey rsa -pkeyopt rsa_keygen_bits:4096 -days 3650 -nodes -keyout $CERT_NAME.key -out $CERT_NAME.crt -subj "/CN=Garden Linux test signing key for oci"

5 changes: 5 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from .helper import call_command

def pytest_sessionstart(session):
call_command("./cert/gencert.sh")

20 changes: 20 additions & 0 deletions tests/helper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import subprocess
import shlex

def spawn_background_process(command):
process = subprocess.Popen(command)
return process


def call_command(cmd):
try:
args = shlex.split(cmd)
result = subprocess.run(
args, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE
)
output = result.stdout.decode("utf-8")
return output

except subprocess.CalledProcessError as e:
error_message = e.stderr.decode("utf-8")
return f"An error occurred: {error_message}"
29 changes: 4 additions & 25 deletions tests/test_push_image.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,19 @@
import subprocess
from dotenv import load_dotenv
import shlex
import pytest
from click.testing import CliRunner
from gloci.cli import cli


from .helper import spawn_background_process
ZOT_CONFIG_FILE = "./zot/config.json"
CONTAINER_NAME_ZOT_EXAMPLE = "localhost:8081/examplecontainer2"


def spawn_background_process(command):
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
return process


def call_command(cmd):
try:
args = shlex.split(cmd)
result = subprocess.run(
args, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE
)
output = result.stdout.decode("utf-8")
return output

except subprocess.CalledProcessError as e:
error_message = e.stderr.decode("utf-8")
return f"An error occurred: {error_message}"


@pytest.fixture
def setup_test_environment():
print("Spawning zot registry")
zot_process = spawn_background_process(f"zot serve {ZOT_CONFIG_FILE}")


yield zot_process

zot_process.terminate()
Expand Down Expand Up @@ -73,11 +54,9 @@ def test_push_example(info_yaml_path, version, cname, arch):
],
)
if result.exit_code != 0:
# Print the output and error message for debugging
print(f"Exit Code: {result.exit_code}")
print(f"Output: {result.output}")
print(
f"Error: {result.stderr}"
) # If stderr was captured (can also be in result.output)

)
assert result.exit_code == 0

0 comments on commit b9d7fdb

Please sign in to comment.