FreedomBox/plinth/tests/test_views.py
Sunil Mohan Adapa 07e62a213b
views: Update utility for checking URL safety
Django has updated the is_safe_url() method that we based our implementation on.
It is now called url_has_allowed_host_and_scheme(). Our implementation remains
simple as we don't allow any hostname or scheme to be set.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2021-09-26 11:25:07 -04:00

37 lines
760 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:///example.com',
'https:///plinth/login',
'ftp://example.com',
'https://[aabb::ccdd', # Invalid IPv6
])
def test_is_safe_url_invalid_url(url):
"""Test invalid URLs for safe URL checks."""
assert not is_safe_url(url)