kopia lustrzana https://github.com/tsileo/little-boxes
More tests
rodzic
62698a7724
commit
619883cc8f
|
@ -0,0 +1,32 @@
|
|||
from unittest import mock
|
||||
|
||||
import pytest
|
||||
|
||||
from little_boxes import urlutils
|
||||
|
||||
|
||||
def test_urlutils_reject_invalid_scheme():
|
||||
assert not urlutils.is_url_valid("ftp://localhost:123")
|
||||
|
||||
|
||||
def test_urlutils_reject_localhost():
|
||||
assert not urlutils.is_url_valid("http://localhost:8000")
|
||||
|
||||
|
||||
def test_urlutils_reject_private_ip():
|
||||
assert not urlutils.is_url_valid("http://192.168.1.10:8000")
|
||||
|
||||
|
||||
@mock.patch("socket.getaddrinfo", return_value=[[0, 1, 2, 3, ["192.168.1.11", None]]])
|
||||
def test_urlutils_reject_domain_that_resolve_to_private_ip(_):
|
||||
assert not urlutils.is_url_valid("http://resolve-to-private.com")
|
||||
|
||||
|
||||
@mock.patch("socket.getaddrinfo", return_value=[[0, 1, 2, 3, ["1.2.3.4", None]]])
|
||||
def test_urlutils_accept_valid_url(_):
|
||||
assert urlutils.is_url_valid("https://microblog.pub")
|
||||
|
||||
|
||||
def test_urlutils_check_url_helper():
|
||||
with pytest.raises(urlutils.InvalidURLError):
|
||||
urlutils.check_url("http://localhost:5000")
|
|
@ -0,0 +1,33 @@
|
|||
import logging
|
||||
|
||||
from little_boxes import webfinger
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
||||
|
||||
_WEBFINGER_RESP = {
|
||||
"aliases": ["https://microblog.pub"],
|
||||
"links": [
|
||||
{
|
||||
"href": "https://microblog.pub",
|
||||
"rel": "http://webfinger.net/rel/profile-page",
|
||||
"type": "text/html",
|
||||
},
|
||||
{
|
||||
"href": "https://microblog.pub",
|
||||
"rel": "self",
|
||||
"type": "application/activity+json",
|
||||
},
|
||||
{
|
||||
"rel": "http://ostatus.org/schema/1.0/subscribe",
|
||||
"template": "https://microblog.pub/authorize_follow?profile={uri}",
|
||||
},
|
||||
],
|
||||
"subject": "acct:dev@microblog.pub",
|
||||
}
|
||||
|
||||
|
||||
def test_webfinger():
|
||||
data = webfinger.webfinger("@dev@microblog.pub")
|
||||
|
||||
assert data == _WEBFINGER_RESP
|
Ładowanie…
Reference in New Issue