|
| 1 | +from datetime import datetime, timedelta |
| 2 | +from tempfile import mkstemp |
1 | 3 | import json |
2 | 4 | import os |
3 | 5 | import shutil |
4 | 6 | import subprocess |
5 | 7 | import sys |
6 | | -import tempfile |
7 | 8 | import pytest |
8 | 9 |
|
9 | 10 | from cryptography import x509 |
10 | 11 | from cryptography.x509.oid import NameOID |
11 | 12 | from cryptography.hazmat.primitives import hashes, serialization |
12 | 13 | from cryptography.hazmat.primitives.asymmetric import rsa |
13 | | -from datetime import datetime, timedelta |
14 | 14 | from dotenv import load_dotenv |
15 | 15 | from gardenlinux.features import Parser |
16 | 16 |
|
|
26 | 26 | TEST_FEATURE_STRINGS_SHORT, |
27 | 27 | TEST_ARCHITECTURES, |
28 | 28 | ) |
| 29 | + |
29 | 30 | from .helper import call_command, spawn_background_process |
30 | 31 |
|
31 | 32 |
|
@@ -80,11 +81,6 @@ def generate_test_certificates(): |
80 | 81 | print(f"Generated test certificates in {CERT_DIR}") |
81 | 82 |
|
82 | 83 |
|
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 | | - |
88 | 84 | def create_test_data(): |
89 | 85 | """Generate test data for OCI registry tests (replaces build-test-data.sh)""" |
90 | 86 | print("Creating fake artifacts...") |
@@ -127,20 +123,46 @@ def create_test_data(): |
127 | 123 | f.write(f"dummy content for {file_path}") |
128 | 124 |
|
129 | 125 |
|
| 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 | + |
130 | 131 | @pytest.fixture(autouse=False, scope="function") |
131 | 132 | def zot_session(): |
132 | 133 | load_dotenv() |
133 | 134 | print("start zot session") |
| 135 | + |
| 136 | + fd, temp_htaccess_file = mkstemp(dir=TEST_DATA_DIR, suffix=".htpasswd") |
| 137 | + os.close(fd) |
| 138 | + |
134 | 139 | zot_config = { |
135 | 140 | "distSpecVersion": "1.1.0", |
136 | 141 | "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": { |
| 146 | + "htpasswd": { |
| 147 | + "path": f"{temp_htaccess_file}" |
| 148 | + } |
| 149 | + }, |
| 150 | + "accessControl": { |
| 151 | + "repositories": { |
| 152 | + "**": { |
| 153 | + "anonymousPolicy": ["read", "create", "update", "delete"] |
| 154 | + }, |
| 155 | + "protected/**": { |
| 156 | + "anonymousPolicy": [] |
| 157 | + } |
| 158 | + } |
| 159 | + } |
| 160 | + }, |
138 | 161 | "log": {"level": "warn"}, |
139 | 162 | } |
140 | 163 |
|
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 |
| 164 | + fd, zot_config_file_path = mkstemp(text=True, dir=TEST_DATA_DIR, suffix=".json") |
| 165 | + write_zot_config(zot_config, fd) |
144 | 166 |
|
145 | 167 | print(f"Spawning zot registry with config {zot_config_file_path}") |
146 | 168 | zot_process = spawn_background_process( |
|
0 commit comments