Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: now applying the same verifications when creating or editing comments #1038

Merged
merged 1 commit into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions isso/tests/test_comments.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,22 @@ def testUpdate(self):
self.assertEqual(rv['website'], 'http://example.com/')
self.assertIn('modified', rv)

def testUpdateForbidden(self):

self.post('/new?uri=test', data=json.dumps({'text': 'Hello world!'}))

resp = self.put('/id/1', data=json.dumps({}))
self.assertEqual(resp.status, '400 BAD REQUEST')
self.assertIn('text is missing', resp.text)

resp = self.put('/id/1', data=json.dumps({'text': ''}))
self.assertEqual(resp.status, '400 BAD REQUEST')
self.assertIn('text is too short', resp.text)

resp = self.put('/id/1', data=json.dumps({'text': 'Hello again!', 'website': '[email protected]'}))
self.assertEqual(resp.status, '400 BAD REQUEST')
self.assertIn('Website not Django-conform', resp.text)

def testDelete(self):

self.post('/new?uri=%2Fpath%2F',
Expand Down
7 changes: 4 additions & 3 deletions isso/views/comments.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,12 +539,13 @@ def edit(self, environ, request, id):

data = request.json

if data.get("text") is None or len(data["text"]) < 3:
raise BadRequest("no text given")

for key in set(data.keys()) - set(["text", "author", "website"]):
data.pop(key)

valid, reason = API.verify(data)
if not valid:
return BadRequest(reason)

data['modified'] = time.time()

with self.isso.lock:
Expand Down
Loading