Skip to content

Commit b1fbacd

Browse files
committed
Adding explicit TLS output checks
1 parent 2a71a89 commit b1fbacd

2 files changed

Lines changed: 45 additions & 2 deletions

File tree

tests/e2e/features/tls.feature

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Feature: TLS configuration for remote inference providers
2121
{"query": "Say hello", "model": "mock-tls-model", "provider": "tls-openai"}
2222
"""
2323
Then The status code of the response is 200
24+
And The body of the response contains Hello from the TLS mock inference server
2425

2526
Scenario: Inference succeeds with CA certificate verification
2627
Given Llama Stack is configured with CA certificate verification
@@ -31,6 +32,7 @@ Feature: TLS configuration for remote inference providers
3132
{"query": "Say hello", "model": "mock-tls-model", "provider": "tls-openai"}
3233
"""
3334
Then The status code of the response is 200
35+
And The body of the response contains Hello from the TLS mock inference server
3436

3537
Scenario: Inference fails with an untrusted CA certificate
3638
Given Llama Stack is configured with CA certificate path "/certs/untrusted-ca.crt"
@@ -74,6 +76,7 @@ Feature: TLS configuration for remote inference providers
7476
{"query": "Say hello", "model": "mock-tls-model", "provider": "tls-openai"}
7577
"""
7678
Then The status code of the response is 200
79+
And The body of the response contains Hello from the TLS mock inference server
7780

7881
Scenario: Inference fails when mTLS is required but no client certificate is provided
7982
Given Llama Stack is configured for mTLS without client certificate
@@ -150,6 +153,7 @@ Feature: TLS configuration for remote inference providers
150153
{"query": "Say hello", "model": "mock-tls-model", "provider": "tls-openai"}
151154
"""
152155
Then The status code of the response is 200
156+
And The body of the response contains Hello from the TLS mock inference server
153157

154158
Scenario: Inference fails with TLS minimum version TLSv1.3 and untrusted CA certificate
155159
Given Llama Stack is configured with TLS minimum version "TLSv1.3" and CA certificate path "/certs/untrusted-ca.crt"

tests/e2e/mock_tls_inference_server/server.py

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,49 @@ def do_POST(self) -> None: # pylint: disable=invalid-name
7575
request_data = {}
7676

7777
model = request_data.get("model", MODEL_ID)
78+
completion_id = "chatcmpl-tls-test-001"
79+
response_text = "Hello from the TLS mock inference server."
80+
81+
# Llama Stack calls remote chat completions with stream=True and reads
82+
# assistant text from delta.content chunks.
83+
if request_data.get("stream"):
84+
self.send_response(200)
85+
self.send_header("Content-Type", "text/event-stream")
86+
self.send_header("Cache-Control", "no-cache")
87+
self.end_headers()
88+
content_chunk = {
89+
"id": completion_id,
90+
"object": "chat.completion.chunk",
91+
"created": 1700000000,
92+
"model": model,
93+
"choices": [
94+
{
95+
"index": 0,
96+
"delta": {"role": "assistant", "content": response_text},
97+
"finish_reason": None,
98+
}
99+
],
100+
}
101+
self.wfile.write(f"data: {json.dumps(content_chunk)}\n\n".encode())
102+
finish_chunk = {
103+
"id": completion_id,
104+
"object": "chat.completion.chunk",
105+
"created": 1700000000,
106+
"model": model,
107+
"choices": [{"index": 0, "delta": {}, "finish_reason": "stop"}],
108+
"usage": {
109+
"prompt_tokens": 8,
110+
"completion_tokens": 9,
111+
"total_tokens": 17,
112+
},
113+
}
114+
self.wfile.write(f"data: {json.dumps(finish_chunk)}\n\n".encode())
115+
self.wfile.write(b"data: [DONE]\n\n")
116+
return
78117

79118
self._send_json(
80119
{
81-
"id": "chatcmpl-tls-test-001",
120+
"id": completion_id,
82121
"object": "chat.completion",
83122
"created": 1700000000,
84123
"model": model,
@@ -87,7 +126,7 @@ def do_POST(self) -> None: # pylint: disable=invalid-name
87126
"index": 0,
88127
"message": {
89128
"role": "assistant",
90-
"content": "Hello from the TLS mock inference server.",
129+
"content": response_text,
91130
},
92131
"finish_reason": "stop",
93132
}

0 commit comments

Comments
 (0)