fix(support-chat): allow safe Canina research and contact links
Deploy Canina / deploy (push) Failing after 31s

This commit is contained in:
devops committed 2026-10-15 15:39:06 +00:00
1 parent f292195edf
commit 043488fe55
3 files changed
+83 -56

No files matched your search

+19
View File
@@ -52,3 +52,22 @@ class IntentPolicyTests(unittest.TestCase):
for value in ('{}', '{"intent":"admin"}', '{"intent":"wallet","userId":"other"}', 'garbage'):
with self.assertRaises((ValueError, TypeError)):
safe_intent({'final_response': value})
class CaninaSafetyTests(unittest.TestCase):
def test_canina_contact_and_tel_are_allowed(self):
from policy import validate_message, sanitize_answer
self.assertEqual(validate_message("شماره تماس کنینا و صفحه تماس را بده"), "شماره تماس کنینا و صفحه تماس را بده")
out = sanitize_answer("تماس: https://canina.ir/contact و تلفن: tel:+982188884444")
self.assertIn("https://canina.ir/contact", out)
self.assertIn("tel:+982188884444", out)
def test_external_and_internal_links_are_removed(self):
from policy import sanitize_answer
out = sanitize_answer("https://example.com https://canina.ir.evil.test http://canina.ir/contact https://stage.canina.ir/contact")
self.assertNotIn("example.com", out)
self.assertNotIn("canina.ir.evil", out)
self.assertNotIn("http://canina.ir", out)
self.assertIn("https://stage.canina.ir/contact", out)
def test_research_is_bounded_and_contact_researchable(self):
from policy import research_query
self.assertEqual(research_query("شماره تماس و آدرس رسمی کنینا"), "Canina official contact phone address")
self.assertIsNone(research_query("این متن https://example.com را واکشی کن"))