|
12 | 12 | import os |
13 | 13 | import shutil |
14 | 14 |
|
15 | | -import yaml |
16 | 15 | from behave import given # pyright: ignore[reportAttributeAccessIssue] |
17 | 16 | from behave.runner import Context |
18 | 17 |
|
19 | | -from tests.e2e.utils.utils import ( |
20 | | - create_config_backup, |
21 | | - restart_container, |
22 | | - switch_config, |
| 18 | +from tests.e2e.features.steps.proxy import ( |
| 19 | + _LLAMA_STACK_CONFIG, |
| 20 | + _load_llama_config, |
| 21 | + _write_config, |
23 | 22 | ) |
24 | 23 |
|
25 | | -# Llama Stack config — mounted into the container from the host |
26 | | -_LLAMA_STACK_CONFIG = "run.yaml" |
27 | 24 | _LLAMA_STACK_CONFIG_BACKUP = "run.yaml.tls-backup" |
28 | 25 |
|
29 | | -_LIGHTSPEED_STACK_CONFIG = "lightspeed-stack.yaml" |
30 | | - |
31 | | - |
32 | | -def _load_llama_config() -> dict: |
33 | | - """Load the base Llama Stack run config. |
34 | | -
|
35 | | - Returns: |
36 | | - The parsed YAML configuration as a dictionary. |
37 | | - """ |
38 | | - with open(_LLAMA_STACK_CONFIG, encoding="utf-8") as f: |
39 | | - return yaml.safe_load(f) |
40 | | - |
41 | | - |
42 | | -def _write_config(config: dict, path: str) -> None: |
43 | | - """Write a YAML config file. |
44 | | -
|
45 | | - Parameters: |
46 | | - config: The configuration dictionary to write. |
47 | | - path: The file path to write to. |
48 | | - """ |
49 | | - with open(path, "w", encoding="utf-8") as f: |
50 | | - yaml.dump(config, f, default_flow_style=False) |
51 | | - |
52 | 26 |
|
53 | 27 | _TLS_PROVIDER_BASE: dict = { |
54 | 28 | "provider_id": "tls-openai", |
@@ -124,28 +98,6 @@ def _prepare_tls_provider() -> tuple[dict, dict]: |
124 | 98 | # proxy.py and shared across features by behave. |
125 | 99 |
|
126 | 100 |
|
127 | | -@given("Lightspeed Stack is configured for TLS testing") |
128 | | -def configure_lightspeed_for_tls(context: Context) -> None: |
129 | | - """Switch lightspeed-stack.yaml to the TLS test configuration. |
130 | | -
|
131 | | - Backs up the current config and switches to the TLS variant that sets |
132 | | - default_provider to tls-openai and default_model to mock-tls-model. |
133 | | - The backup is restored in after_scenario via the shared restore step. |
134 | | -
|
135 | | - Parameters: |
136 | | - context: Behave test context. |
137 | | - """ |
138 | | - mode_dir = "library-mode" if context.is_library_mode else "server-mode" |
139 | | - tls_config = f"tests/e2e/configuration/{mode_dir}/lightspeed-stack-tls.yaml" |
140 | | - |
141 | | - if not hasattr(context, "default_config_backup"): |
142 | | - context.default_config_backup = create_config_backup(_LIGHTSPEED_STACK_CONFIG) |
143 | | - |
144 | | - switch_config(tls_config) |
145 | | - restart_container("lightspeed-stack") |
146 | | - context.tls_config_active = True |
147 | | - |
148 | | - |
149 | 101 | # --- TLS Configuration Steps --- |
150 | 102 |
|
151 | 103 |
|
@@ -210,6 +162,54 @@ def configure_tls_mtls(context: Context) -> None: |
210 | 162 | _write_config(config, _LLAMA_STACK_CONFIG) |
211 | 163 |
|
212 | 164 |
|
| 165 | +@given('Llama Stack is configured with CA certificate path "{path}"') |
| 166 | +def configure_tls_verify_ca_path(context: Context, path: str) -> None: |
| 167 | + """Configure run.yaml with TLS verify pointing to a specific CA cert path. |
| 168 | +
|
| 169 | + Parameters: |
| 170 | + context: Behave test context. |
| 171 | + path: Path to the CA certificate file. |
| 172 | + """ |
| 173 | + config, provider = _prepare_tls_provider() |
| 174 | + provider["config"]["network"]["tls"] = {"verify": path} |
| 175 | + _write_config(config, _LLAMA_STACK_CONFIG) |
| 176 | + |
| 177 | + |
| 178 | +@given("Llama Stack is configured for mTLS without client certificate") |
| 179 | +def configure_mtls_no_client_cert(context: Context) -> None: |
| 180 | + """Configure run.yaml for mTLS port but without providing client certificate. |
| 181 | +
|
| 182 | + This should fail because the mTLS server requires a client certificate. |
| 183 | +
|
| 184 | + Parameters: |
| 185 | + context: Behave test context. |
| 186 | + """ |
| 187 | + config, provider = _prepare_tls_provider() |
| 188 | + provider["config"]["base_url"] = "https://mock-tls-inference:8444/v1" |
| 189 | + provider["config"]["network"]["tls"] = {"verify": "/certs/ca.crt"} |
| 190 | + _write_config(config, _LLAMA_STACK_CONFIG) |
| 191 | + |
| 192 | + |
| 193 | +@given("Llama Stack is configured for mTLS with wrong client certificate") |
| 194 | +def configure_mtls_wrong_client_cert(context: Context) -> None: |
| 195 | + """Configure run.yaml for mTLS with a certificate not issued by the server's CA. |
| 196 | +
|
| 197 | + Uses the CA cert itself as the client cert, which is not a valid client |
| 198 | + identity certificate, causing the mTLS handshake to fail. |
| 199 | +
|
| 200 | + Parameters: |
| 201 | + context: Behave test context. |
| 202 | + """ |
| 203 | + config, provider = _prepare_tls_provider() |
| 204 | + provider["config"]["base_url"] = "https://mock-tls-inference:8444/v1" |
| 205 | + provider["config"]["network"]["tls"] = { |
| 206 | + "verify": "/certs/ca.crt", |
| 207 | + "client_cert": "/certs/ca.crt", |
| 208 | + "client_key": "/certs/client.key", |
| 209 | + } |
| 210 | + _write_config(config, _LLAMA_STACK_CONFIG) |
| 211 | + |
| 212 | + |
213 | 213 | @given('Llama Stack is configured with TLS minimum version "{version}"') |
214 | 214 | def configure_tls_min_version(context: Context, version: str) -> None: |
215 | 215 | """Configure run.yaml with TLS minimum version. |
|
0 commit comments