Spaces:
Running
Running
GitHub Actions commited on
Commit ·
84c1ab9
1
Parent(s): 3ea15ff
Deploy a68420a
Browse files- app/models/chat.py +6 -1
- tests/test_chat_endpoint.py +2 -1
- tests/test_models.py +5 -5
app/models/chat.py
CHANGED
|
@@ -11,7 +11,12 @@ class SourceRef(BaseModel):
|
|
| 11 |
|
| 12 |
class ChatRequest(BaseModel):
|
| 13 |
message: str = Field(..., min_length=1, max_length=500)
|
| 14 |
-
session_id: str = Field(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
|
| 17 |
class ChatResponse(BaseModel):
|
|
|
|
| 11 |
|
| 12 |
class ChatRequest(BaseModel):
|
| 13 |
message: str = Field(..., min_length=1, max_length=500)
|
| 14 |
+
session_id: str = Field(
|
| 15 |
+
...,
|
| 16 |
+
min_length=1,
|
| 17 |
+
max_length=64,
|
| 18 |
+
pattern=r"^[a-zA-Z0-9_-]+$",
|
| 19 |
+
)
|
| 20 |
|
| 21 |
|
| 22 |
class ChatResponse(BaseModel):
|
tests/test_chat_endpoint.py
CHANGED
|
@@ -52,7 +52,8 @@ class TestChatInputValidation:
|
|
| 52 |
assert resp.status_code == 422
|
| 53 |
|
| 54 |
def test_invalid_session_id_returns_422(self, app_client, valid_token):
|
| 55 |
-
|
|
|
|
| 56 |
assert resp.status_code == 422
|
| 57 |
|
| 58 |
def test_missing_session_id_returns_422(self, app_client, valid_token):
|
|
|
|
| 52 |
assert resp.status_code == 422
|
| 53 |
|
| 54 |
def test_invalid_session_id_returns_422(self, app_client, valid_token):
|
| 55 |
+
# session_id must match ^[a-zA-Z0-9_-]+$ — spaces and special chars are rejected.
|
| 56 |
+
resp = chat(app_client, "hello", session_id="invalid id with spaces!", token=valid_token)
|
| 57 |
assert resp.status_code == 422
|
| 58 |
|
| 59 |
def test_missing_session_id_returns_422(self, app_client, valid_token):
|
tests/test_models.py
CHANGED
|
@@ -29,14 +29,14 @@ class TestChatRequest:
|
|
| 29 |
assert len(req.message) == 500
|
| 30 |
|
| 31 |
def test_invalid_session_id_rejected(self):
|
| 32 |
-
#
|
| 33 |
with pytest.raises(ValidationError):
|
| 34 |
-
ChatRequest(message="hello", session_id="
|
| 35 |
|
| 36 |
-
def
|
| 37 |
-
#
|
| 38 |
with pytest.raises(ValidationError):
|
| 39 |
-
ChatRequest(message="hello", session_id="
|
| 40 |
|
| 41 |
def test_missing_message_rejected(self):
|
| 42 |
with pytest.raises(ValidationError):
|
|
|
|
| 29 |
assert len(req.message) == 500
|
| 30 |
|
| 31 |
def test_invalid_session_id_rejected(self):
|
| 32 |
+
# Contains spaces and special chars not in [a-zA-Z0-9_-]
|
| 33 |
with pytest.raises(ValidationError):
|
| 34 |
+
ChatRequest(message="hello", session_id="invalid id with spaces!")
|
| 35 |
|
| 36 |
+
def test_session_id_with_special_chars_rejected(self):
|
| 37 |
+
# @ and # are not in the allowed set [a-zA-Z0-9_-]
|
| 38 |
with pytest.raises(ValidationError):
|
| 39 |
+
ChatRequest(message="hello", session_id="bad@session#id")
|
| 40 |
|
| 41 |
def test_missing_message_rejected(self):
|
| 42 |
with pytest.raises(ValidationError):
|