1- from . helper import call_command
1+ import json
22import os
3- import tempfile
4- from .helper import spawn_background_process
5- import sys
63import shutil
7- import json
4+ import subprocess
5+ import sys
6+ import tempfile
7+
88import pytest
99from dotenv import load_dotenv
1010
11- GL_ROOT_DIR = "test-data/gardenlinux"
11+ from .helper import call_command , spawn_background_process
12+
13+ TEST_DATA_DIR = "test-data"
14+ GL_ROOT_DIR = f"{ TEST_DATA_DIR } /gardenlinux"
15+ CERT_DIR = f"{ TEST_DATA_DIR } /cert"
16+
17+
18+ def generate_test_certificates ():
19+ """Generate self-signed certificates for testing"""
20+ os .makedirs (CERT_DIR , exist_ok = True )
21+ key_path = os .path .join (CERT_DIR , "oci-sign.key" )
22+ cert_path = os .path .join (CERT_DIR , "oci-sign.crt" )
23+ cmd = [
24+ "openssl" ,
25+ "req" ,
26+ "-x509" ,
27+ "-newkey" ,
28+ "rsa:4096" ,
29+ "-keyout" ,
30+ key_path ,
31+ "-out" ,
32+ cert_path ,
33+ "-days" ,
34+ "365" ,
35+ "-nodes" ,
36+ "-subj" ,
37+ "/CN=Garden Linux test signing key for oci" ,
38+ ]
39+ try :
40+ subprocess .run (cmd , check = True )
41+ # Set proper permissions
42+ os .chmod (key_path , 0o600 )
43+ print (f"Generated test certificates in { CERT_DIR } " )
44+ except subprocess .CalledProcessError as e :
45+ print (f"Error generating certificates: { e } " )
46+ raise
1247
1348
1449def write_zot_config (config_dict , file_path ):
@@ -33,7 +68,7 @@ def zot_session():
3368
3469 print (f"Spawning zot registry with config { zot_config_file_path } " )
3570 zot_process = spawn_background_process (
36- f"zot serve { zot_config_file_path } " ,
71+ f"{ TEST_DATA_DIR } / zot serve { zot_config_file_path } " ,
3772 stdout = sys .stdout ,
3873 stderr = sys .stderr ,
3974 )
@@ -50,12 +85,12 @@ def zot_session():
5085
5186
5287def pytest_sessionstart (session ):
53- call_command ( "./cert/gencert.sh" )
88+ generate_test_certificates ( )
5489 call_command ("./test-data/build-test-data.sh --dummy" )
5590
5691
5792def pytest_sessionfinish (session ):
58- if os .path .isfile ("./cert /oci-sign.crt" ):
59- os .remove ("./cert /oci-sign.crt" )
60- if os .path .isfile ("./cert /oci-sign.key" ):
61- os .remove ("./cert /oci-sign.key" )
93+ if os .path .isfile (CERT_DIR + " /oci-sign.crt" ):
94+ os .remove (CERT_DIR + " /oci-sign.crt" )
95+ if os .path .isfile (CERT_DIR + " /oci-sign.key" ):
96+ os .remove (CERT_DIR + " /oci-sign.key" )
0 commit comments