mirror of https://gitlab.com/bashrc2/epicyon
Function to check domains
parent
2a53e0148c
commit
083dddea0d
|
|
@ -16,6 +16,7 @@ from siteactive import referer_is_active
|
||||||
from httpcodes import http_400
|
from httpcodes import http_400
|
||||||
from httpcodes import http_404
|
from httpcodes import http_404
|
||||||
from httpcodes import http_503
|
from httpcodes import http_503
|
||||||
|
from utils import resembles_domain
|
||||||
from utils import get_json_content_from_accept
|
from utils import get_json_content_from_accept
|
||||||
from utils import convert_domains
|
from utils import convert_domains
|
||||||
from utils import local_network_host
|
from utils import local_network_host
|
||||||
|
|
@ -113,9 +114,7 @@ def _masto_api_v1(self, path: str, calling_domain: str,
|
||||||
# is this a real website making the call ?
|
# is this a real website making the call ?
|
||||||
if not debug and not unit_test and referer_domain:
|
if not debug and not unit_test and referer_domain:
|
||||||
# Does calling_domain look like a domain?
|
# Does calling_domain look like a domain?
|
||||||
if ' ' in referer_domain or \
|
if resembles_domain(referer_domain):
|
||||||
';' in referer_domain or \
|
|
||||||
'.' not in referer_domain:
|
|
||||||
print('mastodon api ' +
|
print('mastodon api ' +
|
||||||
'referer does not look like a domain ' +
|
'referer does not look like a domain ' +
|
||||||
referer_domain)
|
referer_domain)
|
||||||
|
|
@ -246,9 +245,7 @@ def _masto_api_v2(self, path: str, calling_domain: str,
|
||||||
# is this a real website making the call ?
|
# is this a real website making the call ?
|
||||||
if not debug and not unit_test and referer_domain:
|
if not debug and not unit_test and referer_domain:
|
||||||
# Does calling_domain look like a domain?
|
# Does calling_domain look like a domain?
|
||||||
if ' ' in referer_domain or \
|
if not resembles_domain(referer_domain):
|
||||||
';' in referer_domain or \
|
|
||||||
'.' not in referer_domain:
|
|
||||||
print('mastodon api v2 ' +
|
print('mastodon api v2 ' +
|
||||||
'referer does not look like a domain ' +
|
'referer does not look like a domain ' +
|
||||||
referer_domain)
|
referer_domain)
|
||||||
|
|
|
||||||
12
tests.py
12
tests.py
|
|
@ -67,6 +67,7 @@ from flags import is_right_to_left_text
|
||||||
from status import actor_status_expired
|
from status import actor_status_expired
|
||||||
from status import get_actor_status
|
from status import get_actor_status
|
||||||
from unicodetext import uninvert_text
|
from unicodetext import uninvert_text
|
||||||
|
from utils import resembles_domain
|
||||||
from utils import remove_domain_port
|
from utils import remove_domain_port
|
||||||
from utils import get_port_from_domain
|
from utils import get_port_from_domain
|
||||||
from utils import is_yggdrasil_url
|
from utils import is_yggdrasil_url
|
||||||
|
|
@ -9769,6 +9770,17 @@ def _test_post_collection() -> None:
|
||||||
"https://lemmings/activities/like/7243"
|
"https://lemmings/activities/like/7243"
|
||||||
|
|
||||||
|
|
||||||
|
def test_domain_check() -> None:
|
||||||
|
print('test domain check')
|
||||||
|
assert not resembles_domain('')
|
||||||
|
assert not resembles_domain('abcdef')
|
||||||
|
assert resembles_domain('192.168.3.9')
|
||||||
|
assert resembles_domain('somedomain.onion')
|
||||||
|
assert not resembles_domain('somedomain.onion and something else')
|
||||||
|
assert not resembles_domain('[abc.def.abc]')
|
||||||
|
assert resembles_domain('[abc:def:abc]')
|
||||||
|
|
||||||
|
|
||||||
def run_all_tests():
|
def run_all_tests():
|
||||||
base_dir = os.getcwd()
|
base_dir = os.getcwd()
|
||||||
data_dir_testing(base_dir)
|
data_dir_testing(base_dir)
|
||||||
|
|
|
||||||
19
utils.py
19
utils.py
|
|
@ -4030,6 +4030,25 @@ def resembles_url(text: str) -> bool:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def resembles_domain(text: str) -> bool:
|
||||||
|
"""Does the given text resemble a domain?
|
||||||
|
Why not use validators? It's so that exotic, potentially p2p domains
|
||||||
|
may be used.
|
||||||
|
"""
|
||||||
|
if ' ' in text or '-' in text or '<' in text or ';' in text or \
|
||||||
|
'"' in text or '(' in text or ')' in text:
|
||||||
|
return False
|
||||||
|
|
||||||
|
# conventional domain or yggdrasil address
|
||||||
|
if '.' in text and '[' not in text and ']' not in text:
|
||||||
|
return True
|
||||||
|
|
||||||
|
if (text.startswith('[') and text.endswith(']') and ':' in text):
|
||||||
|
return True
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def post_summary_contains_links(message_json: {}) -> bool:
|
def post_summary_contains_links(message_json: {}) -> bool:
|
||||||
"""check if the json post summary contains links
|
"""check if the json post summary contains links
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue