1+ from datetime import datetime , timedelta
2+ from tempfile import mkstemp
13import json
24import os
35import shutil
46import subprocess
57import sys
6- import tempfile
78import pytest
89
910from cryptography import x509
1011from cryptography .x509 .oid import NameOID
1112from cryptography .hazmat .primitives import hashes , serialization
1213from cryptography .hazmat .primitives .asymmetric import rsa
13- from datetime import datetime , timedelta
1414from dotenv import load_dotenv
1515from gardenlinux .features import Parser
1616
2626 TEST_FEATURE_STRINGS_SHORT ,
2727 TEST_ARCHITECTURES ,
2828)
29+
2930from .helper import call_command , spawn_background_process
3031
3132
@@ -80,11 +81,6 @@ def generate_test_certificates():
8081 print (f"Generated test certificates in { CERT_DIR } " )
8182
8283
83- def write_zot_config (config_dict , file_path ):
84- with open (file_path , "w" ) as config_file :
85- json .dump (config_dict , config_file , indent = 4 )
86-
87-
8884def create_test_data ():
8985 """Generate test data for OCI registry tests (replaces build-test-data.sh)"""
9086 print ("Creating fake artifacts..." )
@@ -127,20 +123,38 @@ def create_test_data():
127123 f .write (f"dummy content for { file_path } " )
128124
129125
126+ def write_zot_config (config_dict , fd ):
127+ with os .fdopen (fd , "w" ) as fp :
128+ json .dump (config_dict , fp , indent = 4 )
129+
130+
130131@pytest .fixture (autouse = False , scope = "function" )
131132def zot_session ():
132133 load_dotenv ()
133134 print ("start zot session" )
135+
136+ fd , htpasswd_file = mkstemp (dir = TEST_DATA_DIR , suffix = ".htpasswd" )
137+ os .close (fd )
138+
134139 zot_config = {
135140 "distSpecVersion" : "1.1.0" ,
136141 "storage" : {"rootDirectory" : "output/registry/zot" },
137- "http" : {"address" : "127.0.0.1" , "port" : "18081" },
142+ "http" : {
143+ "address" : "127.0.0.1" ,
144+ "port" : "18081" ,
145+ "auth" : {"htpasswd" : {"path" : f"{ htpasswd_file } " }},
146+ "accessControl" : {
147+ "repositories" : {
148+ "**" : {"anonymousPolicy" : ["read" , "create" , "update" , "delete" ]},
149+ "protected/**" : {"anonymousPolicy" : []},
150+ }
151+ },
152+ },
138153 "log" : {"level" : "warn" },
139154 }
140155
141- with tempfile .NamedTemporaryFile (delete = False , suffix = ".json" ) as temp_config_file :
142- write_zot_config (zot_config , temp_config_file .name )
143- zot_config_file_path = temp_config_file .name
156+ fd , zot_config_file_path = mkstemp (text = True , dir = TEST_DATA_DIR , suffix = ".json" )
157+ write_zot_config (zot_config , fd )
144158
145159 print (f"Spawning zot registry with config { zot_config_file_path } " )
146160 zot_process = spawn_background_process (
@@ -156,6 +170,8 @@ def zot_session():
156170
157171 if os .path .isdir ("./output" ):
158172 shutil .rmtree ("./output" )
173+ if os .path .isfile (htpasswd_file ):
174+ os .remove (htpasswd_file )
159175 if os .path .isfile (zot_config_file_path ):
160176 os .remove (zot_config_file_path )
161177
0 commit comments