fix(applications): bound public submission data
This commit is contained in:
1 parent
038d1f41a5
commit
61036641f8
3 files changed
+81
-5
No files matched your search
@@ -2,7 +2,8 @@ import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
from app.belki.applications import ApplicationError, ApplicationStore, validate_application
|
||||
from app.belki.applications import (MAX_APPLICATION_ATTACHMENTS, MAX_APPLICATION_FEATHERS,
|
||||
ApplicationError, ApplicationStore, validate_application)
|
||||
from app.belki.google_sheets_export import GoogleSheetsExportConfig, GoogleSheetsExportService
|
||||
from app.belki.identity import IdentityDirectory
|
||||
from app.belki.vk_bot import ApplicationDialog
|
||||
@@ -27,6 +28,31 @@ class ApplicationTests(unittest.TestCase):
|
||||
expected = link if link.startswith("https://") else f"https://{link}"
|
||||
self.assertEqual(application["vk_link"], expected)
|
||||
|
||||
def test_application_rejects_non_vk_or_insecure_profile_links(self) -> None:
|
||||
for link in ("http://vk.com/id1", "https://vk.com.evil.test/id1", "https://example.test"):
|
||||
with self.subTest(link=link), self.assertRaisesRegex(ApplicationError, "HTTPS-ссылку на страницу VK"):
|
||||
validate_application({
|
||||
"type": "flying_squirrel", "name": "Муся", "character_id": 1337,
|
||||
"practiced_before": False, "vk_link": link,
|
||||
})
|
||||
|
||||
def test_application_bounds_attachment_and_feather_fan_out(self) -> None:
|
||||
too_many_attachments = [{"url": "https://img.example.test/photo.jpg"}] * (MAX_APPLICATION_ATTACHMENTS + 1)
|
||||
with self.assertRaisesRegex(ApplicationError, "не более"):
|
||||
validate_application({"type": "kitten", "name": "Муся", "character_id": 1337, "attachments": too_many_attachments})
|
||||
too_many_feathers = [{"amount": 1, "color": "синее", "source": "запасы"}] * (MAX_APPLICATION_FEATHERS + 1)
|
||||
with self.assertRaisesRegex(ApplicationError, "не более"):
|
||||
validate_application({"type": "feather_donation", "name": "Муся", "character_id": 1337, "feathers": too_many_feathers})
|
||||
|
||||
def test_application_requires_https_attachment_and_practice_review_links(self) -> None:
|
||||
with self.assertRaisesRegex(ApplicationError, "(?i)вложение.*https"):
|
||||
validate_application({"type": "kitten", "name": "Муся", "character_id": 1337, "attachments": [{"url": "http://example.test/a.jpg"}]})
|
||||
with self.assertRaisesRegex(ApplicationError, "(?i)комментарий.*https"):
|
||||
validate_application({
|
||||
"type": "flying_squirrel", "name": "Муся", "character_id": 1337,
|
||||
"practiced_before": True, "practice_review_link": "http://example.test/review",
|
||||
})
|
||||
|
||||
def test_feather_donation_is_saved_and_accepted(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
store = ApplicationStore(sqlite_path=Path(directory) / "applications.sqlite3")
|
||||
|
||||
Reference in new issue
Block a user