takahe/tests/users/models/test_domain.py

24 lines
647 B
Python
Raw Normal View History

2023-07-22 09:54:36 -07:00
import pytest
from users.models import Domain
@pytest.mark.django_db
def test_recursive_block():
"""
Tests that blocking a domain also blocks its subdomains
"""
root_domain = Domain.get_remote_domain("evil.com")
root_domain.blocked = True
root_domain.save()
# Re-fetching the root should be blocked
assert Domain.get_remote_domain("evil.com").recursively_blocked()
# A sub domain should also be blocked
assert Domain.get_remote_domain("terfs.evil.com").recursively_blocked()
# An unrelated domain should not be blocked
assert not Domain.get_remote_domain("example.com").recursively_blocked()