mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-09-27 22:02:00 +00:00
2de115fc1e
In most cases, we want to return back to where we came from after performing an action. It's not safe to return to an arbitrary referer, so this streamlines using the util validator to verify the redirect and fall back on regular redirect params if the referer is outside our domain.
31 lines
942 B
Python
31 lines
942 B
Python
""" test searching for books """
|
|
import re
|
|
from django.test import TestCase
|
|
|
|
from bookwyrm.utils import regex
|
|
from bookwyrm.utils.validate import validate_url_domain
|
|
|
|
|
|
class TestUtils(TestCase):
|
|
"""utility functions"""
|
|
|
|
def test_regex(self):
|
|
"""Regexes used throughout the app"""
|
|
self.assertTrue(re.match(regex.DOMAIN, "xn--69aa8bzb.xn--y9a3aq"))
|
|
|
|
def test_valid_url_domain(self):
|
|
"""Check with a valid URL"""
|
|
self.assertEqual(
|
|
validate_url_domain("https://your.domain.here/legit-book-url/"),
|
|
"https://your.domain.here/legit-book-url/",
|
|
)
|
|
|
|
def test_invalid_url_domain(self):
|
|
"""Check with an invalid URL"""
|
|
self.assertIsNone(
|
|
validate_url_domain("https://up-to-no-good.tld/bad-actor.exe")
|
|
)
|
|
|
|
def test_default_url_domain(self):
|
|
"""Check with a default URL"""
|
|
self.assertEqual(validate_url_domain("/"), "/")
|