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 tests latest post #1391

Merged
merged 6 commits into from
Feb 16, 2025
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
11 changes: 10 additions & 1 deletion ChangeLog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Inyoka Changelog
-----------


Unreleased 1.42.1 (2025-01-DD)
Unreleased 1.42.2 (2025-02-DD)
==============================

Deployment notes
Expand Down Expand Up @@ -67,6 +67,15 @@ Deployment notes
* Update requirements (at least the dependencies ``Django`` and ``jinja2`` includes known security fixes)


1.42.1 (2025-02-16)
===================

🔒 Security
-----------

* Prevent to leak posts via `__service__=forum.get_new_latest_posts`


1.42.0 (2024-11-23)
===================

Expand Down
2 changes: 1 addition & 1 deletion inyoka/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@
from .celery_app import app as celery_app # noqa

# Inyoka version is updated through bumpversion and can stay hardcoded here.
INYOKA_VERSION = "1.42.0"
INYOKA_VERSION = "1.42.1"
10 changes: 9 additions & 1 deletion inyoka/forum/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"""
from urllib.parse import unquote

from django.http import HttpResponseBadRequest
from django.shortcuts import render
from django.utils.datastructures import MultiValueDictKeyError
from django.views.decorators.http import require_GET, require_POST
Expand Down Expand Up @@ -164,9 +165,16 @@ def get_version_details(request):
@require_POST
@dispatcher.register()
def get_new_latest_posts(request):
post_id = int(request.POST['post'])
try:
post_id = int(request.POST.get('post'))
except (TypeError, ValueError):
return HttpResponseBadRequest()

post = Post.objects.get(id=post_id)

if not request.user.has_perm('forum.view_forum', post.topic.forum) or (not request.user.has_perm('forum.moderate_forum', post.topic.forum) and post.topic.hidden or post.hidden):
return None

posts = Post.objects.filter(id__gt=post.id, topic__id=post.topic.id) \
.order_by('-position').all()

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "inyoka",
"title": "Inyoka theme",
"version": "1.42.0",
"version": "1.42.1",
"description": "Inyoka Theme",
"main": "index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ ignore = [


[tool.bumpversion]
current_version = "1.42.0"
current_version = "1.42.1"
parse = "(?P<major>\\d+)\\.(?P<django>\\d+)\\.(?P<patch>\\d+)"
serialize = ["{major}.{django}.{patch}"]
search = "{current_version}"
Expand Down
20 changes: 19 additions & 1 deletion tests/apps/forum/test_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,27 @@ def setUp(self):
topic=self.topic, position=0)

self.client.defaults['HTTP_HOST'] = 'forum.%s' % settings.BASE_DOMAIN_NAME
#self.client.login(username='admin', password='admin')

def test_get_new_latest_posts(self):
self.client.login(username='admin', password='admin')

response = self.client.post('/?__service__=forum.get_new_latest_posts', data={'post': self.post.id}, follow=True)
self.assertEqual(response.status_code, 200)
self.assertContains(response, 'Post 2')

def test_get_new_latest_posts__anonymous(self):
response = self.client.post('/?__service__=forum.get_new_latest_posts', data={'post': self.post.id}, follow=True)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.content.decode(), 'null')

def test_get_new_latest_posts__missing_post_parameter(self):
response = self.client.post('/?__service__=forum.get_new_latest_posts', follow=True)
self.assertEqual(response.status_code, 400)

def test_get_new_latest_posts__string_as_post_parameter(self):
response = self.client.post('/?__service__=forum.get_new_latest_posts', data={'post': 'foo'}, follow=True)
self.assertEqual(response.status_code, 400)

def test_get_new_latest_posts__get_method(self):
response = self.client.get('/?__service__=forum.get_new_latest_posts', follow=True)
self.assertEqual(response.status_code, 400)
Loading