GitHub Actions commited on
Commit
84c1ab9
·
1 Parent(s): 3ea15ff

Deploy a68420a

Browse files
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(..., pattern=r"^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$")
 
 
 
 
 
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
- resp = chat(app_client, "hello", session_id="not-a-uuid", token=valid_token)
 
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
- # Not a valid UUID v4
33
  with pytest.raises(ValidationError):
34
- ChatRequest(message="hello", session_id="not-a-uuid")
35
 
36
- def test_non_v4_uuid_rejected(self):
37
- # UUID v1 the pattern enforces the 4xxx-[89ab]xxx format
38
  with pytest.raises(ValidationError):
39
- ChatRequest(message="hello", session_id="a1b2c3d4-e5f6-1789-8abc-def012345678")
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):