mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-01-28 08:03:36 +00:00
We are currently using django.utils.http.is_safe_url which is a private method and may break API anytime. Replace it with similar but limited implementation. Tests: - Unit tests. - Dismiss a notification and the redirect to the same page happens properly. - Logout, goto to home page or login page. Change the language and it will redirect back to home page or login page appropriately. Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
32 lines
615 B
Python
32 lines
615 B
Python
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
"""
|
|
Tests for common FreedomBox views.
|
|
"""
|
|
|
|
import pytest
|
|
|
|
from plinth.views import is_safe_url
|
|
|
|
|
|
@pytest.mark.parametrize('url', [
|
|
'/plinth/login/',
|
|
'/',
|
|
'safe',
|
|
])
|
|
def test_is_safe_url_valid_url(url):
|
|
"""Test valid URLs for safe URL checks."""
|
|
assert is_safe_url(url)
|
|
|
|
|
|
@pytest.mark.parametrize('url', [
|
|
'',
|
|
None,
|
|
'\\plinth',
|
|
'///plinth',
|
|
'https://example.com/plinth/login/',
|
|
'https:///plinth/login',
|
|
])
|
|
def test_is_safe_url_invalid_url(url):
|
|
"""Test invalid URLs for safe URL checks."""
|
|
assert not is_safe_url(url)
|